summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2022-03-25 08:35:16 -0400
committerMatthias Clasen <mclasen@redhat.com>2022-04-21 19:15:20 -0400
commit29d4821e3d9cdb36551e92e8aff6650f24a1530b (patch)
tree7c42401ffc8f485da30f442a3609ddc335e10cb2
parentcbd03cda5625ba4a0acfc37395ece2eef1335092 (diff)
downloadgtk+-29d4821e3d9cdb36551e92e8aff6650f24a1530b.tar.gz
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.
-rw-r--r--gtk/inspector/prop-editor.c57
1 files changed, 57 insertions, 0 deletions
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
@@ -360,6 +360,22 @@ intern_string_modified (GtkEntry *entry, ObjectProperty *p)
}
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)
{
GtkEntry *entry = GTK_ENTRY (data);
@@ -385,6 +401,35 @@ string_changed (GObject *object, GParamSpec *pspec, gpointer data)
}
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)
{
GValue val = G_VALUE_INIT;
@@ -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;