[Window] Add tilda_window_remove_term() implementation
authorIra W. Snyder <devel@irasnyder.com>
Mon, 14 Jan 2008 06:55:05 +0000 (22:55 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Mon, 14 Jan 2008 06:55:05 +0000 (22:55 -0800)
Before this, the tilda_window_remove_term() function was just a stub. This
fills it out to a real implementation, which will be used later to close
running terminals.

tilda-window.c
tilda-window.h

index 0a55adf..b0adcfd 100644 (file)
@@ -55,20 +55,52 @@ tilda_window_add_term (TildaWindow *tw)
        return TRUE;
 }
 
-static gboolean
-tilda_window_remove_term (TildaWindow *tw, int number)
+/**
+ * Remove the TildaTerminal with the given number from the given
+ * TildaWindow.
+ *
+ * Return: TRUE on success, FALSE otherwise.
+ */
+gboolean
+tilda_window_remove_term (TildaWindow *tw, gint terminal_number)
 {
-       int i;
+       gint i;
 
        for (i=0; i<tw->terms->len; ++i)
        {
                TildaTerminal *tt = g_ptr_array_index (tw->terms, i);
 
-               if (tt->number == number)
+               if (tt->number == terminal_number)
                {
-                       // FIXME: Find it in the notebook. Remove that notebook page.
-                       // FIXME: Check if we need to exit. Etc.
-                       g_print ("Need to remove window %d terminal %d\n", tw->number, tt->number);
+                       gint notebook_index = gtk_notebook_page_num (GTK_NOTEBOOK(tw->notebook), tt->hbox);
+
+                       /* Make sure the index was valid */
+                       if (notebook_index == -1)
+                       {
+                               g_printerr ("DEBUG ERROR: Bad Notebook Tab\n");
+                               return FALSE;
+                       }
+
+                       /* Actually remove the terminal */
+                       gtk_notebook_remove_page (GTK_NOTEBOOK (tw->notebook), notebook_index);
+
+                       /* We should hide the tabs if there is only one tab left */
+                       if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (tw->notebook)) == 1)
+                               gtk_notebook_set_show_tabs (GTK_NOTEBOOK (tw->notebook), FALSE);
+
+#if 0
+                       // FIXME FIXME FIXME: need to actually do the stuff below
+                       /* With no pages left, it's time to leave the program */
+                       if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (tw->notebook)) < 1)
+                               gtk_main_quit ();
+#endif
+
+                       /* Remove the term from our lists, then free it */
+                       g_ptr_array_remove_fast (tw->terms, tt);
+                       g_object_unref (G_OBJECT(tt));
+
+                       /* Leave the loop, we're done */
+                       break;
                }
        }
 
index f40347a..e11e17c 100644 (file)
@@ -54,6 +54,7 @@ struct _TildaWindowClass {
 GType tilda_window_get_type (void);
 
 /* API */
+gboolean tilda_window_remove_term (TildaWindow *tw, gint terminal_number);
 
 #endif /* TILDA_WINDOW_H */