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 :-(
This commit is contained in:
Matthias Clasen 2015-10-26 23:38:05 -04:00
parent b7d001e613
commit 6852a1eef9

View File

@ -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)
{