From 04be33ddd62ea7f3394079d7abeb76291fe95393 Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Sun, 13 Jan 2008 22:55:05 -0800 Subject: [PATCH] [Window] Add tilda_window_remove_term() implementation 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 | 46 +++++++++++++++++++++++++++++++++++++++------- tilda-window.h | 1 + 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/tilda-window.c b/tilda-window.c index 0a55adf..b0adcfd 100644 --- a/tilda-window.c +++ b/tilda-window.c @@ -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; iterms->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; } } diff --git a/tilda-window.h b/tilda-window.h index f40347a..e11e17c 100644 --- a/tilda-window.h +++ b/tilda-window.h @@ -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 */ -- 2.25.1