[Window] Consolidate tab show/hide code
authorIra W. Snyder <devel@irasnyder.com>
Sun, 17 Feb 2008 23:28:19 +0000 (15:28 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Sun, 17 Feb 2008 23:28:39 +0000 (15:28 -0800)
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

index aa93098..f4be2d8 100644 (file)
@@ -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;