diff options
author | Matthias Clasen <mclasen@redhat.com> | 2013-07-27 20:33:08 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2013-07-27 21:00:33 -0400 |
commit | c9ce98714da965062f514aa0ec8092a40bbe087a (patch) | |
tree | 3dfb70ca9d723fc0dd550ad07f4b060ff834c6aa /examples/application9 | |
parent | 3bb059b6e869b8d4c8d5dda2b16fbc95347e0313 (diff) | |
download | gtk+-c9ce98714da965062f514aa0ec8092a40bbe087a.tar.gz |
example: Use declared callbacks where possible
Replace manual signal connections with signal handlers
declared in the ui file, where possible.
Diffstat (limited to 'examples/application9')
-rw-r--r-- | examples/application9/exampleappprefs.c | 12 | ||||
-rw-r--r-- | examples/application9/exampleappwin.c | 22 | ||||
-rw-r--r-- | examples/application9/prefs.ui | 1 | ||||
-rw-r--r-- | examples/application9/window.ui | 2 |
4 files changed, 23 insertions, 14 deletions
diff --git a/examples/application9/exampleappprefs.c b/examples/application9/exampleappprefs.c index bb089e6f1e..8cd5d5e3a3 100644 --- a/examples/application9/exampleappprefs.c +++ b/examples/application9/exampleappprefs.c @@ -21,12 +21,17 @@ struct _ExampleAppPrefsPrivate GSettings *settings; GtkWidget *font; GtkWidget *transition; - GtkWidget *close; }; G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppPrefs, example_app_prefs, GTK_TYPE_DIALOG) static void +preferences_closed (GtkWidget *button) +{ + gtk_widget_destroy (gtk_widget_get_toplevel (button)); +} + +static void example_app_prefs_init (ExampleAppPrefs *prefs) { ExampleAppPrefsPrivate *priv; @@ -41,8 +46,6 @@ example_app_prefs_init (ExampleAppPrefs *prefs) g_settings_bind (priv->settings, "transition", priv->transition, "active-id", G_SETTINGS_BIND_DEFAULT); - g_signal_connect_swapped (priv->close, "clicked", - G_CALLBACK (gtk_widget_destroy), prefs); } static void @@ -65,7 +68,8 @@ example_app_prefs_class_init (ExampleAppPrefsClass *class) "/org/gtk/exampleapp/prefs.ui"); gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (class), ExampleAppPrefs, font); gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (class), ExampleAppPrefs, transition); - gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (class), ExampleAppPrefs, close); + + gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (class), preferences_closed); } ExampleAppPrefs * diff --git a/examples/application9/exampleappwin.c b/examples/application9/exampleappwin.c index 4dfe440ce3..26779e942c 100644 --- a/examples/application9/exampleappwin.c +++ b/examples/application9/exampleappwin.c @@ -31,9 +31,9 @@ struct _ExampleAppWindowPrivate G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW); static void -search_text_changed (GtkEntry *entry, - ExampleAppWindow *win) +search_text_changed (GtkEntry *entry) { + ExampleAppWindow *win; ExampleAppWindowPrivate *priv; const gchar *text; GtkWidget *tab; @@ -46,6 +46,7 @@ search_text_changed (GtkEntry *entry, if (text[0] == '\0') return; + win = EXAMPLE_APP_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (entry))); priv = example_app_window_get_instance_private (win); tab = gtk_stack_get_visible_child (GTK_STACK (priv->stack)); @@ -172,15 +173,16 @@ update_lines (ExampleAppWindow *win) } static void -visible_child_changed (GObject *stack, - GParamSpec *pspec, - ExampleAppWindow *win) +visible_child_changed (GObject *stack, + GParamSpec *pspec) { + ExampleAppWindow *win; ExampleAppWindowPrivate *priv; - if (gtk_widget_in_destruction (GTK_WIDGET (win))) + if (gtk_widget_in_destruction (GTK_WIDGET (stack))) return; + win = EXAMPLE_APP_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (stack))); priv = example_app_window_get_instance_private (win); gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (priv->searchbar), FALSE); update_words (win); @@ -219,10 +221,6 @@ example_app_window_init (ExampleAppWindow *win) priv->searchbar, "search-mode-enabled", G_BINDING_BIDIRECTIONAL); - 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); @@ -265,6 +263,7 @@ example_app_window_class_init (ExampleAppWindowClass *class) gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class), "/org/gtk/exampleapp/window.ui"); + gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (class), ExampleAppWindow, stack); gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (class), ExampleAppWindow, search); gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (class), ExampleAppWindow, searchbar); @@ -274,6 +273,9 @@ example_app_window_class_init (ExampleAppWindowClass *class) gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (class), ExampleAppWindow, sidebar); gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (class), ExampleAppWindow, lines); gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (class), ExampleAppWindow, lines_label); + + gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (class), search_text_changed); + gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (class), visible_child_changed); } ExampleAppWindow * diff --git a/examples/application9/prefs.ui b/examples/application9/prefs.ui index 4e846b8e15..49781d194c 100644 --- a/examples/application9/prefs.ui +++ b/examples/application9/prefs.ui @@ -69,6 +69,7 @@ <property name="visible">True</property> <child> <object class="GtkButton" id="close"> + <signal name="clicked" handler="preferences_closed"/> <property name="visible">True</property> <property name="label">_Close</property> <property name="use-underline">True</property> diff --git a/examples/application9/window.ui b/examples/application9/window.ui index 915dac6327..16046dbbc6 100644 --- a/examples/application9/window.ui +++ b/examples/application9/window.ui @@ -73,6 +73,7 @@ <property name="visible">True</property> <child> <object class="GtkSearchEntry" id="searchentry"> + <signal name="changed" handler="search_text_changed"/> <property name="visible">True</property> </object> </child> @@ -102,6 +103,7 @@ </child> <child> <object class="GtkStack" id="stack"> + <signal name="notify::visible-child" handler="visible_child_changed"/> <property name="visible">True</property> </object> </child> |