[gnome-builder] libide/tweaks: add section to IdeTweaksPage



commit dafbde9c9c145cbad178e44d973806ad7ad9fdc5
Author: Christian Hergert <chergert redhat com>
Date:   Tue Aug 2 19:04:34 2022 -0700

    libide/tweaks: add section to IdeTweaksPage
    
    Just fetch it from the hierarchy. Factories would be required to yield
    IdeTweaksSection before pages for that to continue working.

 src/libide/tweaks/ide-tweaks-item.c        | 11 ++++----
 src/libide/tweaks/ide-tweaks-page.c        | 41 +++++++++++++++++++++++++++---
 src/libide/tweaks/ide-tweaks-page.h        |  2 ++
 src/libide/tweaks/tests/test2/1.ui         |  2 ++
 src/libide/tweaks/tests/test2/expected.xml |  4 +--
 5 files changed, 49 insertions(+), 11 deletions(-)
---
diff --git a/src/libide/tweaks/ide-tweaks-item.c b/src/libide/tweaks/ide-tweaks-item.c
index 891e252d0..aee7b7c26 100644
--- a/src/libide/tweaks/ide-tweaks-item.c
+++ b/src/libide/tweaks/ide-tweaks-item.c
@@ -573,13 +573,12 @@ _ide_tweaks_item_printf (IdeTweaksItem *self,
               g_value_init (&value, G_TYPE_OBJECT);
               g_object_get_property (G_OBJECT (self), pspec->name, &value);
 
-              if ((obj = g_value_get_object (&value)))
-                type_name = G_OBJECT_TYPE_NAME (obj);
+              if (!(obj = g_value_get_object (&value)) || !G_IS_LIST_MODEL (obj))
+                continue;
 
-              if (G_IS_LIST_MODEL (obj))
-                type_name = generic = g_strdup_printf ("%s<%s>",
-                                                       G_OBJECT_TYPE_NAME (obj),
-                                                       g_type_name (g_list_model_get_item_type (G_LIST_MODEL 
(obj))));
+              type_name = generic = g_strdup_printf ("%s<%s>",
+                                                     G_OBJECT_TYPE_NAME (obj),
+                                                     g_type_name (g_list_model_get_item_type (G_LIST_MODEL 
(obj))));
 
               g_string_append_printf (string, " %s=\"%s\"", pspec->name, type_name);
             }
diff --git a/src/libide/tweaks/ide-tweaks-page.c b/src/libide/tweaks/ide-tweaks-page.c
index 8ee4802f1..51bf0f698 100644
--- a/src/libide/tweaks/ide-tweaks-page.c
+++ b/src/libide/tweaks/ide-tweaks-page.c
@@ -26,6 +26,7 @@
 #include "ide-tweaks-factory.h"
 #include "ide-tweaks-group.h"
 #include "ide-tweaks-page.h"
+#include "ide-tweaks-section.h"
 #include "ide-tweaks-subpage.h"
 
 struct _IdeTweaksPage
@@ -40,6 +41,7 @@ G_DEFINE_FINAL_TYPE (IdeTweaksPage, ide_tweaks_page, IDE_TYPE_TWEAKS_ITEM)
 enum {
   PROP_0,
   PROP_ICON_NAME,
+  PROP_SECTION,
   PROP_TITLE,
   N_PROPS
 };
@@ -62,14 +64,14 @@ ide_tweaks_page_accepts (IdeTweaksItem *item,
 }
 
 static void
-ide_tweaks_page_finalize (GObject *object)
+ide_tweaks_page_dispose (GObject *object)
 {
   IdeTweaksPage *self = (IdeTweaksPage *)object;
 
   g_clear_pointer (&self->icon_name, g_free);
   g_clear_pointer (&self->title, g_free);
 
-  G_OBJECT_CLASS (ide_tweaks_page_parent_class)->finalize (object);
+  G_OBJECT_CLASS (ide_tweaks_page_parent_class)->dispose (object);
 }
 
 static void
@@ -86,6 +88,10 @@ ide_tweaks_page_get_property (GObject    *object,
       g_value_set_string (value, ide_tweaks_page_get_icon_name (self));
       break;
 
+    case PROP_SECTION:
+      g_value_set_object (value, ide_tweaks_page_get_section (self));
+      break;
+
     case PROP_TITLE:
       g_value_set_string (value, ide_tweaks_page_get_title (self));
       break;
@@ -124,7 +130,7 @@ ide_tweaks_page_class_init (IdeTweaksPageClass *klass)
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   IdeTweaksItemClass *item_class = IDE_TWEAKS_ITEM_CLASS (klass);
 
-  object_class->finalize = ide_tweaks_page_finalize;
+  object_class->dispose = ide_tweaks_page_dispose;
   object_class->get_property = ide_tweaks_page_get_property;
   object_class->set_property = ide_tweaks_page_set_property;
 
@@ -134,6 +140,11 @@ ide_tweaks_page_class_init (IdeTweaksPageClass *klass)
     g_param_spec_string ("icon-name", NULL, NULL, NULL,
                          (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
 
+  properties [PROP_SECTION] =
+    g_param_spec_object ("section", NULL, NULL,
+                         IDE_TYPE_TWEAKS_SECTION,
+                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
   properties [PROP_TITLE] =
     g_param_spec_string ("title", NULL, NULL, NULL,
                          (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
@@ -181,3 +192,27 @@ ide_tweaks_page_set_title (IdeTweaksPage *self,
   if (ide_set_string (&self->title, title))
     g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TITLE]);
 }
+
+/**
+ * ide_tweaks_page_get_section:
+ * @self: a #IdeTweaksPage
+ *
+ * Gets the section containing the page.
+ *
+ * Returns: (nullable) (transfer none): an #IdeTweaksItem or %NULL
+ */
+IdeTweaksItem *
+ide_tweaks_page_get_section (IdeTweaksPage *self)
+{
+  IdeTweaksItem *item = (IdeTweaksItem *)self;
+
+  g_return_val_if_fail (IDE_IS_TWEAKS_PAGE (self), NULL);
+
+  while ((item = ide_tweaks_item_get_parent (item)))
+    {
+      if (IDE_IS_TWEAKS_SECTION (item))
+        return item;
+    }
+
+  return NULL;
+}
diff --git a/src/libide/tweaks/ide-tweaks-page.h b/src/libide/tweaks/ide-tweaks-page.h
index c3a3871fb..6b0affbdc 100644
--- a/src/libide/tweaks/ide-tweaks-page.h
+++ b/src/libide/tweaks/ide-tweaks-page.h
@@ -38,6 +38,8 @@ IDE_AVAILABLE_IN_ALL
 void           ide_tweaks_page_set_icon_name (IdeTweaksPage *self,
                                               const char    *icon_name);
 IDE_AVAILABLE_IN_ALL
+IdeTweaksItem *ide_tweaks_page_get_section   (IdeTweaksPage *self);
+IDE_AVAILABLE_IN_ALL
 const char    *ide_tweaks_page_get_title     (IdeTweaksPage *self);
 IDE_AVAILABLE_IN_ALL
 void           ide_tweaks_page_set_title     (IdeTweaksPage *self,
diff --git a/src/libide/tweaks/tests/test2/1.ui b/src/libide/tweaks/tests/test2/1.ui
index 699c83e8d..04cc1e8a3 100644
--- a/src/libide/tweaks/tests/test2/1.ui
+++ b/src/libide/tweaks/tests/test2/1.ui
@@ -4,6 +4,8 @@
       <object class="IdeTweaksSection">
         <child internal-child="languages_page">
           <object class="IdeTweaksPage">
+            <property name="icon-name">preferences-desktop-appearance-symbolic</property>
+            <property name="title">Appearance</property>
             <child internal-child="language_subpage_factory">
               <object class="IdeTweaksFactory">
                 <child internal-child="language_subpage">
diff --git a/src/libide/tweaks/tests/test2/expected.xml b/src/libide/tweaks/tests/test2/expected.xml
index 2fa220e37..e0877fdcc 100644
--- a/src/libide/tweaks/tests/test2/expected.xml
+++ b/src/libide/tweaks/tests/test2/expected.xml
@@ -1,7 +1,7 @@
 <IdeTweaks id="IdeTweaks" sort-key="">
   <IdeTweaksSection id="programming_section" sort-key="">
-    <IdeTweaksPage id="languages_page" icon-name="" sort-key="" title="">
-      <IdeTweaksFactory id="language_subpage_factory" item="" model="GListStore<GtkSourceLanguage>" 
sort-key="">
+    <IdeTweaksPage id="languages_page" icon-name="preferences-desktop-appearance-symbolic" sort-key="" 
title="Appearance">
+      <IdeTweaksFactory id="language_subpage_factory" model="GListStore<GtkSourceLanguage>" sort-key="">
         <IdeTweaksSubpage id="language_subpage" icon-name="" sort-key="" title="">
           <IdeTweaksGroup id="language_general_group" sort-key="test-key" title="General"/>
         </IdeTweaksSubpage>


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