[gtk/prop-list: 48/57] gtk-demo: Add filtering to the settings demo
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/prop-list: 48/57] gtk-demo: Add filtering to the settings demo
- Date: Sat, 21 Dec 2019 00:05:00 +0000 (UTC)
commit ccd5aaad28dcd30742580ac06d45132d257a704e
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Dec 15 23:48:34 2019 -0500
gtk-demo: Add filtering to the settings demo
A demo of filtering with lists was missing so far.
demos/gtk-demo/listview_settings.c | 54 ++++++++++++++++++++++++++++++--
demos/gtk-demo/listview_settings.ui | 62 +++++++++++++++++++++++++++----------
2 files changed, 97 insertions(+), 19 deletions(-)
---
diff --git a/demos/gtk-demo/listview_settings.c b/demos/gtk-demo/listview_settings.c
index 6480d8afbc..6a868b1a5b 100644
--- a/demos/gtk-demo/listview_settings.c
+++ b/demos/gtk-demo/listview_settings.c
@@ -117,6 +117,8 @@ strvcmp (gconstpointer p1,
return strcmp (*s1, *s2);
}
+static GtkFilter *current_filter;
+
static gboolean
transform_settings_to_keys (GBinding *binding,
const GValue *from_value,
@@ -128,6 +130,9 @@ transform_settings_to_keys (GBinding *binding,
GSettingsSchema *schema;
GListStore *store;
GtkSortListModel *sort_model;
+ GtkFilterListModel *filter_model;
+ GtkFilter *filter;
+ GtkExpression *expression;
char **keys;
guint i;
@@ -156,8 +161,18 @@ transform_settings_to_keys (GBinding *binding,
sort_model = gtk_sort_list_model_new (G_LIST_MODEL (store),
gtk_column_view_get_sorter (GTK_COLUMN_VIEW (data)));
+ expression = gtk_property_expression_new (SETTINGS_TYPE_KEY, NULL, "name");
+ filter = gtk_string_filter_new ();
+ gtk_string_filter_set_expression (GTK_STRING_FILTER (filter), expression);
+ filter_model = gtk_filter_list_model_new (G_LIST_MODEL (sort_model), filter);
+ gtk_expression_unref (expression);
+ g_object_unref (sort_model);
+
+ g_set_object (¤t_filter, filter);
+
+ g_object_unref (filter);
- g_value_take_object (to_value, sort_model);
+ g_value_take_object (to_value, filter_model);
return TRUE;
}
@@ -208,6 +223,32 @@ create_settings_model (gpointer item,
return G_LIST_MODEL (result);
}
+static void
+search_enabled (GtkSearchEntry *entry)
+{
+ gtk_editable_set_text (GTK_EDITABLE (entry), "");
+}
+
+static void
+search_changed (GtkSearchEntry *entry,
+ gpointer data)
+{
+ const char *text = gtk_editable_get_text (GTK_EDITABLE (entry));
+
+ if (current_filter)
+ gtk_string_filter_set_search (GTK_STRING_FILTER (current_filter), text);
+}
+
+static void
+stop_search (GtkSearchEntry *entry,
+ gpointer data)
+{
+ gtk_editable_set_text (GTK_EDITABLE (entry), "");
+
+ if (current_filter)
+ gtk_string_filter_set_search (GTK_STRING_FILTER (current_filter), "");
+}
+
static GtkWidget *window = NULL;
GtkWidget *
@@ -219,13 +260,22 @@ do_listview_settings (GtkWidget *do_widget)
GListModel *model;
GtkTreeListModel *treemodel;
GtkSingleSelection *selection;
+ GtkBuilderScope *scope;
GtkBuilder *builder;
GtkColumnViewColumn *name_column;
GtkSorter *sorter;
g_type_ensure (SETTINGS_TYPE_KEY);
- builder = gtk_builder_new_from_resource ("/listview_settings/listview_settings.ui");
+ scope = gtk_builder_cscope_new ();
+ 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);
+
+ builder = gtk_builder_new ();
+ gtk_builder_set_scope (builder, scope);
+ gtk_builder_add_from_resource (builder, "/listview_settings/listview_settings.ui", NULL);
+
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
diff --git a/demos/gtk-demo/listview_settings.ui b/demos/gtk-demo/listview_settings.ui
index 2bc197f68f..8088ca9102 100644
--- a/demos/gtk-demo/listview_settings.ui
+++ b/demos/gtk-demo/listview_settings.ui
@@ -4,6 +4,16 @@
<property name="title" translatable="yes">Settings</property>
<property name="default-width">640</property>
<property name="default-height">480</property>
+ <child type="titlebar">
+ <object class="GtkHeaderBar">
+ <property name="show-title-buttons">1</property>
+ <child type="end">
+ <object class="GtkToggleButton" id="search_button">
+ <property name="icon-name">system-search-symbolic</property>
+ </object>
+ </child>
+ </object>
+ </child>
<child>
<object class="GtkPaned">
<property name="position">300</property>
@@ -44,15 +54,31 @@
</object>
</child>
<child>
- <object class="GtkScrolledWindow">
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkSearchBar">
+ <property name="search-mode-enabled" bind-source="search_button" bind-property="active"
bind-flags="bidirectional"/>
+ <signal name="notify::search-mode-enabled" handler="search_enabled" object="entry"/>
+ <child>
+ <object class="GtkSearchEntry" id="entry">
+ <signal name="search-changed" handler="search_changed"/>
+ <signal name="stop-search" handler="stop_search"/>
+ </object>
+ </child>
+ </object>
+ </child>
<child>
- <object class="GtkColumnView" id="columnview">
+ <object class="GtkScrolledWindow">
+ <property name="expand">1</property>
<child>
- <object class="GtkColumnViewColumn" id="name_column">
- <property name="title">Name</property>
- <property name="factory">
- <object class="GtkBuilderListItemFactory">
- <property name="bytes"><![CDATA[
+ <object class="GtkColumnView" id="columnview">
+ <child>
+ <object class="GtkColumnViewColumn" id="name_column">
+ <property name="title">Name</property>
+ <property name="factory">
+ <object class="GtkBuilderListItemFactory">
+ <property name="bytes"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
@@ -69,16 +95,16 @@
</template>
</interface>
]]></property>
+ </object>
+ </property>
</object>
- </property>
- </object>
- </child>
- <child>
- <object class="GtkColumnViewColumn">
- <property name="title">Value</property>
- <property name="factory">
- <object class="GtkBuilderListItemFactory">
- <property name="bytes"><![CDATA[
+ </child>
+ <child>
+ <object class="GtkColumnViewColumn">
+ <property name="title">Value</property>
+ <property name="factory">
+ <object class="GtkBuilderListItemFactory">
+ <property name="bytes"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
@@ -95,8 +121,10 @@
</template>
</interface>
]]></property>
+ </object>
+ </property>
</object>
- </property>
+ </child>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]