[Terminal] Add proper handling of exit_action
authorIra W. Snyder <devel@irasnyder.com>
Mon, 14 Jan 2008 06:56:38 +0000 (22:56 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Mon, 14 Jan 2008 06:56:38 +0000 (22:56 -0800)
This makes TildaTerminal do the proper thing when the child exits, according
to the exit_action member.

tilda-terminal.c

index 841b2a3..87b081a 100644 (file)
@@ -92,6 +92,36 @@ launch_default_shell:
        return TRUE;
 }
 
+/**
+ * Called when the child process running in the VteTerminal exits.
+ */
+static void
+child_exited_cb (GtkWidget *widget, gpointer data)
+{
+       TildaTerminal *self = TILDA_TERMINAL(data);
+
+       /* These can stay here. They don't need to go into a header because
+        * they are only used at this point in the code. */
+       enum exit_actions { HOLD_TERMINAL_OPEN, RESTART_COMMAND, EXIT_TERMINAL };
+
+       /* Check the user's preference for what to do when the child terminal
+        * is closed. Take the appropriate action */
+       switch (self->exit_action)
+       {
+               case EXIT_TERMINAL:
+                       tilda_window_remove_term (TILDA_WINDOW(self->parent_window), self->number);
+                       break;
+               case RESTART_COMMAND:
+                       vte_terminal_feed (VTE_TERMINAL(self->vte_term), "\r\n\r\n", 4);
+                       tilda_terminal_start_shell (self);
+                       break;
+               case HOLD_TERMINAL_OPEN:
+                       break;
+               default:
+                       break;
+       }
+}
+
 /*******************************************************************************
  * All GObject stuff is below. You probably don't need to change this...
  ******************************************************************************/
@@ -413,7 +443,6 @@ tilda_terminal_get_property (GObject    *object,
 
                case TILDA_TERMINAL_MOUSE_AUTOHIDE:
                        g_value_set_boolean (value, self->mouse_autohide);
-                       break;
 
                default:
                        /* We don't have this property... */
@@ -449,8 +478,11 @@ tilda_terminal_constructor (GType                  type,
        gtk_widget_show (self->scrollbar);
 
 
+       /* Connect Signals */
        g_signal_connect (G_OBJECT(self->vte_term), "child-exited",
-                                         G_CALLBACK(gtk_main_quit), self);
+                                         G_CALLBACK(child_exited_cb), self);
+       g_signal_connect (G_OBJECT(self->vte_term), "eof",
+                                         G_CALLBACK(child_exited_cb), self);
 
        tilda_terminal_start_shell (self);
        tilda_terminal_dbus_register_object (self);