From: Christian Dywan Date: Sat, 14 Jul 2012 22:07:59 +0000 (+0200) Subject: Move tab removal out of the signal X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ac017589942cf3f2bf59bf162c9acd82eff062f;p=midori Move tab removal out of the signal Every caller should use the API to remove a tab to produce consistent behavior. The destroy callback takes care of UI updates. --- diff --git a/extensions/tab-panel.c b/extensions/tab-panel.c index a99a3a2d..24600dfc 100644 --- a/extensions/tab-panel.c +++ b/extensions/tab-panel.c @@ -231,12 +231,12 @@ midori_extension_button_release_event_cb (GtkWidget* widget, if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), event->x, event->y, NULL, &column, NULL, NULL) && column == gtk_tree_view_get_column (GTK_TREE_VIEW (widget), 1)) - gtk_widget_destroy (view); + midori_browser_remove_tab (browser, view); else midori_browser_set_current_tab (browser, view); } else if (event->button == 2) - gtk_widget_destroy (view); + midori_browser_remove_tab (midori_browser_get_for_widget (widget), view); else tab_panel_popup (widget, event, view); diff --git a/midori/main.c b/midori/main.c index e6c121cf..11ffbb1d 100644 --- a/midori/main.c +++ b/midori/main.c @@ -1700,7 +1700,7 @@ midori_inactivity_timeout (gpointer data) GList* data_items = sokoke_register_privacy_item (NULL, NULL, NULL); while ((view = midori_browser_get_nth_tab (mit->browser, i++))) - gtk_widget_destroy (view); + midori_browser_remove_tab (mit->browser, view); midori_browser_set_current_uri (mit->browser, mit->uri); /* Clear all private data */ if (history != NULL) diff --git a/midori/midori-browser.c b/midori/midori-browser.c index fae649c9..1d85da13 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -1602,36 +1602,32 @@ midori_browser_get_n_pages (MidoriBrowser* browser) #endif } -static gboolean -midori_browser_tab_destroy_cb (GtkWidget* widget, +static void +midori_browser_tab_destroy_cb (MidoriView* view, MidoriBrowser* browser) { - KatzeItem* item; - - if (browser->proxy_array && MIDORI_IS_VIEW (widget)) + if (browser->proxy_array) { - item = midori_view_get_proxy_item (MIDORI_VIEW (widget)); - if (browser->trash && !midori_view_is_blank (MIDORI_VIEW (widget))) + KatzeItem* item = midori_view_get_proxy_item (view); + if (browser->trash && !midori_view_is_blank (view)) katze_array_add_item (browser->trash, item); katze_array_remove_item (browser->proxy_array, item); - } - - _midori_browser_update_actions (browser); - - /* This callback must only be called once, but we need to ensure - that "remove-tab" is emitted in any case */ - g_signal_handlers_disconnect_by_func (widget, - midori_browser_tab_destroy_cb, browser); - - g_signal_emit (browser, signals[REMOVE_TAB], 0, widget); /* We don't ever want to be in a situation with no tabs, so just create an empty one if the last one is closed. The only exception is when we are closing the window, which is indicated by the proxy array having been unset. */ - if (browser->proxy_array && !midori_browser_get_current_tab (browser)) - midori_browser_add_uri (browser, ""); - return FALSE; + if (midori_browser_get_n_pages (browser) == 0) + midori_browser_add_uri (browser, ""); + } + + _midori_browser_update_actions (browser); +} + +static void +_midori_browser_remove_tab (MidoriBrowser* browser, + GtkWidget* widget) +{ } #ifndef HAVE_GRANITE @@ -1787,14 +1783,6 @@ _midori_browser_add_tab (MidoriBrowser* browser, _midori_browser_update_actions (browser); } -static void -_midori_browser_remove_tab (MidoriBrowser* browser, - GtkWidget* view) -{ - gtk_widget_destroy (view); - midori_browser_notebook_size_allocate_cb (browser->notebook, NULL, browser); -} - /** * midori_browser_foreach: * @browser: a #MidoriBrowser @@ -2655,15 +2643,16 @@ _action_tab_close_activate (GtkAction* action, MidoriBrowser* browser) { GtkWidget* widget = midori_browser_get_current_tab (browser); + MidoriView* view = MIDORI_VIEW (widget); gboolean last_tab = midori_browser_get_n_pages (browser) == 1; if (last_tab && sokoke_is_app_or_private ()) { gtk_widget_destroy (GTK_WIDGET (browser)); return; } - if (last_tab && midori_view_is_blank (MIDORI_VIEW (widget))) + if (last_tab && midori_view_is_blank (view)) return; - gtk_widget_destroy (widget); + midori_browser_remove_tab (browser, widget); } static void @@ -4267,13 +4256,7 @@ midori_browser_bookmark_open_in_window_activate_cb (GtkWidget* menuitem, item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem"); uri = katze_item_get_uri (item); - - if (uri && *uri) - { - MidoriBrowser* new_browser; - g_signal_emit (browser, signals[NEW_WINDOW], 0, NULL, &new_browser); - midori_browser_add_uri (new_browser, uri); - } + midori_view_new_window_cb (NULL, uri, browser); } static void @@ -5296,6 +5279,17 @@ midori_browser_notebook_tab_added_cb (GtkWidget* notebook, midori_view_set_uri (MIDORI_VIEW (view), ""); } +static gboolean +midori_browser_notebook_tab_removed_cb (GtkWidget* notebook, + GraniteWidgetsTab* tab, + MidoriBrowser* browser) +{ + MidoriView* view = MIDORI_VIEW (granite_widgets_tab_get_page (tab)); + g_signal_emit (browser, signals[REMOVE_TAB], 0, view); + gtk_widget_destroy (view); + return TRUE; +} + static void midori_browser_notebook_tab_switched_cb (GraniteWidgetsDynamicNotebook* notebook, GraniteWidgetsTab* old_tab, @@ -5350,6 +5344,7 @@ midori_browser_notebook_page_removed_cb (GtkWidget* notebook, MidoriBrowser* browser) { _midori_browser_remove_tab (browser, view); + midori_browser_notebook_size_allocate_cb (browser->notebook, NULL, browser); } static gboolean @@ -6556,6 +6551,9 @@ midori_browser_init (MidoriBrowser* browser) g_signal_connect (browser->notebook, "tab-added", G_CALLBACK (midori_browser_notebook_tab_added_cb), browser); + g_signal_connect (browser->notebook, "tab-removed", + G_CALLBACK (midori_browser_notebook_tab_removed_cb), + browser); g_signal_connect (browser->notebook, "tab-switched", G_CALLBACK (midori_browser_notebook_tab_switched_cb), browser); @@ -7622,6 +7620,13 @@ midori_browser_remove_tab (MidoriBrowser* browser, g_return_if_fail (GTK_IS_WIDGET (view)); g_signal_emit (browser, signals[REMOVE_TAB], 0, view); + #ifdef HAVE_GRANITE + granite_widgets_dynamic_notebook_remove_tab ( + GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook), + midori_view_get_tab (MIDORI_VIEW (view))); + #else + gtk_widget_destroy (view); + #endif } /** diff --git a/midori/midori-view.c b/midori/midori-view.c index 9d8eb063..a509f06e 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -4764,7 +4764,7 @@ midori_view_browser_close_tabs_cb (GtkWidget* view, { GtkWidget* remaining_view = data; if (view != remaining_view) - gtk_widget_destroy (view); + midori_browser_remove_tab (midori_browser_get_for_widget (view), view); } static void @@ -4786,7 +4786,7 @@ static void midori_view_tab_label_menu_close_cb (GtkWidget* menuitem, GtkWidget* view) { - gtk_widget_destroy (view); + midori_browser_remove_tab (midori_browser_get_for_widget (view), view); } /** @@ -4883,7 +4883,7 @@ midori_view_tab_label_button_press_event (GtkWidget* tab_label, if (event->button == 2) { /* Close the widget on middle click */ - gtk_widget_destroy (widget); + midori_browser_remove_tab (midori_browser_get_for_widget (widget), widget); return TRUE; } else if (MIDORI_EVENT_CONTEXT_MENU (event)) @@ -4903,7 +4903,7 @@ static void midori_view_tab_close_clicked (GtkWidget* tab_close, GtkWidget* widget) { - gtk_widget_destroy (widget); + midori_browser_remove_tab (midori_browser_get_for_widget (widget), widget); } #if !GTK_CHECK_VERSION (3, 0, 0)