Преглед изворни кода

Fixes to terminal class and add "add session" menuitem.

Signed-off-by: Bradley Smith <[email protected]>
Bradley Smith пре 15 година
родитељ
комит
3176af35e8
3 измењених фајлова са 35 додато и 14 уклоњено
  1. 14 10
      src/mssh-terminal.c
  2. 3 2
      src/mssh-terminal.h
  3. 18 2
      src/mssh-window.c

+ 14 - 10
src/mssh-terminal.c

@@ -27,26 +27,28 @@ gboolean mssh_terminal_isactive(MSSHTerminal *terminal)
 		GTK_CHECK_MENU_ITEM(terminal->menu_item));
 }
 
-void mssh_terminal_start_session(MSSHTerminal *terminal, char *hostname,
-	char **env)
+void mssh_terminal_init_session(MSSHTerminal *terminal, char *hostname)
 {
-	char *args[3];
-
 	terminal->hostname = hostname;
 
+	terminal->menu_item = gtk_check_menu_item_new_with_label(
+		terminal->hostname);
+
+	gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
+		terminal->menu_item), TRUE);
+}
+
+void mssh_terminal_start_session(MSSHTerminal *terminal, char **env)
+{
+	char *args[3];
+
 	args[0] = strdup("ssh");
 	args[1] = terminal->hostname;
 	args[2] = NULL;
 
-	terminal->menu_item = gtk_check_menu_item_new_with_label(
-		terminal->hostname);
-
 	vte_terminal_fork_command(VTE_TERMINAL(terminal), "ssh", args,
 		env, NULL, FALSE, FALSE, FALSE);
 
-	gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
-		terminal->menu_item), TRUE);
-
 	free(args[0]);
 }
 
@@ -71,6 +73,8 @@ void mssh_terminal_send_data(MSSHTerminal *terminal, GdkEventKey *event)
 
 static void mssh_terminal_init(MSSHTerminal* terminal)
 {
+	terminal->started = 0;
+
 	g_signal_connect(G_OBJECT(terminal), "child-exited",
 		G_CALLBACK(mssh_terminal_child_exited), terminal);
 	g_signal_connect(G_OBJECT(terminal), "focus-in-event",

+ 3 - 2
src/mssh-terminal.h

@@ -21,6 +21,7 @@ typedef struct
 	VteTerminal vte;
 	GtkWidget *menu_item;
 	char *hostname;
+	int started;
 } MSSHTerminal;
 
 typedef struct
@@ -39,8 +40,8 @@ GType mssh_terminal_get_type(void) G_GNUC_CONST;
 GtkWidget* mssh_terminal_new(void);
 void mssh_terminal_destroy(MSSHTerminal *terminal);
 gboolean mssh_terminal_isactive(MSSHTerminal *terminal);
-void mssh_terminal_start_session(MSSHTerminal *terminal, char *hostnane,
-	char **env);
+void mssh_terminal_init_session(MSSHTerminal *terminal, char *hostname);
+void mssh_terminal_start_session(MSSHTerminal *terminal, char **env);
 void mssh_terminal_send_host(MSSHTerminal *terminal);
 void mssh_terminal_send_data(MSSHTerminal *terminal, GdkEventKey *event);
 

+ 18 - 2
src/mssh-window.c

@@ -81,6 +81,10 @@ static void mssh_window_destroy(GtkWidget *widget, gpointer data)
 
 		gtk_widget_destroy(dialog);
 	}
+	else
+	{
+		gtk_main_quit();
+	}
 }
 
 static void mssh_window_pref(GtkWidget *widget, gpointer data)
@@ -206,9 +210,18 @@ static void mssh_window_relayout(MSSHWindow *window)
 			(i % 2), (i == len - 1) ? 2 : (i % 2) + 1, i / 2, (i / 2) + 1,
 			GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 2, 2);
 		g_object_unref(terminal);
+
+		if(!terminal->started)
+		{
+			mssh_terminal_start_session(terminal, window->env);
+			terminal->started = 1;
+		}
 	}
 
-	gtk_table_resize(GTK_TABLE(window->table), ((len + 1) / 2), 2);
+	if(len > 0)
+	{
+		gtk_table_resize(GTK_TABLE(window->table), ((len + 1) / 2), 2);
+	}
 }
 
 static void mssh_window_add_session(MSSHWindow *window, char *hostname)
@@ -222,7 +235,7 @@ static void mssh_window_add_session(MSSHWindow *window, char *hostname)
 	g_signal_connect(G_OBJECT(terminal), "session-focused",
 		G_CALLBACK(mssh_window_session_focused), window);
 
-	mssh_terminal_start_session(terminal, hostname, window->env);
+	mssh_terminal_init_session(terminal, hostname);
 
 	gtk_menu_shell_append(GTK_MENU_SHELL(window->server_menu),
 		terminal->menu_item);
@@ -246,6 +259,8 @@ static void mssh_window_init(MSSHWindow* window)
 		GTK_STOCK_QUIT, NULL);
 	GtkWidget *file_sendhost = gtk_image_menu_item_new_with_label(
 		"Send hostname");
+	GtkWidget *file_add = gtk_image_menu_item_new_with_label(
+		"Add session");
 
 	GtkWidget *edit_pref = gtk_image_menu_item_new_from_stock(
 		GTK_STOCK_PREFERENCES, NULL);
@@ -257,6 +272,7 @@ static void mssh_window_init(MSSHWindow* window)
 	gtk_menu_item_set_submenu(GTK_MENU_ITEM(server_item),
 		window->server_menu);
 
+	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_quit);
 	gtk_menu_shell_append(GTK_MENU_SHELL(edit_menu), edit_pref);