[gtk/ebassi/settings-builder: 3/3] examples: Update to bind settings inside UI definitions




commit 24b69a9a10d80e5b00a29d4c3fcb9b888ace2055
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Sep 9 19:22:48 2021 +0100

    examples: Update to bind settings inside UI definitions

 examples/application9/exampleappprefs.c | 33 ++++-----------------------------
 examples/application9/prefs.ui          |  2 ++
 2 files changed, 6 insertions(+), 29 deletions(-)
---
diff --git a/examples/application9/exampleappprefs.c b/examples/application9/exampleappprefs.c
index 4bdf6542ca..a9bb251096 100644
--- a/examples/application9/exampleappprefs.c
+++ b/examples/application9/exampleappprefs.c
@@ -7,10 +7,6 @@
 struct _ExampleAppPrefs
 {
   GtkDialog parent;
-
-  GSettings *settings;
-  GtkWidget *font;
-  GtkWidget *transition;
 };
 
 G_DEFINE_TYPE (ExampleAppPrefs, example_app_prefs, GTK_TYPE_DIALOG)
@@ -19,41 +15,20 @@ static void
 example_app_prefs_init (ExampleAppPrefs *prefs)
 {
   gtk_widget_init_template (GTK_WIDGET (prefs));
-  prefs->settings = g_settings_new ("org.gtk.exampleapp");
-
-  g_settings_bind (prefs->settings, "font",
-                   prefs->font, "font",
-                   G_SETTINGS_BIND_DEFAULT);
-  g_settings_bind (prefs->settings, "transition",
-                   prefs->transition, "active-id",
-                   G_SETTINGS_BIND_DEFAULT);
-}
-
-static void
-example_app_prefs_dispose (GObject *object)
-{
-  ExampleAppPrefs *prefs;
-
-  prefs = EXAMPLE_APP_PREFS (object);
-
-  g_clear_object (&prefs->settings);
-
-  G_OBJECT_CLASS (example_app_prefs_parent_class)->dispose (object);
 }
 
 static void
 example_app_prefs_class_init (ExampleAppPrefsClass *class)
 {
-  G_OBJECT_CLASS (class)->dispose = example_app_prefs_dispose;
-
   gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
                                                "/org/gtk/exampleapp/prefs.ui");
-  gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), ExampleAppPrefs, font);
-  gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), ExampleAppPrefs, transition);
 }
 
 ExampleAppPrefs *
 example_app_prefs_new (ExampleAppWindow *win)
 {
-  return g_object_new (EXAMPLE_APP_PREFS_TYPE, "transient-for", win, "use-header-bar", TRUE, NULL);
+  return g_object_new (EXAMPLE_APP_PREFS_TYPE,
+                       "transient-for", win,
+                       "use-header-bar", TRUE,
+                       NULL);
 }
diff --git a/examples/application9/prefs.ui b/examples/application9/prefs.ui
index 04ca33c92d..b9e29c4c7f 100644
--- a/examples/application9/prefs.ui
+++ b/examples/application9/prefs.ui
@@ -28,6 +28,7 @@
             </child>
             <child>
               <object class="GtkFontButton" id="font">
+              <property name="font" bind-settings-schema="org.gtk.exampleapp" bind-settings-key="font"/>
                 <layout>
                   <property name="column">1</property>
                   <property name="row">0</property>
@@ -48,6 +49,7 @@
             </child>
             <child>
               <object class="GtkComboBoxText" id="transition">
+                <property name="active-id" bind-settings-schema="org.gtk.exampleapp" 
bind-settings-key="transition"/>
                 <items>
                   <item translatable="yes" id="none">None</item>
                   <item translatable="yes" id="crossfade">Fade</item>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]