[hotssh] Support creating new tabs for existing connections, add New Connection button



commit 92b32461f1770ef7f5dfb3ea28fad4b4e4865aaf
Author: Colin Walters <walters verbum org>
Date:   Fri Oct 18 14:34:05 2013 -0400

    Support creating new tabs for existing connections, add New Connection button
    
    This demos the support for subchannels.

 src/gears-menu.ui |    2 +-
 src/hotssh-tab.c  |   18 +++++++++++++++---
 src/hotssh-tab.h  |    1 +
 src/hotssh-win.c  |   46 +++++++++++++++++++++++++++++++++++++---------
 src/window.ui     |   11 +++++++++++
 5 files changed, 65 insertions(+), 13 deletions(-)
---
diff --git a/src/gears-menu.ui b/src/gears-menu.ui
index 3c5c710..91bf7be 100644
--- a/src/gears-menu.ui
+++ b/src/gears-menu.ui
@@ -5,7 +5,7 @@
     <section>
       <item>
         <attribute name="label" translatable="yes">_New Tab</attribute>
-        <attribute name="action">win.new-tab</attribute>
+        <attribute name="action">win.new-channel</attribute>
       </item>
     </section>
   </menu>
diff --git a/src/hotssh-tab.c b/src/hotssh-tab.c
index 734c199..d03072e 100644
--- a/src/hotssh-tab.c
+++ b/src/hotssh-tab.c
@@ -387,9 +387,8 @@ on_connect (GtkButton     *button,
 
 static void
 on_disconnect (GtkButton     *button,
-              HotSshTab  *self)
+              HotSshTab     *self)
 {
-  HotSshTabPrivate *priv = hotssh_tab_get_instance_private (self);
   page_transition (self, HOTSSH_TAB_PAGE_NEW_CONNECTION);
   gtk_notebook_set_current_page ((GtkNotebook*)self, 0);
 }
@@ -577,7 +576,6 @@ static void
 hotssh_tab_dispose (GObject *object)
 {
   HotSshTab *self = HOTSSH_TAB (object);
-  HotSshTabPrivate *priv = hotssh_tab_get_instance_private (self);
 
   page_transition (self, HOTSSH_TAB_PAGE_NEW_CONNECTION);
 
@@ -614,3 +612,17 @@ hotssh_tab_new (void)
 {
   return g_object_new (HOTSSH_TYPE_TAB, NULL);
 }
+
+HotSshTab *
+hotssh_tab_new_channel  (HotSshTab *source)
+{
+  HotSshTab *tab = hotssh_tab_new ();
+  HotSshTabPrivate *priv = hotssh_tab_get_instance_private (tab);
+  HotSshTabPrivate *source_priv = hotssh_tab_get_instance_private (source);
+
+  state_reset_for_new_connection (tab);
+  priv->connection = g_object_ref (source_priv->connection);
+  on_connection_state_notify (priv->connection, NULL, tab);
+
+  return tab;
+}
diff --git a/src/hotssh-tab.h b/src/hotssh-tab.h
index d3f4037..ab1a4f0 100644
--- a/src/hotssh-tab.h
+++ b/src/hotssh-tab.h
@@ -31,3 +31,4 @@ typedef struct _HotSshTabClass    HotSshTabClass;
 
 GType                   hotssh_tab_get_type     (void);
 HotSshTab              *hotssh_tab_new          (void);
+HotSshTab              *hotssh_tab_new_channel  (HotSshTab *source);
diff --git a/src/hotssh-win.c b/src/hotssh-win.c
index 388378b..c915a74 100644
--- a/src/hotssh-win.c
+++ b/src/hotssh-win.c
@@ -23,13 +23,17 @@
 
 #include "libgsystem.h"
 
-static void hotssh_win_append_tab (HotSshWindow   *self);
+static void hotssh_win_append_tab (HotSshWindow   *self, gboolean new_channel);
 static void new_tab_activated (GSimpleAction    *action,
-                              GVariant         *parameter,
-                              gpointer          user_data);
+                               GVariant         *parameter,
+                               gpointer          user_data);
+static void new_channel_activated (GSimpleAction    *action,
+                                   GVariant         *parameter,
+                                   gpointer          user_data);
 
 static GActionEntry win_entries[] = {
-  { "new-tab", new_tab_activated, NULL, NULL, NULL }
+  { "new-tab", new_tab_activated, NULL, NULL, NULL },
+  { "new-channel", new_channel_activated, NULL, NULL, NULL }
 };
 
 struct _HotSshWindow
@@ -51,6 +55,7 @@ struct _HotSshWindowPrivate
 
   /* Bound via template */
   GtkWidget *main_notebook;
+  GtkWidget *new_connection;
   GtkWidget *gears;
 };
 
@@ -96,7 +101,7 @@ create_tab_label (HotSshWindow       *self,
   GtkImage *close_image;
 
   label_box = (GtkContainer*)gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
-  label = (GtkLabel*)gtk_label_new ("New Connection");
+  label = (GtkLabel*)gtk_label_new ("Unconnected");
   gtk_label_set_single_line_mode (label, TRUE);
   gtk_misc_set_alignment ((GtkMisc*)label, 0.0, 0.5);
   gtk_misc_set_padding ((GtkMisc*)label, 0, 0);
@@ -121,13 +126,23 @@ create_tab_label (HotSshWindow       *self,
 }
 
 static void
-hotssh_win_append_tab (HotSshWindow   *self)
+hotssh_win_append_tab (HotSshWindow   *self, gboolean new_channel)
 {
   HotSshWindowPrivate *priv = hotssh_window_get_instance_private (self);
   GtkWidget *label;
   HotSshTab *tab;
 
-  tab = hotssh_tab_new ();
+  if (new_channel)
+    {
+      guint i = gtk_notebook_get_current_page ((GtkNotebook*)priv->main_notebook);
+      HotSshTab *current_tab = (HotSshTab*)gtk_notebook_get_nth_page ((GtkNotebook*)priv->main_notebook, i);
+      tab = hotssh_tab_new_channel (current_tab);
+    }
+  else
+    {
+      tab = hotssh_tab_new ();
+    }
+
   g_object_set_data ((GObject*)tab, "window", self);
   label = create_tab_label (self, tab);
   
@@ -145,7 +160,17 @@ new_tab_activated (GSimpleAction    *action,
 {
   HotSshWindow *self = user_data;
 
-  hotssh_win_append_tab (self);
+  hotssh_win_append_tab (self, FALSE);
+}
+
+static void
+new_channel_activated (GSimpleAction    *action,
+                       GVariant         *parameter,
+                       gpointer          user_data)
+{
+  HotSshWindow *self = user_data;
+
+  hotssh_win_append_tab (self, TRUE);
 }
 
 static void
@@ -166,7 +191,9 @@ hotssh_window_init (HotSshWindow *self)
   gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (priv->gears), menu);
   g_object_unref (builder);
 
-  hotssh_win_append_tab (self);
+  gtk_actionable_set_action_name ((GtkActionable*)priv->new_connection, "win.new-tab");
+
+  hotssh_win_append_tab (self, FALSE);
 }
 
 static void
@@ -189,6 +216,7 @@ hotssh_window_class_init (HotSshWindowClass *class)
                                                "/org/gnome/hotssh/window.ui");
 
   gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (class), HotSshWindow, main_notebook);
+  gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (class), HotSshWindow, new_connection);
   gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (class), HotSshWindow, gears);
 }
 
diff --git a/src/window.ui b/src/window.ui
index f5de1f2..3031000 100644
--- a/src/window.ui
+++ b/src/window.ui
@@ -15,6 +15,17 @@
         <style>
           <class name="titlebar"/>
         </style>
+       <child>
+         <object class="GtkButton" id="new_connection">
+            <property name="label" translatable="yes">New Connection</property>
+            <property name="visible">True</property>
+            <property name="use-underline">True</property>
+            <property name="can-default">True</property>
+         </object>
+         <packing>
+            <property name="pack-type">start</property>
+         </packing>
+       </child>
         <child>
           <object class="GtkMenuButton" id="gears">
             <property name="visible">True</property>


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