From e698ba33800bf3461ede2d6f9cf39e80313da965 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Wed, 7 Dec 2011 22:31:13 +0100 Subject: [PATCH] Introduce helper for correctly restoring tabs We need to ensure a reference on the item. --- midori/midori-browser.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/midori/midori-browser.c b/midori/midori-browser.c index fa96a55a..38b326fe 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -2817,6 +2817,19 @@ _action_trash_populate_popup (GtkAction* action, gtk_widget_show (menuitem); } +static gint +midori_browser_restore_tab (MidoriBrowser* browser, + KatzeItem* item) +{ + gint n; + + g_object_ref (item); + katze_array_remove_item (browser->trash, item); + n = midori_browser_add_item (browser, item); + g_object_unref (item); + return n; +} + static gboolean _action_trash_activate_item_alt (GtkAction* action, KatzeItem* item, @@ -2825,17 +2838,13 @@ _action_trash_activate_item_alt (GtkAction* action, { if (MIDORI_EVENT_NEW_TAB (gtk_get_current_event ())) { - guint n; - katze_array_remove_item (browser->trash, item); - n = midori_browser_add_item (browser, item); - midori_browser_set_current_page_smartly (browser, n); + midori_browser_set_current_page_smartly (browser, + midori_browser_restore_tab (browser, item)); } else if (button == 1) { - guint n; - katze_array_remove_item (browser->trash, item); - n = midori_browser_add_item (browser, item); - midori_browser_set_current_page (browser, n); + midori_browser_set_current_page (browser, + midori_browser_restore_tab (browser, item)); } return TRUE; @@ -5107,7 +5116,6 @@ _action_undo_tab_close_activate (GtkAction* action, { guint last; KatzeItem* item; - guint n; if (!browser->trash) return; @@ -5115,9 +5123,8 @@ _action_undo_tab_close_activate (GtkAction* action, /* Reopen the most recent trash item */ last = katze_array_get_length (browser->trash) - 1; item = katze_array_get_nth_item (browser->trash, last); - katze_array_remove_item (browser->trash, item); - n = midori_browser_add_item (browser, item); - midori_browser_set_current_page (browser, n); + midori_browser_set_current_page (browser, + midori_browser_restore_tab (browser, item)); } static void -- 2.39.5