gtk-demo: Use editable labels in the settings demo

This is more in line with the expected behavior for
editable lists.
This commit is contained in:
Matthias Clasen 2020-06-12 11:07:37 -04:00
parent b0d2ae612f
commit 02ce417279
2 changed files with 18 additions and 9 deletions

View File

@ -143,8 +143,9 @@ settings_key_new (GSettings *settings,
}
static void
item_value_changed (GtkListItem *item,
GtkEntry *entry)
item_value_changed (GtkEditableLabel *label,
GParamSpec *pspec,
GtkListItem *item)
{
SettingsKey *self;
const char *text;
@ -152,8 +153,9 @@ item_value_changed (GtkListItem *item,
GVariant *variant;
GError *error = NULL;
const char *name;
char *value;
text = gtk_editable_get_text (GTK_EDITABLE (entry));
text = gtk_editable_get_text (GTK_EDITABLE (label));
g_object_get (item, "item", &self, NULL);
g_object_unref (self);
@ -166,17 +168,25 @@ item_value_changed (GtkListItem *item,
{
g_warning ("%s", error->message);
g_clear_error (&error);
return;
goto revert;
}
if (!g_settings_schema_key_range_check (self->key, variant))
{
g_warning ("Not a valid value for %s", name);
return;
goto revert;
}
g_settings_set_value (self->settings, name, variant);
g_variant_unref (variant);
return;
revert:
gtk_widget_error_bell (GTK_WIDGET (label));
g_object_get (self, "value", &value, NULL);
gtk_editable_set_text (GTK_EDITABLE (label), value);
g_free (value);
}
static int

View File

@ -113,14 +113,13 @@
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkEntry">
<signal name="activate" handler="item_value_changed" object="GtkListItem" swapped="yes"/>
<property name="xalign">0</property>
<binding name="text">
<object class="GtkEditableLabel">
<binding name="label">
<lookup name="value" type="SettingsKey">
<lookup name="item">GtkListItem</lookup>
</lookup>
</binding>
<signal name="notify::label" handler="item_value_changed"/>
</object>
</property>
</template>