[buoh] Port view from GtkNotebook to GtkStack



commit 7c89b1df0e5775bb84ad7cc4801dd8e38077c7cd
Author: Jan Tojnar <jtojnar gmail com>
Date:   Sat Feb 2 18:14:41 2019 +0100

    Port view from GtkNotebook to GtkStack

 build-aux/ui-pre-validation.xsl |  6 +++---
 data/ui/view.ui                 | 32 ++++----------------------------
 src/buoh-view.c                 | 18 ++++++------------
 src/buoh-view.h                 |  2 +-
 4 files changed, 14 insertions(+), 44 deletions(-)
---
diff --git a/build-aux/ui-pre-validation.xsl b/build-aux/ui-pre-validation.xsl
index 5c1756d..cdac169 100644
--- a/build-aux/ui-pre-validation.xsl
+++ b/build-aux/ui-pre-validation.xsl
@@ -25,11 +25,11 @@
 
   <!-- Usage of custom elements -->
   <xsl:template match="object/@class[. = 'BuohView']">
-    <!-- GtkBin is abstract -->
-    <xsl:attribute name="class">GtkWindow</xsl:attribute>
+    <xsl:attribute name="class">GtkStack</xsl:attribute>
   </xsl:template>
   <xsl:template match="object/@class[. = 'BuohComicList']">
-    <xsl:attribute name="class">GtkNotebook</xsl:attribute>
+    <!-- GtkBin is abstract -->
+    <xsl:attribute name="class">GtkWindow</xsl:attribute>
   </xsl:template>
   <xsl:template match="object/@class[. = 'BuohViewComic']">
     <xsl:attribute name="class">GtkViewport</xsl:attribute>
diff --git a/data/ui/view.ui b/data/ui/view.ui
index 3d3d196..11a8108 100644
--- a/data/ui/view.ui
+++ b/data/ui/view.ui
@@ -2,10 +2,9 @@
 <!-- Generated with glade 3.22.1 -->
 <interface>
   <requires lib="gtk+" version="3.20"/>
-  <template class="BuohView" parent="GtkNotebook">
+  <template class="BuohView" parent="GtkStack">
     <property name="visible">1</property>
     <property name="can-focus">1</property>
-    <property name="show-tabs">0</property>
     <signal name="notify::status" handler="buoh_view_status_changed_cb" swapped="no"/>
     <child>
       <object class="GtkScrolledWindow">
@@ -19,13 +18,8 @@
           </object>
         </child>
       </object>
-    </child>
-    <child type="tab">
-      <object class="GtkLabel">
-        <property name="visible">1</property>
-      </object>
       <packing>
-        <property name="tab-fill">0</property>
+        <property name="name">image</property>
       </packing>
     </child>
     <child>
@@ -40,16 +34,7 @@
         </child>
       </object>
       <packing>
-        <property name="position">1</property>
-      </packing>
-    </child>
-    <child type="tab">
-      <object class="GtkLabel">
-        <property name="visible">1</property>
-      </object>
-      <packing>
-        <property name="position">1</property>
-        <property name="tab-fill">0</property>
+        <property name="name">message</property>
       </packing>
     </child>
     <child>
@@ -57,16 +42,7 @@
         <property name="visible">1</property>
       </object>
       <packing>
-        <property name="position">2</property>
-      </packing>
-    </child>
-    <child type="tab">
-      <object class="GtkLabel">
-        <property name="visible">1</property>
-      </object>
-      <packing>
-        <property name="position">2</property>
-        <property name="tab-fill">0</property>
+        <property name="name">empty</property>
       </packing>
     </child>
   </template>
diff --git a/src/buoh-view.c b/src/buoh-view.c
index 4ddb3bf..a96b466 100644
--- a/src/buoh-view.c
+++ b/src/buoh-view.c
@@ -32,19 +32,13 @@ enum {
         PROP_STATUS
 };
 
-enum {
-        VIEW_PAGE_IMAGE,
-        VIEW_PAGE_MESSAGE,
-        VIEW_PAGE_EMPTY
-};
-
 enum {
         SCALE_CHANGED,
         N_SIGNALS
 };
 
 struct _BuohView {
-        GtkNotebook      parent;
+        GtkStack         parent;
 
         GtkWidget       *message;
         GtkWidget       *comic;
@@ -74,7 +68,7 @@ static void     buoh_view_scale_changed_cb   (GObject        *object,
                                               GParamSpec     *arg,
                                               gpointer        gdata);
 
-G_DEFINE_TYPE (BuohView, buoh_view, GTK_TYPE_NOTEBOOK)
+G_DEFINE_TYPE (BuohView, buoh_view, GTK_TYPE_STACK)
 
 static void
 buoh_view_init (BuohView *buoh_view)
@@ -99,7 +93,7 @@ buoh_view_init (BuohView *buoh_view)
                                       "on the right side. Thanks for using Buoh."));
         buoh_view_message_set_icon (BUOH_VIEW_MESSAGE (buoh_view->message), "buoh");
 
-        gtk_notebook_set_current_page (GTK_NOTEBOOK (buoh_view), VIEW_PAGE_MESSAGE);
+        gtk_stack_set_visible_child_name (GTK_STACK (buoh_view), "message");
 
         /* Callbacks */
         g_signal_connect (G_OBJECT (buoh_view->comic),
@@ -231,14 +225,14 @@ buoh_view_status_changed_cb (GObject *object, GParamSpec *arg, gpointer gdata)
         switch (view->status) {
         case STATE_MESSAGE_WELCOME:
         case STATE_MESSAGE_ERROR:
-                gtk_notebook_set_current_page (GTK_NOTEBOOK (view), VIEW_PAGE_MESSAGE);
+                gtk_stack_set_visible_child_name (GTK_STACK (view), "message");
                 break;
         case STATE_COMIC_LOADING:
         case STATE_COMIC_LOADED:
-                gtk_notebook_set_current_page (GTK_NOTEBOOK (view), VIEW_PAGE_IMAGE);
+                gtk_stack_set_visible_child_name (GTK_STACK (view), "image");
                 break;
         case STATE_EMPTY:
-                gtk_notebook_set_current_page (GTK_NOTEBOOK (view), VIEW_PAGE_EMPTY);
+                gtk_stack_set_visible_child_name (GTK_STACK (view), "empty");
                 break;
         default:
                 break;
diff --git a/src/buoh-view.h b/src/buoh-view.h
index 224299f..69a4ea3 100644
--- a/src/buoh-view.h
+++ b/src/buoh-view.h
@@ -29,7 +29,7 @@
 G_BEGIN_DECLS
 
 #define BUOH_TYPE_VIEW buoh_view_get_type ()
-G_DECLARE_FINAL_TYPE (BuohView, buoh_view, BUOH, VIEW, GtkNotebook)
+G_DECLARE_FINAL_TYPE (BuohView, buoh_view, BUOH, VIEW, GtkStack)
 
 typedef enum {
         STATE_MESSAGE_WELCOME,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]