diff options
author | Matthias Clasen <mclasen@redhat.com> | 2022-03-25 08:35:16 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2022-03-25 08:35:16 -0400 |
commit | 79f0f4ee8e6dd1dc95f14e6b191eea219f797279 (patch) | |
tree | ee79f56f49fbcaabe240a76cbf140c689fbf0ac7 | |
parent | 7106cf652492f250db6f02eb063ff337ab2c50b9 (diff) | |
download | gtk+-79f0f4ee8e6dd1dc95f14e6b191eea219f797279.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.c | 57 |
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; |