Browse Source

Now can add a new server

Héctor García 10 years ago
parent
commit
3a40debf87
4 changed files with 108 additions and 5 deletions
  1. 3 1
      ChangeLog
  2. 3 1
      NEWS
  3. 11 0
      mssh.schemas
  4. 91 3
      src/mssh-window.c

+ 3 - 1
ChangeLog

@@ -4,7 +4,9 @@
 
 
 	Added support to maximize a terminal (ctrl + shift + x). Patch from Balint Deak.
 	Added support to maximize a terminal (ctrl + shift + x). Patch from Balint Deak.
 
 
-    Added support to change bg y fg colors on selected terminal. Patch from Balint Deak.
+	Added support to change bg y fg colors on selected terminal. Patch from Balint Deak.
+
+	Added support to create a new session. Patch from Balint Deak.
 
 
 2014-01-15  Héctor García  <[email protected]>
 2014-01-15  Héctor García  <[email protected]>
 
 

+ 3 - 1
NEWS

@@ -1,4 +1,6 @@
 2014-03-14
 2014-03-14
-    New ctrl + shift +x combination to maximize a terminal
+    New ctrl + shift + x combination to maximize a terminal.
+
+    New ctrl + shift + n combinatio to add a new server.
 
 
     Now you can have different colors on select terminal. MUST update mssh.schema or mssh will crash.
     Now you can have different colors on select terminal. MUST update mssh.schema or mssh will crash.

+ 11 - 0
mssh.schemas

@@ -121,6 +121,17 @@
                 <long>Uses directional focus rather than linear focus</long>
                 <long>Uses directional focus rather than linear focus</long>
             </locale>
             </locale>
         </schema>
         </schema>
+        <schema>
+            <key>/schemas/apps/mssh/use_pattern_expansion</key>
+            <applyto>/apps/mssh/use_pattern_expansion</applyto>
+            <owner>mssh</owner>
+            <type>bool</type>
+            <default>true</default>
+            <locale name="C">
+                <short>Allow expansion of curly braces when adding new sessions</short>
+                <long>Use curly bracket expansion when adding new sessions</long>
+            </locale>
+        </schema>              
         <schema>
         <schema>
             <key>/schemas/apps/mssh/modifier</key>
             <key>/schemas/apps/mssh/modifier</key>
             <applyto>/apps/mssh/modifier</applyto>
             <applyto>/apps/mssh/modifier</applyto>

+ 91 - 3
src/mssh-window.c

@@ -1,8 +1,10 @@
 #include <string.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdlib.h>
+#include <stdio.h>
 
 
 #include <gconf/gconf-client.h>
 #include <gconf/gconf-client.h>
 #include <gdk/gdkkeysyms.h>
 #include <gdk/gdkkeysyms.h>
+#include <gtk/gtk.h>
 
 
 #include "mssh-terminal.h"
 #include "mssh-terminal.h"
 #include "mssh-pref.h"
 #include "mssh-pref.h"
@@ -11,6 +13,8 @@
 
 
 #include "config.h"
 #include "config.h"
 
 
+#include <regex.h>  
+
 static void mssh_window_sendhost(GtkWidget *widget, gpointer data);
 static void mssh_window_sendhost(GtkWidget *widget, gpointer data);
 static void mssh_window_destroy(GtkWidget *widget, gpointer data);
 static void mssh_window_destroy(GtkWidget *widget, gpointer data);
 static void mssh_window_pref(GtkWidget *widget, gpointer data);
 static void mssh_window_pref(GtkWidget *widget, gpointer data);
@@ -26,6 +30,9 @@ static void mssh_window_insert(GtkWidget *widget, gchar *new_text,
 static void mssh_window_add_session(MSSHWindow *window, char *hostname);
 static void mssh_window_add_session(MSSHWindow *window, char *hostname);
 static void mssh_window_init(MSSHWindow* window);
 static void mssh_window_init(MSSHWindow* window);
 static void mssh_window_class_init(MSSHWindowClass *klass);
 static void mssh_window_class_init(MSSHWindowClass *klass);
+static void mssh_window_add(GtkWidget *widget, gpointer data);
+gboolean mssh_window_dialog_emit_response(GtkWidget *widget, GObject *acceleratable,
+    guint keyval, GdkModifierType modifier, gpointer data);
 static void mssh_window_maximize(GtkWidget *widget, gpointer data);
 static void mssh_window_maximize(GtkWidget *widget, gpointer data);
 static void mssh_window_restore_layout(GtkWidget *widget, gpointer data);
 static void mssh_window_restore_layout(GtkWidget *widget, gpointer data);
 void mssh_window_relayout_for_one(MSSHWindow *window, GtkWidget *t);
 void mssh_window_relayout_for_one(MSSHWindow *window, GtkWidget *t);
@@ -441,8 +448,8 @@ static void mssh_window_init(MSSHWindow* window)
         GTK_STOCK_QUIT, NULL);
         GTK_STOCK_QUIT, NULL);
     GtkWidget *file_sendhost = gtk_image_menu_item_new_with_label(
     GtkWidget *file_sendhost = gtk_image_menu_item_new_with_label(
         "Send hostname");
         "Send hostname");
-/*  GtkWidget *file_add = gtk_image_menu_item_new_with_label(
-        "Add session");*/
+    GtkWidget *file_add = gtk_menu_item_new_with_label(
+        "Add session");
 
 
     GtkWidget *edit_pref = gtk_image_menu_item_new_from_stock(
     GtkWidget *edit_pref = gtk_image_menu_item_new_from_stock(
         GTK_STOCK_PREFERENCES, NULL);
         GTK_STOCK_PREFERENCES, NULL);
@@ -470,12 +477,14 @@ static void mssh_window_init(MSSHWindow* window)
     gtk_menu_item_set_submenu(GTK_MENU_ITEM(server_item),
     gtk_menu_item_set_submenu(GTK_MENU_ITEM(server_item),
         window->server_menu);
         window->server_menu);
 
 
-/*  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_add);*/
+    gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_add);
     gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_sendhost);
     gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_sendhost);
     gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_quit);
     gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_quit);
     gtk_menu_shell_append(GTK_MENU_SHELL(edit_menu), edit_pref);
     gtk_menu_shell_append(GTK_MENU_SHELL(edit_menu), edit_pref);
     g_signal_connect(G_OBJECT(file_sendhost), "activate",
     g_signal_connect(G_OBJECT(file_sendhost), "activate",
         G_CALLBACK(mssh_window_sendhost), window);
         G_CALLBACK(mssh_window_sendhost), window);
+    g_signal_connect(G_OBJECT(file_add), "activate",
+        G_CALLBACK(mssh_window_add), window);
     g_signal_connect(G_OBJECT(file_quit), "activate",
     g_signal_connect(G_OBJECT(file_quit), "activate",
         G_CALLBACK(mssh_window_destroy), window);
         G_CALLBACK(mssh_window_destroy), window);
     g_signal_connect(G_OBJECT(edit_pref), "activate",
     g_signal_connect(G_OBJECT(edit_pref), "activate",
@@ -564,6 +573,11 @@ static void mssh_window_init(MSSHWindow* window)
         GTK_ACCEL_VISIBLE, g_cclosure_new(
         GTK_ACCEL_VISIBLE, g_cclosure_new(
         G_CALLBACK(mssh_window_toggle_maximize), window, NULL));
         G_CALLBACK(mssh_window_toggle_maximize), window, NULL));
 
 
+    /* bind Ctrl + Shift + N to show the dialog for adding new sessions */
+    gtk_accel_group_connect(accel, GDK_KEY_n, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
+        GTK_ACCEL_VISIBLE, g_cclosure_new(
+        G_CALLBACK(mssh_window_add), window, NULL));
+
     window->accel = accel;
     window->accel = accel;
 
 
     gtk_window_add_accel_group(GTK_WINDOW(window), accel);
     gtk_window_add_accel_group(GTK_WINDOW(window), accel);
@@ -734,3 +748,77 @@ static void mssh_window_restore_layout(GtkWidget *widget, gpointer data)
         mssh_gconf_notify_bg_colour_focus(client, 0, entry, window);
         mssh_gconf_notify_bg_colour_focus(client, 0, entry, window);
 	}
 	}
 }
 }
+
+/* show a popup window for adding new sessions  */
+static void mssh_window_add(GtkWidget *widget, gpointer data)
+{
+
+    MSSHWindow *window = MSSH_WINDOW(data);
+    GtkWidget *dialog, *label, *content_area, *button_add;
+	GtkWidget *new_session_entry;
+	gint result;
+    
+    /* create new dialog */
+    dialog = gtk_dialog_new();
+    /* get the content area that will be packed */
+    content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+
+    /* label for text */
+    label = gtk_label_new ("Add new session with hostname: ");
+
+    /* Add the label and entry, and show everything we've added to the dialog */
+    new_session_entry = gtk_entry_new();
+    gtk_entry_set_max_length (GTK_ENTRY(new_session_entry), 255);
+
+    /* pack the widgets */
+    gtk_container_add (GTK_CONTAINER (content_area), label);
+    gtk_container_add (GTK_CONTAINER (content_area), new_session_entry);
+    /* add two buttons */
+    button_add = gtk_dialog_add_button(GTK_DIALOG(dialog), "Add", GTK_RESPONSE_ACCEPT);
+    gtk_dialog_add_button(GTK_DIALOG(dialog), "Cancel", GTK_RESPONSE_CANCEL);
+    /* make the add button the default */
+    gtk_widget_grab_default(button_add);
+    /* set dialog properties (modal, etc) */
+    gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
+    gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
+    gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(window));
+    /* set it's title */
+    gtk_window_set_title(GTK_WINDOW(dialog), "Add new session");
+
+    /* catch the activate signal (hitting enter) */
+    g_signal_connect(G_OBJECT(new_session_entry), "activate",
+        G_CALLBACK(mssh_window_dialog_emit_response), window);
+
+    /* show the dialog and it's widgets */
+    gtk_widget_show_all (dialog);
+
+    /* wait for input */
+    result = gtk_dialog_run (GTK_DIALOG (dialog));
+    switch (result)
+      {
+        case GTK_RESPONSE_ACCEPT:
+           mssh_window_add_session(window, (gchar*) gtk_entry_get_text(GTK_ENTRY(new_session_entry)));
+           /* relayout */
+           mssh_window_relayout(window);
+           break;
+        default:
+           /* do nothing */
+           break;
+      }
+    gtk_widget_destroy (dialog);
+}
+
+/* catch the 'activate' signal of the entry (return has been pushed)  */
+/* emit the response for accept, simulating a mouse click on the add button  */
+gboolean mssh_window_dialog_emit_response(GtkWidget *widget, GObject *acceleratable,
+    guint keyval, GdkModifierType modifier, gpointer data)
+{
+
+    /* get the dialog by getting the parent of the parent for the emitting (entry) widget */
+    GtkWidget *vbox = gtk_widget_get_parent(widget);
+    GtkWidget *dialog = gtk_widget_get_parent(vbox);
+    /* emit the response signal simulating the clicking of 'ok'  */
+    gtk_dialog_response (GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
+
+    return TRUE;
+}