[gtk/inspector-attributes] inspector: Allow viewing PangoAttrList properties




commit 79f0f4ee8e6dd1dc95f14e6b191eea219f797279
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Mar 25 08:35:16 2022 -0400

    inspector: Allow viewing PangoAttrList properties
    
    We have pango_attr_list_to/from_string, so this is
    easy. The editing UI isn't ideal, but it solves my
    immediate need to see attributes.

 gtk/inspector/prop-editor.c | 57 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
---
diff --git a/gtk/inspector/prop-editor.c b/gtk/inspector/prop-editor.c
index 822e0ef722..db3d6f2c1b 100644
--- a/gtk/inspector/prop-editor.c
+++ b/gtk/inspector/prop-editor.c
@@ -359,6 +359,22 @@ intern_string_modified (GtkEntry *entry, ObjectProperty *p)
     gtk_css_node_set_name (GTK_CSS_NODE (p->obj), g_quark_from_string (s));
 }
 
+static void
+attr_list_modified (GtkEntry *entry, ObjectProperty *p)
+{
+  GValue val = G_VALUE_INIT;
+  PangoAttrList *attrs;
+
+  attrs = pango_attr_list_from_string (gtk_editable_get_text (GTK_EDITABLE (entry)));
+  if (!attrs)
+    return;
+
+  g_value_init (&val, PANGO_TYPE_ATTR_LIST);
+  g_value_take_boxed (&val, attrs);
+  set_property_value (p->obj, p->spec, &val);
+  g_value_unset (&val);
+}
+
 static void
 string_changed (GObject *object, GParamSpec *pspec, gpointer data)
 {
@@ -384,6 +400,35 @@ string_changed (GObject *object, GParamSpec *pspec, gpointer data)
   g_value_unset (&val);
 }
 
+static void
+attr_list_changed (GObject *object, GParamSpec *pspec, gpointer data)
+{
+  GtkEntry *entry = GTK_ENTRY (data);
+  GValue val = G_VALUE_INIT;
+  char *str;
+  const char *text;
+  PangoAttrList *attrs;
+
+  g_value_init (&val, PANGO_TYPE_ATTR_LIST);
+  get_property_value (object, pspec, &val);
+
+  attrs = g_value_get_boxed (&val);
+  str = pango_attr_list_to_string (attrs);
+  if (str == NULL)
+    str = g_strdup ("");
+  text = gtk_editable_get_text (GTK_EDITABLE (entry));
+  if (g_strcmp0 (str, text) != 0)
+    {
+      block_controller (G_OBJECT (entry));
+      gtk_editable_set_text (GTK_EDITABLE (entry), str);
+      unblock_controller (G_OBJECT (entry));
+    }
+
+  g_free (str);
+
+  g_value_unset (&val);
+}
+
 static void
 strv_modified (GtkInspectorStrvEditor *self, ObjectProperty *p)
 {
@@ -1168,6 +1213,18 @@ property_editor (GObject                *object,
       gtk_widget_set_halign (prop_edit, GTK_ALIGN_START);
       gtk_widget_set_valign (prop_edit, GTK_ALIGN_CENTER);
     }
+  else if (type == G_TYPE_PARAM_BOXED &&
+           G_PARAM_SPEC_VALUE_TYPE (spec) == PANGO_TYPE_ATTR_LIST)
+    {
+      prop_edit = gtk_entry_new ();
+
+      g_object_connect_property (object, spec,
+                                 G_CALLBACK (attr_list_changed),
+                                 prop_edit, G_OBJECT (prop_edit));
+
+      connect_controller (G_OBJECT (prop_edit), "changed",
+                          object, spec, G_CALLBACK (attr_list_modified));
+    }
   else if (type == GTK_TYPE_PARAM_SPEC_EXPRESSION)
     {
       GtkExpression *expression;


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