From: Christian Dywan Date: Tue, 3 Jul 2012 23:18:13 +0000 (+0200) Subject: Split connecting and adding tabs X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=120f7440f6c6294fce8adfd495b5fcb897cf559e;p=midori Split connecting and adding tabs This is necessary to correctly use Granite notebook API. Fixes: https://bugs.launchpad.net/midori/+bug/1020346 --- diff --git a/midori/midori-browser.c b/midori/midori-browser.c index b7cd0008..8c6087ab 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -254,13 +254,12 @@ static gboolean _toggle_tabbar_smartly (MidoriBrowser* browser, gboolean ignore_fullscreen) { + gboolean has_tabs = midori_browser_get_n_pages (browser) > 1; #ifdef HAVE_GRANITE - gboolean has_tabs = !(midori_browser_is_fullscreen (browser) || ignore_fullscreen); + gboolean show_tabs = !(midori_browser_is_fullscreen (browser) || ignore_fullscreen); granite_widgets_dynamic_notebook_set_show_tabs ( - GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook), has_tabs); + GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook), show_tabs); #else - gboolean has_tabs = - gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), 1) != NULL; gboolean show_tabs = browser->show_tabs && (!midori_browser_is_fullscreen (browser) || ignore_fullscreen) @@ -1522,7 +1521,7 @@ midori_view_search_text_cb (GtkWidget* view, midori_findbar_search_text (MIDORI_FINDBAR (browser->find), view, found, typing); } -static gint +gint midori_browser_get_n_pages (MidoriBrowser* browser) { #ifdef HAVE_GRANITE @@ -1631,20 +1630,13 @@ midori_browser_notebook_size_allocate_cb (GtkWidget* widget, } static void -_midori_browser_add_tab (MidoriBrowser* browser, - GtkWidget* view) +midori_browser_connect_tab (MidoriBrowser* browser, + GtkWidget* view) { - GtkWidget* notebook = browser->notebook; -#ifndef HAVE_GRANITE - GtkWidget* tab_label; -#endif - KatzeItem* item; - guint n; - - gtk_widget_set_can_focus (view, TRUE); - item = midori_view_get_proxy_item (MIDORI_VIEW (view)); + KatzeItem* item = midori_view_get_proxy_item (MIDORI_VIEW (view)); katze_array_add_item (browser->proxy_array, item); + gtk_widget_set_can_focus (view, TRUE); g_object_connect (view, "signal::notify::icon", midori_view_notify_icon_cb, browser, @@ -1684,7 +1676,23 @@ _midori_browser_add_tab (MidoriBrowser* browser, midori_view_add_speed_dial_cb, browser, "signal::leave-notify-event", midori_browser_tab_leave_notify_event_cb, browser, + "signal::destroy", + midori_browser_tab_destroy_cb, browser, NULL); +} + +static void +_midori_browser_add_tab (MidoriBrowser* browser, + GtkWidget* view) +{ + GtkWidget* notebook = browser->notebook; + KatzeItem* item = midori_view_get_proxy_item (MIDORI_VIEW (view)); + #ifndef HAVE_GRANITE + GtkWidget* tab_label; + #endif + guint n; + + midori_browser_connect_tab (browser, view); if (!katze_item_get_meta_boolean (item, "append") && katze_object_get_boolean (browser->settings, "open-tabs-next-to-current")) @@ -1694,6 +1702,8 @@ _midori_browser_add_tab (MidoriBrowser* browser, } else n = -1; + katze_item_set_meta_integer (item, "append", -1); + #ifdef HAVE_GRANITE granite_widgets_dynamic_notebook_insert_tab ( GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (notebook), @@ -1707,15 +1717,10 @@ _midori_browser_add_tab (MidoriBrowser* browser, gtk_notebook_insert_page (GTK_NOTEBOOK (notebook), view, tab_label, n); gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (notebook), view, TRUE); gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (notebook), view, TRUE); + midori_browser_notebook_size_allocate_cb (browser->notebook, NULL, browser); #endif - katze_item_set_meta_integer (item, "append", -1); - - /* We want the tab to be removed if the widget is destroyed */ - g_signal_connect (view, "destroy", - G_CALLBACK (midori_browser_tab_destroy_cb), browser); _midori_browser_update_actions (browser); - midori_browser_notebook_size_allocate_cb (browser->notebook, NULL, browser); } static void @@ -5155,8 +5160,10 @@ midori_browser_notebook_tab_added_cb (GtkWidget* notebook, { GtkWidget* view = midori_view_new_with_item (NULL, browser->settings); midori_view_set_tab (MIDORI_VIEW (view), tab); - gint n = midori_browser_add_tab (browser, view); - midori_browser_set_current_page (browser, n); + midori_browser_connect_tab (browser, view); + /* FIXME: signal add-tab */ + _midori_browser_update_actions (browser); + midori_view_set_uri (MIDORI_VIEW (view), ""); } static void diff --git a/midori/midori-browser.h b/midori/midori-browser.h index 2f2cf444..bedbacf1 100644 --- a/midori/midori-browser.h +++ b/midori/midori-browser.h @@ -159,6 +159,9 @@ midori_browser_page_num (MidoriBrowser* browser, GList* midori_browser_get_tabs (MidoriBrowser* browser); +gint +midori_browser_get_n_pages (MidoriBrowser* browser); + KatzeArray* midori_browser_get_proxy_items (MidoriBrowser* browser); diff --git a/midori/midori-view.c b/midori/midori-view.c index a8a34f74..485217f3 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -672,8 +672,9 @@ midori_view_set_title (MidoriView* view, const gchar* title) if (uri) soup_uri_free (uri); #ifdef HAVE_GRANITE - g_object_set (midori_view_get_tab (view), - "label", display_title, "ellipsize-mode", view->ellipsize, NULL); + if (view->tab) + g_object_set (view->tab, + "label", display_title, "ellipsize-mode", view->ellipsize, NULL); #else if (view->tab_label) { @@ -703,7 +704,8 @@ midori_view_apply_icon (MidoriView* view, g_object_notify (G_OBJECT (view), "icon"); #ifdef HAVE_GRANITE - g_object_set (midori_view_get_tab (view), "icon", icon, NULL); + if (view->tab) + g_object_set (view->tab, "icon", icon, NULL); #else if (view->tab_icon) { @@ -943,8 +945,9 @@ midori_view_update_load_status (MidoriView* view, g_object_notify (G_OBJECT (view), "load-status"); #ifdef HAVE_GRANITE - g_object_set (midori_view_get_tab (view), - "working", view->load_status != MIDORI_LOAD_FINISHED, NULL); + if (view->tab) + g_object_set (view->tab, + "working", view->load_status != MIDORI_LOAD_FINISHED, NULL); #else if (view->tab_icon) katze_throbber_set_animated (KATZE_THROBBER (view->tab_icon), @@ -3322,8 +3325,9 @@ midori_view_set_property (GObject* object, g_signal_handlers_unblock_by_func (view->item, midori_view_item_meta_data_changed, view); #ifdef HAVE_GRANITE - g_object_set (midori_view_get_tab (view), "label", - "fixed", view->minimized, NULL); + if (view->tab) + g_object_set (view->tab, "label", + "fixed", view->minimized, NULL); //view->minimized ? NULL : midori_view_get_display_title(view), NULL); #else if (view->tab_label)