[gnome-builder] libide/tweaks: make printf helper a bit smarter



commit e8f5c64c5bab7200d76b458e607322aff892ec34
Author: Christian Hergert <chergert redhat com>
Date:   Tue Aug 2 20:22:48 2022 -0700

    libide/tweaks: make printf helper a bit smarter
    
    It's nice to know what the object reference is, so print that when possible
    witha # prefix, otherwise more of the item type.

 src/libide/tweaks/ide-tweaks-item.c        | 18 +++++++++++-------
 src/libide/tweaks/tests/test1/expected.xml |  6 +++---
 src/libide/tweaks/tests/test2/expected.xml |  2 +-
 3 files changed, 15 insertions(+), 11 deletions(-)
---
diff --git a/src/libide/tweaks/ide-tweaks-item.c b/src/libide/tweaks/ide-tweaks-item.c
index aee7b7c26..0e4e340b8 100644
--- a/src/libide/tweaks/ide-tweaks-item.c
+++ b/src/libide/tweaks/ide-tweaks-item.c
@@ -566,21 +566,25 @@ _ide_tweaks_item_printf (IdeTweaksItem *self,
           else if (g_type_is_a (pspec->value_type, G_TYPE_OBJECT))
             {
               g_auto(GValue) value = G_VALUE_INIT;
-              g_autofree char *generic = NULL;
-              const char *type_name = "";
+              g_autofree char *name = NULL;
               GObject *obj;
 
               g_value_init (&value, G_TYPE_OBJECT);
               g_object_get_property (G_OBJECT (self), pspec->name, &value);
 
-              if (!(obj = g_value_get_object (&value)) || !G_IS_LIST_MODEL (obj))
+              if (!(obj = g_value_get_object (&value)))
                 continue;
 
-              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))));
+              if (GTK_IS_BUILDABLE (obj))
+                name = g_strdup_printf ("#%s", gtk_buildable_get_buildable_id (GTK_BUILDABLE (obj)));
+              else if (G_IS_LIST_MODEL (obj))
+                name = g_strdup_printf ("%s<%s>",
+                                        G_OBJECT_TYPE_NAME (obj),
+                                        g_type_name (g_list_model_get_item_type (G_LIST_MODEL (obj))));
+              else
+                name = g_strdup (G_OBJECT_TYPE_NAME (obj));
 
-              g_string_append_printf (string, " %s=\"%s\"", pspec->name, type_name);
+              g_string_append_printf (string, " %s=\"%s\"", pspec->name, name);
             }
         }
     }
diff --git a/src/libide/tweaks/tests/test1/expected.xml b/src/libide/tweaks/tests/test1/expected.xml
index 5edac498a..e3bf935c0 100644
--- a/src/libide/tweaks/tests/test1/expected.xml
+++ b/src/libide/tweaks/tests/test1/expected.xml
@@ -1,11 +1,11 @@
 <IdeTweaks id="IdeTweaks" sort-key="">
   <IdeTweaksSection id="visual_section" sort-key="">
-    <IdeTweaksPage id="appearance_page" icon-name="" sort-key="" title="Appearance">
+    <IdeTweaksPage id="appearance_page" icon-name="" section="#visual_section" sort-key="" 
title="Appearance">
       <IdeTweaksGroup id="appearance_group" sort-key="" title="Appearance"/>
     </IdeTweaksPage>
   </IdeTweaksSection>
   <IdeTweaksSection id="foundry_section" sort-key="">
-    <IdeTweaksPage id="build_page" icon-name="" sort-key="" title="Build"/>
-    <IdeTweaksPage id="debugger_page" icon-name="builder-debugger-symbolic" sort-key="" title="Debugger"/>
+    <IdeTweaksPage id="build_page" icon-name="" section="#foundry_section" sort-key="" title="Build"/>
+    <IdeTweaksPage id="debugger_page" icon-name="builder-debugger-symbolic" section="#foundry_section" 
sort-key="" title="Debugger"/>
   </IdeTweaksSection>
 </IdeTweaks>
diff --git a/src/libide/tweaks/tests/test2/expected.xml b/src/libide/tweaks/tests/test2/expected.xml
index e0877fdcc..d80d71363 100644
--- a/src/libide/tweaks/tests/test2/expected.xml
+++ b/src/libide/tweaks/tests/test2/expected.xml
@@ -1,6 +1,6 @@
 <IdeTweaks id="IdeTweaks" sort-key="">
   <IdeTweaksSection id="programming_section" sort-key="">
-    <IdeTweaksPage id="languages_page" icon-name="preferences-desktop-appearance-symbolic" sort-key="" 
title="Appearance">
+    <IdeTweaksPage id="languages_page" icon-name="preferences-desktop-appearance-symbolic" 
section="#programming_section" 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"/>


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