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;
}
}