[hotssh] tab: Convert to a GtkStack



commit 4eb603b0cb702bbdb043d85d11f88052711f1a29
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Mon Dec 2 11:12:07 2013 -0500

    tab: Convert to a GtkStack

 src/hotssh-tab.c |   33 +++++++++--------------
 src/tab.ui       |   76 +++++-------------------------------------------------
 2 files changed, 20 insertions(+), 89 deletions(-)
---
diff --git a/src/hotssh-tab.c b/src/hotssh-tab.c
index 032b09d..5c3bffa 100644
--- a/src/hotssh-tab.c
+++ b/src/hotssh-tab.c
@@ -44,24 +44,23 @@ enum {
 
 struct _HotSshTab
 {
-  GtkNotebook parent;
+  GtkStack parent;
 };
 
 struct _HotSshTabClass
 {
-  GtkNotebookClass parent_class;
+  GtkStackClass parent_class;
 };
 
 typedef struct _HotSshTabPrivate HotSshTabPrivate;
 
-typedef enum {
-  HOTSSH_TAB_PAGE_NEW_CONNECTION,
-  HOTSSH_TAB_PAGE_CONNECTING,
-  HOTSSH_TAB_PAGE_ERROR,
-  HOTSSH_TAB_PAGE_HOSTKEY,
-  HOTSSH_TAB_PAGE_PASSWORD,
-  HOTSSH_TAB_PAGE_TERMINAL
-} HotSshTabPage;
+#define HOTSSH_TAB_PAGE_NEW_CONNECTION ("new-connection")
+#define HOTSSH_TAB_PAGE_CONNECTING     ("connecting")
+#define HOTSSH_TAB_PAGE_ERROR          ("error")
+#define HOTSSH_TAB_PAGE_HOSTKEY        ("hostkey")
+#define HOTSSH_TAB_PAGE_PASSWORD       ("password")
+#define HOTSSH_TAB_PAGE_TERMINAL       ("terminal")
+typedef const char * HotSshTabPage;
 
 struct _HotSshTabPrivate
 {
@@ -109,7 +108,7 @@ struct _HotSshTabPrivate
   GCancellable *cancellable;
 };
 
-G_DEFINE_TYPE_WITH_PRIVATE(HotSshTab, hotssh_tab, GTK_TYPE_NOTEBOOK);
+G_DEFINE_TYPE_WITH_PRIVATE(HotSshTab, hotssh_tab, GTK_TYPE_STACK);
 
 
 static void
@@ -181,17 +180,15 @@ page_transition (HotSshTab        *self,
   if (new_page == priv->active_page)
     return;
 
-  g_debug ("PAGE: %d => %d", priv->active_page, new_page);
-  g_assert (new_page >= HOTSSH_TAB_PAGE_NEW_CONNECTION &&
-           new_page <= HOTSSH_TAB_PAGE_TERMINAL);
+  g_debug ("PAGE: %s => %s", priv->active_page, new_page);
   priv->active_page = new_page;
 
   if (priv->active_page == HOTSSH_TAB_PAGE_NEW_CONNECTION
       || priv->active_page == HOTSSH_TAB_PAGE_ERROR)
     state_reset_for_new_connection (self);
 
-  gtk_notebook_set_current_page ((GtkNotebook*)self, (guint)new_page);
-  
+  gtk_stack_set_visible_child_name ((GtkStack*)self, new_page);
+
   if (priv->active_page == HOTSSH_TAB_PAGE_TERMINAL)
     gtk_widget_grab_focus ((GtkWidget*)priv->terminal);
 }
@@ -508,7 +505,6 @@ on_connect (GtkButton     *button,
   const char *username;
 
   page_transition (self, HOTSSH_TAB_PAGE_CONNECTING);
-  gtk_notebook_set_current_page ((GtkNotebook*)self, 1);
 
   hostname = gtk_entry_get_text (GTK_ENTRY (priv->host_entry));
   username = gtk_entry_get_text (GTK_ENTRY (priv->username_entry));
@@ -803,8 +799,6 @@ hotssh_tab_init (HotSshTab *self)
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
-  gtk_notebook_set_show_tabs ((GtkNotebook*)self, FALSE);
-
   g_signal_connect (priv->connect_button, "clicked", G_CALLBACK (on_connect), self);
   g_signal_connect (priv->connect_cancel_button, "clicked", G_CALLBACK (on_connect_cancel), self);
   g_signal_connect (priv->error_disconnect, "clicked", G_CALLBACK (on_connect_cancel), self);
@@ -913,7 +907,6 @@ void
 hotssh_tab_disconnect  (HotSshTab *self)
 {
   page_transition (self, HOTSSH_TAB_PAGE_NEW_CONNECTION);
-  gtk_notebook_set_current_page ((GtkNotebook*)self, 0);
 }
 
 const char *
diff --git a/src/tab.ui b/src/tab.ui
index 7c6aaf4..1119ca1 100644
--- a/src/tab.ui
+++ b/src/tab.ui
@@ -2,7 +2,7 @@
 <!-- Generated with glade 3.16.0 on Sun Nov 17 16:27:47 2013 -->
 <interface>
   <!-- interface-requires gtk+ 3.10 -->
-  <template class="HotSshTab" parent="GtkNotebook">
+  <template class="HotSshTab" parent="GtkStack">
     <property name="can_focus">False</property>
     <child>
       <object class="GtkBox" id="content_box">
@@ -123,15 +123,8 @@
           </packing>
         </child>
       </object>
-    </child>
-    <child type="tab">
-      <object class="GtkLabel" id="label1">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="label" translatable="yes">Host</property>
-      </object>
       <packing>
-        <property name="tab_fill">False</property>
+        <property name="name">new-connection</property>
       </packing>
     </child>
     <child>
@@ -179,18 +172,7 @@
         </child>
       </object>
       <packing>
-        <property name="position">1</property>
-      </packing>
-    </child>
-    <child type="tab">
-      <object class="GtkLabel" id="label8">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="label" translatable="yes">Status</property>
-      </object>
-      <packing>
-        <property name="position">1</property>
-        <property name="tab_fill">False</property>
+        <property name="name">connecting</property>
       </packing>
     </child>
     <child>
@@ -257,18 +239,7 @@
         </child>
       </object>
       <packing>
-        <property name="position">2</property>
-      </packing>
-    </child>
-    <child type="tab">
-      <object class="GtkLabel" id="label9">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="label" translatable="yes">Error</property>
-      </object>
-      <packing>
-        <property name="position">2</property>
-        <property name="tab_fill">False</property>
+        <property name="name">error</property>
       </packing>
     </child>
     <child>
@@ -375,18 +346,7 @@
         </child>
       </object>
       <packing>
-        <property name="position">3</property>
-      </packing>
-    </child>
-    <child type="tab">
-      <object class="GtkLabel" id="label7">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="label" translatable="yes">Hostkey</property>
-      </object>
-      <packing>
-        <property name="position">3</property>
-        <property name="tab_fill">False</property>
+        <property name="name">hostkey</property>
       </packing>
     </child>
     <child>
@@ -486,18 +446,7 @@
         </child>
       </object>
       <packing>
-        <property name="position">4</property>
-      </packing>
-    </child>
-    <child type="tab">
-      <object class="GtkLabel" id="label2">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="label" translatable="yes">Password</property>
-      </object>
-      <packing>
-        <property name="position">4</property>
-        <property name="tab_fill">False</property>
+        <property name="name">password</property>
       </packing>
     </child>
     <child>
@@ -522,18 +471,7 @@
         </child>
       </object>
       <packing>
-        <property name="position">5</property>
-      </packing>
-    </child>
-    <child type="tab">
-      <object class="GtkLabel" id="label3">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="label" translatable="yes">Terminal</property>
-      </object>
-      <packing>
-        <property name="position">5</property>
-        <property name="tab_fill">False</property>
+        <property name="name">terminal</property>
       </packing>
     </child>
   </template>


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