From fae4409d3de153e2d5ce493304fcd7e0bccb2ad9 Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Sun, 17 Feb 2008 15:28:19 -0800 Subject: [PATCH] [Window] Consolidate tab show/hide code This simplifies and consolidates the code that shows and hides the tabs bar in a TildaWindow. This makes it much easier to make sure you have the correct behavior. There are no functional differences. --- tilda-window.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/tilda-window.c b/tilda-window.c index aa93098..f4be2d8 100644 --- a/tilda-window.c +++ b/tilda-window.c @@ -67,6 +67,26 @@ tilda_window_find_next_free_terminal_number (TildaWindow *self) return 0; } +static void +tilda_window_show_hide_tabs_if_appropriate (TildaWindow *self) +{ + debug_enter (); + debug_assert (TILDA_IS_WINDOW(self)); + + /* If we only have one tab, we have a choice to make, otherwise, always show tabs */ + if (gtk_notebook_get_n_pages (GTK_NOTEBOOK(self->notebook)) <= 1) + { + if (self->always_show_tabs) + gtk_notebook_set_show_tabs (GTK_NOTEBOOK(self->notebook), TRUE); + else + gtk_notebook_set_show_tabs (GTK_NOTEBOOK(self->notebook), FALSE); + } + else + { + gtk_notebook_set_show_tabs (GTK_NOTEBOOK(self->notebook), TRUE); + } +} + /** * Clean up and remove self completely from the program * @@ -108,8 +128,7 @@ tilda_window_add_terminal (TildaWindow *self) gtk_notebook_set_current_page (GTK_NOTEBOOK(self->notebook), notebook_index); /* Always show tabs if we have > 1 tab open */ - if (gtk_notebook_get_n_pages (GTK_NOTEBOOK(self->notebook)) > 1) - gtk_notebook_set_show_tabs (GTK_NOTEBOOK(self->notebook), TRUE); + tilda_window_show_hide_tabs_if_appropriate (self); /* Focus the VTE Terminal */ gtk_widget_grab_focus (tt->vte_term); @@ -151,11 +170,7 @@ tilda_window_remove_terminal (TildaWindow *self, gint terminal_number) gtk_notebook_remove_page (GTK_NOTEBOOK (self->notebook), notebook_index); /* We should hide the tabs if there is only one tab left */ - if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (self->notebook)) <= 1) - { - if (!self->always_show_tabs) - gtk_notebook_set_show_tabs (GTK_NOTEBOOK (self->notebook), FALSE); - } + tilda_window_show_hide_tabs_if_appropriate (self); /* Remove the term from our lists, then free it */ g_ptr_array_remove_fast (self->terms, tt); @@ -986,13 +1001,7 @@ tilda_window_set_property (GObject *object, case TILDA_WINDOW_ALWAYS_SHOW_TABS: self->always_show_tabs = g_value_get_boolean (value); - if (gtk_notebook_get_n_pages (GTK_NOTEBOOK(self->notebook)) <= 1) - { - if (self->always_show_tabs) - gtk_notebook_set_show_tabs (GTK_NOTEBOOK(self->notebook), TRUE); - else - gtk_notebook_set_show_tabs (GTK_NOTEBOOK(self->notebook), FALSE); - } + tilda_window_show_hide_tabs_if_appropriate (self); debug_printf ("window always show tabs: %d\n", self->always_show_tabs); break; -- 2.34.1