Ensure REMOVE_TAB emission, don't alter session when destroying

This commit is contained in:
Christian Dywan 2008-07-25 12:45:50 +02:00
parent 3301b37803
commit 549310a7cd
2 changed files with 38 additions and 4 deletions

View file

@ -358,6 +358,15 @@ midori_browser_session_cb (MidoriBrowser* browser,
g_free (config_path);
}
void
midori_browser_weak_notify_cb (MidoriBrowser* browser,
KatzeXbelItem* session)
{
g_object_disconnect (browser, "any-signal",
G_CALLBACK (midori_browser_session_cb), session, NULL);
}
int
main (int argc,
char** argv)
@ -598,6 +607,8 @@ main (int argc,
G_CALLBACK (midori_browser_session_cb), session);
g_signal_connect_after (browser, "remove-tab",
G_CALLBACK (midori_browser_session_cb), session);
g_object_weak_ref (G_OBJECT (session),
(GWeakNotify)(midori_browser_weak_notify_cb), browser);
/* Load extensions */
JSGlobalContextRef js_context = gjs_global_context_new ();

View file

@ -115,6 +115,9 @@ enum
static guint signals[LAST_SIGNAL];
static void
midori_browser_dispose (GObject* object);
static void
midori_browser_finalize (GObject* object);
@ -787,6 +790,13 @@ midori_browser_tab_destroy_cb (GtkWidget* widget,
}
_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);
return FALSE;
}
@ -1190,6 +1200,7 @@ midori_browser_class_init (MidoriBrowserClass* class)
class->quit = _midori_browser_quit;
GObjectClass* gobject_class = G_OBJECT_CLASS (class);
gobject_class->dispose = midori_browser_dispose;
gobject_class->finalize = midori_browser_finalize;
gobject_class->set_property = midori_browser_set_property;
gobject_class->get_property = midori_browser_get_property;
@ -2898,7 +2909,7 @@ midori_browser_size_allocate_cb (MidoriBrowser* browser,
static void
midori_browser_destroy_cb (MidoriBrowser* browser)
{
/* Destroy tabs first, so widgets can still see window elements on destroy */
/* Destroy tabs first, so child widgets don't need special care */
gtk_container_foreach (GTK_CONTAINER (browser->notebook),
(GtkCallback) gtk_widget_destroy, NULL);
}
@ -3560,6 +3571,18 @@ midori_browser_init (MidoriBrowser* browser)
browser->close_buttons = NULL;
}
static void
midori_browser_dispose (GObject* object)
{
MidoriBrowser* browser = MIDORI_BROWSER (object);
/* We are done, the session mustn't change anymore */
if (browser->proxy_xbel_folder)
katze_object_assign (browser->proxy_xbel_folder, NULL);
G_OBJECT_CLASS (midori_browser_parent_class)->dispose (object);
}
static void
midori_browser_finalize (GObject* object)
{
@ -3569,9 +3592,6 @@ midori_browser_finalize (GObject* object)
g_list_free (browser->tab_titles);
g_list_free (browser->close_buttons);
if (browser->proxy_xbel_folder)
katze_xbel_item_unref (browser->proxy_xbel_folder);
if (browser->settings)
g_object_unref (browser->settings);
if (browser->trash)
@ -4133,6 +4153,9 @@ midori_browser_get_current_web_view (MidoriBrowser* browser)
*
* Note that this implicitly creates proxy xbel items of all web views.
*
* Note: Calling this function doesn't add a reference and the browser
* may release its reference at some point.
*
* Return value: the proxy #KatzeXbelItem
**/
KatzeXbelItem*