From 6852a1eef97867a1cd9be285f8fed18eecc9a3aa Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 26 Oct 2015 23:38:05 -0400 Subject: [PATCH] inspector: Support editing interned string properties Sadly, interned string properties cannot be handled generically at all - GObject insists on inserting a strcpy in any attempt to set a string property with generic api, destroying the internedness of the string. Therefore, we have to special-case GtkCssNode in the property editor code :-( --- gtk/inspector/prop-editor.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/gtk/inspector/prop-editor.c b/gtk/inspector/prop-editor.c index c6a70a988c..b014dba5ca 100644 --- a/gtk/inspector/prop-editor.c +++ b/gtk/inspector/prop-editor.c @@ -42,6 +42,7 @@ #include "gtksettingsprivate.h" #include "gtktogglebutton.h" #include "gtkwidgetprivate.h" +#include "gtkcssnodeprivate.h" struct _GtkInspectorPropEditorPrivate { @@ -393,6 +394,18 @@ string_modified (GtkEntry *entry, ObjectProperty *p) g_value_unset (&val); } +static void +intern_string_modified (GtkEntry *entry, ObjectProperty *p) +{ + const gchar *s; + + s = g_intern_string (gtk_entry_get_text (entry)); + if (g_str_equal (p->spec->name, "id")) + gtk_css_node_set_id (GTK_CSS_NODE (p->obj), s); + else if (g_str_equal (p->spec->name, "name")) + gtk_css_node_set_name (GTK_CSS_NODE (p->obj), s); +} + static void string_changed (GObject *object, GParamSpec *pspec, gpointer data) { @@ -922,8 +935,12 @@ property_editor (GObject *object, G_CALLBACK (string_changed), prop_edit, G_OBJECT (prop_edit)); - connect_controller (G_OBJECT (prop_edit), "changed", - object, spec, G_CALLBACK (string_modified)); + if (GTK_IS_CSS_NODE (object)) + connect_controller (G_OBJECT (prop_edit), "changed", + object, spec, G_CALLBACK (intern_string_modified)); + else + connect_controller (G_OBJECT (prop_edit), "changed", + object, spec, G_CALLBACK (string_modified)); } else if (type == G_TYPE_PARAM_BOOLEAN) {