Commit 7fe3455c authored by Matthias Clasen's avatar Matthias Clasen

Getting started: Drop ugly signal handler cleanup

I disconnected signals in dispose() to avoid a visible-tab
change notification during destruction, but this is clunky.

Instead, make the notify::visible-tab signal handler bail out
early when called during destruction.
parent b73027aa
......@@ -21,8 +21,6 @@ struct _ExampleAppWindowPrivate
GtkWidget *search;
GtkWidget *searchbar;
GtkWidget *searchentry;
gulong text_changed_handler;
gulong tab_changed_handler;
};
G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW);
......@@ -67,6 +65,9 @@ visible_child_changed (GObject *stack,
{
ExampleAppWindowPrivate *priv;
if (gtk_widget_in_destruction (GTK_WIDGET (win)))
return;
priv = example_app_window_get_instance_private (win);
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (priv->searchbar), FALSE);
}
......@@ -88,10 +89,10 @@ example_app_window_init (ExampleAppWindow *win)
priv->searchbar, "search-mode-enabled",
G_BINDING_BIDIRECTIONAL);
priv->text_changed_handler = g_signal_connect (priv->searchentry, "changed",
G_CALLBACK (search_text_changed), win);
priv->tab_changed_handler = g_signal_connect (priv->stack, "notify::visible-child",
G_CALLBACK (visible_child_changed), win);
g_signal_connect (priv->searchentry, "changed",
G_CALLBACK (search_text_changed), win);
g_signal_connect (priv->stack, "notify::visible-child",
G_CALLBACK (visible_child_changed), win);
}
static void
......@@ -103,18 +104,6 @@ example_app_window_dispose (GObject *object)
win = EXAMPLE_APP_WINDOW (object);
priv = example_app_window_get_instance_private (win);
if (priv->text_changed_handler != 0)
{
g_signal_handler_disconnect (priv->searchentry, priv->text_changed_handler);
priv->text_changed_handler = 0;
}
if (priv->tab_changed_handler != 0)
{
g_signal_handler_disconnect (priv->stack, priv->tab_changed_handler);
priv->tab_changed_handler = 0;
}
g_clear_object (&priv->settings);
G_OBJECT_CLASS (example_app_window_parent_class)->dispose (object);
......
......@@ -24,9 +24,6 @@ struct _ExampleAppWindowPrivate
GtkWidget *gears;
GtkWidget *sidebar;
GtkWidget *words;
gulong text_changed_handler;
gulong tab_changed_handler;
gulong words_changed_handler;
};
G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW);
......@@ -140,6 +137,9 @@ visible_child_changed (GObject *stack,
{
ExampleAppWindowPrivate *priv;
if (gtk_widget_in_destruction (GTK_WIDGET (win)))
return;
priv = example_app_window_get_instance_private (win);
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (priv->searchbar), FALSE);
update_words (win);
......@@ -177,12 +177,12 @@ example_app_window_init (ExampleAppWindow *win)
priv->searchbar, "search-mode-enabled",
G_BINDING_BIDIRECTIONAL);
priv->text_changed_handler = g_signal_connect (priv->searchentry, "changed",
G_CALLBACK (search_text_changed), win);
priv->tab_changed_handler = g_signal_connect (priv->stack, "notify::visible-child",
G_CALLBACK (visible_child_changed), win);
priv->words_changed_handler = g_signal_connect (priv->sidebar, "notify::reveal-child",
G_CALLBACK (words_changed), win);
g_signal_connect (priv->searchentry, "changed",
G_CALLBACK (search_text_changed), win);
g_signal_connect (priv->stack, "notify::visible-child",
G_CALLBACK (visible_child_changed), win);
g_signal_connect (priv->sidebar, "notify::reveal-child",
G_CALLBACK (words_changed), win);
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/gears-menu.ui");
menu = G_MENU_MODEL (gtk_builder_get_object (builder, "menu"));
......@@ -203,24 +203,6 @@ example_app_window_dispose (GObject *object)
win = EXAMPLE_APP_WINDOW (object);
priv = example_app_window_get_instance_private (win);
if (priv->text_changed_handler != 0)
{
g_signal_handler_disconnect (priv->searchentry, priv->text_changed_handler);
priv->text_changed_handler = 0;
}
if (priv->tab_changed_handler != 0)
{
g_signal_handler_disconnect (priv->stack, priv->tab_changed_handler);
priv->tab_changed_handler = 0;
}
if (priv->words_changed_handler != 0)
{
g_signal_handler_disconnect (priv->sidebar, priv->words_changed_handler);
priv->words_changed_handler = 0;
}
g_clear_object (&priv->settings);
G_OBJECT_CLASS (example_app_window_parent_class)->dispose (object);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment