[gtk/matthiasc/for-master: 9/9] gtk-demo: Allow editing in the settings demo
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/for-master: 9/9] gtk-demo: Allow editing in the settings demo
- Date: Thu, 4 Jun 2020 12:46:44 +0000 (UTC)
commit 3f2d44d517dd9513fe4328a7d7436bd1ca14134d
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Jun 3 19:33:45 2020 -0400
gtk-demo: Allow editing in the settings demo
This gives us an example of a columnview with editable
content, which we didn't have so far.
demos/gtk-demo/listview_settings.c | 38 +++++++++++++++++++++++++++++++++++++
demos/gtk-demo/listview_settings.ui | 5 +++--
2 files changed, 41 insertions(+), 2 deletions(-)
---
diff --git a/demos/gtk-demo/listview_settings.c b/demos/gtk-demo/listview_settings.c
index 5fcd2d08fa..3e86e18346 100644
--- a/demos/gtk-demo/listview_settings.c
+++ b/demos/gtk-demo/listview_settings.c
@@ -140,6 +140,43 @@ settings_key_new (GSettings *settings,
return result;
}
+static void
+item_value_changed (GtkListItem *item,
+ GtkEntry *entry)
+{
+ SettingsKey *self;
+ const char *text;
+ const GVariantType *type;
+ GVariant *variant;
+ GError *error = NULL;
+ const char *name;
+
+ text = gtk_editable_get_text (GTK_EDITABLE (entry));
+
+ g_object_get (item, "item", &self, NULL);
+ g_object_unref (self);
+
+ type = g_settings_schema_key_get_value_type (self->key);
+ name = g_settings_schema_key_get_name (self->key);
+
+ variant = g_variant_parse (type, text, NULL, NULL, &error);
+ if (!variant)
+ {
+ g_warning ("%s", error->message);
+ g_clear_error (&error);
+ return;
+ }
+
+ if (!g_settings_schema_key_range_check (self->key, variant))
+ {
+ g_warning ("Not a valid value for %s", name);
+ return;
+ }
+
+ g_settings_set_value (self->settings, name, variant);
+ g_variant_unref (variant);
+}
+
static int
strvcmp (gconstpointer p1,
gconstpointer p2)
@@ -318,6 +355,7 @@ do_listview_settings (GtkWidget *do_widget)
gtk_builder_cscope_add_callback_symbol (GTK_BUILDER_CSCOPE (scope), "search_enabled",
(GCallback)search_enabled);
gtk_builder_cscope_add_callback_symbol (GTK_BUILDER_CSCOPE (scope), "search_changed",
(GCallback)search_changed);
gtk_builder_cscope_add_callback_symbol (GTK_BUILDER_CSCOPE (scope), "stop_search",
(GCallback)stop_search);
+ gtk_builder_cscope_add_callback_symbol (GTK_BUILDER_CSCOPE (scope), "item_value_changed",
(GCallback)item_value_changed);
builder = gtk_builder_new ();
gtk_builder_set_scope (builder, scope);
diff --git a/demos/gtk-demo/listview_settings.ui b/demos/gtk-demo/listview_settings.ui
index 0dd3daa793..82410e718a 100644
--- a/demos/gtk-demo/listview_settings.ui
+++ b/demos/gtk-demo/listview_settings.ui
@@ -113,9 +113,10 @@
<interface>
<template class="GtkListItem">
<property name="child">
- <object class="GtkLabel">
+ <object class="GtkEntry">
+ <signal name="activate" handler="item_value_changed" object="GtkListItem" swapped="yes"/>
<property name="xalign">0</property>
- <binding name="label">
+ <binding name="text">
<lookup name="value" type="SettingsKey">
<lookup name="item">GtkListItem</lookup>
</lookup>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]