[gnome-builder] libide/tweaks: port IdeTweaksEntry to IdeTweaksBinding



commit ac01dc1ec024cc0bb63270204201c4c508126362
Author: Christian Hergert <chergert redhat com>
Date:   Wed Aug 24 02:25:02 2022 -0700

    libide/tweaks: port IdeTweaksEntry to IdeTweaksBinding

 src/libide/tweaks/ide-tweaks-entry.c | 56 ++----------------------------------
 src/libide/tweaks/ide-tweaks-entry.h | 18 +++---------
 src/plugins/buildui/tweaks.ui        | 12 +++++---
 3 files changed, 15 insertions(+), 71 deletions(-)
---
diff --git a/src/libide/tweaks/ide-tweaks-entry.c b/src/libide/tweaks/ide-tweaks-entry.c
index b701c9bca..822e17d27 100644
--- a/src/libide/tweaks/ide-tweaks-entry.c
+++ b/src/libide/tweaks/ide-tweaks-entry.c
@@ -30,14 +30,10 @@ struct _IdeTweaksEntry
 {
   IdeTweaksWidget parent_instance;
   char *title;
-  char *property_name;
-  GObject *object;
 };
 
 enum {
   PROP_0,
-  PROP_OBJECT,
-  PROP_PROPERTY_NAME,
   PROP_TITLE,
   N_PROPS
 };
@@ -51,6 +47,7 @@ ide_tweaks_entry_create_for_item (IdeTweaksWidget *widget,
                                   IdeTweaksItem   *item)
 {
   IdeTweaksEntry *info = (IdeTweaksEntry *)item;
+  IdeTweaksBinding *binding;
   AdwEntryRow *row;
 
   g_assert (IDE_IS_TWEAKS_ENTRY (widget));
@@ -60,9 +57,8 @@ ide_tweaks_entry_create_for_item (IdeTweaksWidget *widget,
                       "title", info->title,
                       NULL);
 
-  if (info->object && info->property_name)
-    g_object_bind_property (info->object, info->property_name, row, "text",
-                            G_BINDING_SYNC_CREATE);
+  if ((binding = ide_tweaks_widget_get_binding (IDE_TWEAKS_WIDGET (info))))
+    ide_tweaks_binding_bind (binding, row, "text");
 
   return GTK_WIDGET (row);
 }
@@ -72,8 +68,6 @@ ide_tweaks_entry_dispose (GObject *object)
 {
   IdeTweaksEntry *self = (IdeTweaksEntry *)object;
 
-  g_clear_object (&self->object);
-  g_clear_pointer (&self->property_name, g_free);
   g_clear_pointer (&self->title, g_free);
 
   G_OBJECT_CLASS (ide_tweaks_entry_parent_class)->dispose (object);
@@ -89,12 +83,7 @@ ide_tweaks_entry_get_property (GObject    *object,
 
   switch (prop_id)
     {
-    case PROP_OBJECT:
-      g_value_set_object (value, ide_tweaks_entry_get_object (self));
-      break;
-
     IDE_GET_PROPERTY_STRING (ide_tweaks_entry, title, TITLE);
-    IDE_GET_PROPERTY_STRING (ide_tweaks_entry, property_name, PROPERTY_NAME);
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -110,12 +99,7 @@ ide_tweaks_entry_set_property (GObject      *object,
 
   switch (prop_id)
     {
-    case PROP_OBJECT:
-      ide_tweaks_entry_set_object (self, g_value_get_object (value));
-      break;
-
     IDE_SET_PROPERTY_STRING (ide_tweaks_entry, title, TITLE);
-    IDE_SET_PROPERTY_STRING (ide_tweaks_entry, property_name, PROPERTY_NAME);
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -133,13 +117,7 @@ ide_tweaks_entry_class_init (IdeTweaksEntryClass *klass)
 
   tweaks_widget_class->create_for_item = ide_tweaks_entry_create_for_item;
 
-  properties[PROP_OBJECT] =
-    g_param_spec_object ("object", NULL, NULL,
-                         G_TYPE_OBJECT,
-                         (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
-
   IDE_DEFINE_STRING_PROPERTY ("title", NULL, G_PARAM_READWRITE, TITLE);
-  IDE_DEFINE_STRING_PROPERTY ("property-name", NULL, G_PARAM_READWRITE, PROPERTY_NAME);
 
   g_object_class_install_properties (object_class, N_PROPS, properties);
 }
@@ -157,31 +135,3 @@ ide_tweaks_entry_new (void)
 
 IDE_DEFINE_STRING_GETTER (ide_tweaks_entry, IdeTweaksEntry, IDE_TYPE_TWEAKS_ENTRY, title)
 IDE_DEFINE_STRING_SETTER (ide_tweaks_entry, IdeTweaksEntry, IDE_TYPE_TWEAKS_ENTRY, title, TITLE)
-
-IDE_DEFINE_STRING_GETTER (ide_tweaks_entry, IdeTweaksEntry, IDE_TYPE_TWEAKS_ENTRY, property_name)
-IDE_DEFINE_STRING_SETTER (ide_tweaks_entry, IdeTweaksEntry, IDE_TYPE_TWEAKS_ENTRY, property_name, 
PROPERTY_NAME)
-
-/**
- * ide_tweaks_entry_get_object:
- * @self: a #IdeTweaksEntry
- *
- * Returns: (transfer none) (nullable): a #GObject or %NULL
- */
-GObject *
-ide_tweaks_entry_get_object (IdeTweaksEntry *self)
-{
-  g_return_val_if_fail (IDE_IS_TWEAKS_ENTRY (self), NULL);
-
-  return self->object;
-}
-
-void
-ide_tweaks_entry_set_object (IdeTweaksEntry *self,
-                             GObject        *object)
-{
-  g_return_if_fail (IDE_IS_TWEAKS_ENTRY (self));
-  g_return_if_fail (!object || G_IS_OBJECT (object));
-
-  if (g_set_object (&self->object, object))
-    g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_OBJECT]);
-}
diff --git a/src/libide/tweaks/ide-tweaks-entry.h b/src/libide/tweaks/ide-tweaks-entry.h
index e55e7c4d0..319db743f 100644
--- a/src/libide/tweaks/ide-tweaks-entry.h
+++ b/src/libide/tweaks/ide-tweaks-entry.h
@@ -34,21 +34,11 @@ IDE_AVAILABLE_IN_ALL
 G_DECLARE_FINAL_TYPE (IdeTweaksEntry, ide_tweaks_entry, IDE, TWEAKS_ENTRY, IdeTweaksWidget)
 
 IDE_AVAILABLE_IN_ALL
-IdeTweaksEntry *ide_tweaks_entry_new               (void);
+IdeTweaksEntry *ide_tweaks_entry_new       (void);
 IDE_AVAILABLE_IN_ALL
-const char     *ide_tweaks_entry_get_title         (IdeTweaksEntry *self);
+const char     *ide_tweaks_entry_get_title (IdeTweaksEntry *self);
 IDE_AVAILABLE_IN_ALL
-void            ide_tweaks_entry_set_title         (IdeTweaksEntry *self,
-                                                    const char     *title);
-IDE_AVAILABLE_IN_ALL
-GObject        *ide_tweaks_entry_get_object        (IdeTweaksEntry *self);
-IDE_AVAILABLE_IN_ALL
-void            ide_tweaks_entry_set_object        (IdeTweaksEntry *self,
-                                                    GObject        *object);
-IDE_AVAILABLE_IN_ALL
-const char     *ide_tweaks_entry_get_property_name (IdeTweaksEntry *self);
-IDE_AVAILABLE_IN_ALL
-void            ide_tweaks_entry_set_property_name (IdeTweaksEntry *self,
-                                                    const char     *property_name);
+void            ide_tweaks_entry_set_title (IdeTweaksEntry *self,
+                                            const char     *title);
 
 G_END_DECLS
diff --git a/src/plugins/buildui/tweaks.ui b/src/plugins/buildui/tweaks.ui
index 88dd3656b..2b5874f7d 100644
--- a/src/plugins/buildui/tweaks.ui
+++ b/src/plugins/buildui/tweaks.ui
@@ -162,10 +162,14 @@
                         <child>
                           <object class="IdeTweaksEntry" id="config_opts_entry">
                             <property name="title" translatable="yes">Configure Options</property>
-                            <property name="property-name">config-opts</property>
-                            <binding name="object">
-                              <lookup name="item">config_factory</lookup>
-                            </binding>
+                            <property name="binding">
+                              <object class="IdeTweaksProperty">
+                                <property name="name">config-opts</property>
+                                <binding name="object">
+                                  <lookup name="item">config_factory</lookup>
+                                </binding>
+                              </object>
+                            </property>
                           </object>
                         </child>
                         <child>


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