Avoid counting total pages when not necessary

This commit is contained in:
Christian Dywan 2011-12-07 22:42:06 +01:00
parent e698ba3380
commit ef9e5b6e6c

View file

@ -250,34 +250,33 @@ midori_browser_is_fullscreen (MidoriBrowser* browser)
return state & GDK_WINDOW_STATE_FULLSCREEN; return state & GDK_WINDOW_STATE_FULLSCREEN;
} }
static void static gboolean
_toggle_tabbar_smartly (MidoriBrowser* browser, _toggle_tabbar_smartly (MidoriBrowser* browser,
gboolean ignore_fullscreen) gboolean ignore_fullscreen)
{ {
gboolean has_tabs =
gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), 1) != NULL;
gboolean show_tabs = gboolean show_tabs =
browser->show_tabs browser->show_tabs
&& (!midori_browser_is_fullscreen (browser) || ignore_fullscreen) && (!midori_browser_is_fullscreen (browser) || ignore_fullscreen)
&& (gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), 1) && (has_tabs
|| katze_object_get_boolean (browser->settings, "always-show-tabbar")); || katze_object_get_boolean (browser->settings, "always-show-tabbar"));
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (browser->notebook), show_tabs); gtk_notebook_set_show_tabs (GTK_NOTEBOOK (browser->notebook), show_tabs);
gtk_notebook_set_show_border (GTK_NOTEBOOK (browser->notebook), show_tabs); gtk_notebook_set_show_border (GTK_NOTEBOOK (browser->notebook), show_tabs);
return has_tabs;
} }
static void static void
_midori_browser_update_actions (MidoriBrowser* browser) _midori_browser_update_actions (MidoriBrowser* browser)
{ {
guint n; gboolean has_tabs = _toggle_tabbar_smartly (browser, FALSE);
gboolean trash_empty; _action_set_sensitive (browser, "TabPrevious", has_tabs);
_action_set_sensitive (browser, "TabNext", has_tabs);
_toggle_tabbar_smartly (browser, FALSE);
n = gtk_notebook_get_n_pages (GTK_NOTEBOOK (browser->notebook));
_action_set_sensitive (browser, "TabPrevious", n > 1);
_action_set_sensitive (browser, "TabNext", n > 1);
if (browser->trash) if (browser->trash)
{ {
trash_empty = katze_array_is_empty (browser->trash); gboolean trash_empty = katze_array_is_empty (browser->trash);
_action_set_sensitive (browser, "UndoTabClose", !trash_empty); _action_set_sensitive (browser, "UndoTabClose", !trash_empty);
_action_set_sensitive (browser, "Trash", !trash_empty); _action_set_sensitive (browser, "Trash", !trash_empty);
} }
@ -1577,15 +1576,11 @@ _midori_browser_add_tab (MidoriBrowser* browser,
katze_object_get_boolean (browser->settings, "open-tabs-next-to-current")) katze_object_get_boolean (browser->settings, "open-tabs-next-to-current"))
{ {
n = gtk_notebook_get_current_page (notebook) + 1; n = gtk_notebook_get_current_page (notebook) + 1;
gtk_notebook_insert_page (notebook, view, tab_label, n);
katze_array_move_item (browser->proxy_array, item, n);
} }
else else
{ n = -1;
gtk_notebook_append_page (notebook, view, tab_label); gtk_notebook_insert_page (notebook, view, tab_label, n);
katze_array_move_item (browser->proxy_array, item, katze_array_move_item (browser->proxy_array, item, n);
gtk_notebook_get_n_pages (notebook));
}
gtk_notebook_set_tab_reorderable (notebook, view, TRUE); gtk_notebook_set_tab_reorderable (notebook, view, TRUE);
gtk_notebook_set_tab_detachable (notebook, view, TRUE); gtk_notebook_set_tab_detachable (notebook, view, TRUE);