Merge branch 'inspector-attributes' into 'main'

inspector: Allow viewing PangoAttrList properties

See merge request GNOME/gtk!4596
This commit is contained in:
Matthias Clasen 2022-03-25 13:03:00 +00:00
commit a1ddd3fead

View File

@ -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;