[gnome-builder] libide/tweaks: add project id to toplevel item



commit 0fafdd772448419c7f997488517b372251ccf5c4
Author: Christian Hergert <chergert redhat com>
Date:   Sat Aug 6 00:40:10 2022 -0700

    libide/tweaks: add project id to toplevel item

 src/libide/tweaks/ide-tweaks.c | 98 ++++++++++++++++++++++++++++++++++++++++++
 src/libide/tweaks/ide-tweaks.h | 21 +++++----
 2 files changed, 111 insertions(+), 8 deletions(-)
---
diff --git a/src/libide/tweaks/ide-tweaks.c b/src/libide/tweaks/ide-tweaks.c
index 8f32aebd2..f199ea7b4 100644
--- a/src/libide/tweaks/ide-tweaks.c
+++ b/src/libide/tweaks/ide-tweaks.c
@@ -31,10 +31,37 @@ struct _IdeTweaks
 {
   IdeTweaksItem  parent_instance;
   GtkBuilder    *builder;
+  char          *project_id;
 };
 
 G_DEFINE_FINAL_TYPE (IdeTweaks, ide_tweaks, IDE_TYPE_TWEAKS_ITEM)
 
+enum {
+  PROP_0,
+  PROP_PROJECT_ID,
+  N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
+G_GNUC_PRINTF (2, 3)
+static char *
+ide_tweaks_format (IdeTweaks  *self,
+                   const char *format,
+                   ...)
+{
+  va_list args;
+  char *ret;
+
+  g_assert (IDE_IS_TWEAKS (self));
+
+  va_start (args, format);
+  ret = g_strdup_vprintf (format, args);
+  va_end (args);
+
+  return ret;
+}
+
 static gboolean
 ide_tweaks_accepts (IdeTweaksItem *item,
                     IdeTweaksItem *child)
@@ -51,10 +78,49 @@ ide_tweaks_dispose (GObject *object)
   IdeTweaks *self = (IdeTweaks *)object;
 
   g_clear_object (&self->builder);
+  g_clear_pointer (&self->project_id, g_free);
 
   G_OBJECT_CLASS (ide_tweaks_parent_class)->dispose (object);
 }
 
+static void
+ide_tweaks_get_property (GObject    *object,
+                         guint       prop_id,
+                         GValue     *value,
+                         GParamSpec *pspec)
+{
+  IdeTweaks *self = IDE_TWEAKS (object);
+
+  switch (prop_id)
+    {
+    case PROP_PROJECT_ID:
+      g_value_set_string (value, ide_tweaks_get_project_id (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_tweaks_set_property (GObject      *object,
+                         guint         prop_id,
+                         const GValue *value,
+                         GParamSpec   *pspec)
+{
+  IdeTweaks *self = IDE_TWEAKS (object);
+
+  switch (prop_id)
+    {
+    case PROP_PROJECT_ID:
+      ide_tweaks_set_project_id (self, g_value_get_string (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
 static void
 ide_tweaks_class_init (IdeTweaksClass *klass)
 {
@@ -62,15 +128,29 @@ ide_tweaks_class_init (IdeTweaksClass *klass)
   IdeTweaksItemClass *item_class = IDE_TWEAKS_ITEM_CLASS (klass);
 
   object_class->dispose = ide_tweaks_dispose;
+  object_class->get_property = ide_tweaks_get_property;
+  object_class->set_property = ide_tweaks_set_property;
 
   item_class->accepts = ide_tweaks_accepts;
+
+  properties[PROP_PROJECT_ID] =
+    g_param_spec_string ("project-id", NULL, NULL,
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
 }
 
 static void
 ide_tweaks_init (IdeTweaks *self)
 {
+  g_autoptr(GtkBuilderCScope) scope = (GtkBuilderCScope *)gtk_builder_cscope_new ();
+
   self->builder = gtk_builder_new ();
   gtk_builder_set_current_object (self->builder, G_OBJECT (self));
+
+  gtk_builder_cscope_add_callback_symbol (scope, "format", (gpointer)ide_tweaks_format);
+  gtk_builder_set_scope (self->builder, GTK_BUILDER_SCOPE (scope));
 }
 
 IdeTweaks *
@@ -112,3 +192,21 @@ ide_tweaks_expose_object (IdeTweaks  *self,
 
   gtk_builder_expose_object (self->builder, name, object);
 }
+
+const char *
+ide_tweaks_get_project_id (IdeTweaks *self)
+{
+  g_return_val_if_fail (IDE_IS_TWEAKS (self), NULL);
+
+  return self->project_id;
+}
+
+void
+ide_tweaks_set_project_id (IdeTweaks  *self,
+                           const char *project_id)
+{
+  g_return_if_fail (IDE_IS_TWEAKS (self));
+
+  if (ide_set_string (&self->project_id, project_id))
+    g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_PROJECT_ID]);
+}
diff --git a/src/libide/tweaks/ide-tweaks.h b/src/libide/tweaks/ide-tweaks.h
index 7f1a1b372..52d7cfa02 100644
--- a/src/libide/tweaks/ide-tweaks.h
+++ b/src/libide/tweaks/ide-tweaks.h
@@ -34,15 +34,20 @@ IDE_AVAILABLE_IN_ALL
 G_DECLARE_FINAL_TYPE (IdeTweaks, ide_tweaks, IDE, TWEAKS, IdeTweaksItem)
 
 IDE_AVAILABLE_IN_ALL
-IdeTweaks *ide_tweaks_new            (void);
+IdeTweaks *ide_tweaks_new             (void);
 IDE_AVAILABLE_IN_ALL
-void       ide_tweaks_expose_object  (IdeTweaks     *self,
-                                      const char    *name,
-                                      GObject       *object);
+const char *ide_tweaks_get_project_id (IdeTweaks     *self);
 IDE_AVAILABLE_IN_ALL
-gboolean   ide_tweaks_load_from_file (IdeTweaks     *self,
-                                      GFile         *file,
-                                      GCancellable  *cancellable,
-                                      GError       **error);
+void        ide_tweaks_set_project_id (IdeTweaks     *self,
+                                       const char    *project_id);
+IDE_AVAILABLE_IN_ALL
+void       ide_tweaks_expose_object   (IdeTweaks     *self,
+                                       const char    *name,
+                                       GObject       *object);
+IDE_AVAILABLE_IN_ALL
+gboolean   ide_tweaks_load_from_file  (IdeTweaks     *self,
+                                       GFile         *file,
+                                       GCancellable  *cancellable,
+                                       GError       **error);
 
 G_END_DECLS


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