[gtk/matthiasc/for-master: 2/2] gtk-demo: Work harder to filter the tree
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/for-master: 2/2] gtk-demo: Work harder to filter the tree
- Date: Sun, 12 Jul 2020 22:28:07 +0000 (UTC)
commit b4096cee640002e5a63a3d6bb26cb07b7dd7621d
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Jul 12 18:24:04 2020 -0400
gtk-demo: Work harder to filter the tree
Arrange for an item to be visible if it either
matches the filter or has children that do.
demos/gtk-demo/main.c | 53 ++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 40 insertions(+), 13 deletions(-)
---
diff --git a/demos/gtk-demo/main.c b/demos/gtk-demo/main.c
index 5bad5e80aa..880dcbaf1b 100644
--- a/demos/gtk-demo/main.c
+++ b/demos/gtk-demo/main.c
@@ -965,12 +965,33 @@ selection_cb (GtkSingleSelection *sel,
gtk_window_set_title (GTK_WINDOW (toplevel), demo->title);
}
+static gboolean
+filter_demo (GtkDemo *demo)
+{
+ int i;
+
+ /* Show only if the name maches every needle */
+ for (i = 0; search_needle[i]; i++)
+ {
+ if (!demo->title)
+ return FALSE;
+
+ if (g_str_match_string (search_needle[i], demo->title, TRUE))
+ continue;
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
static gboolean
demo_filter_by_name (GtkTreeListRow *row,
GtkFilterListModel *model)
{
+ GListModel *children;
GtkDemo *demo;
- guint i;
+ guint i, n;
/* Show all items if search is empty */
if (!search_needle || !search_needle[0] || !*search_needle[0])
@@ -979,22 +1000,28 @@ demo_filter_by_name (GtkTreeListRow *row,
g_assert (GTK_IS_TREE_LIST_ROW (row));
g_assert (GTK_IS_FILTER_LIST_MODEL (model));
- demo = gtk_tree_list_row_get_item (row);
- g_assert (GTK_IS_DEMO (demo));
-
- /* Show only if the name maches every needle */
- for (i = 0; search_needle[i]; i++)
+ children = gtk_tree_list_row_get_children (row);
+ if (children)
{
- if (!demo->title)
- return FALSE;
-
- if (g_str_match_string (search_needle[i], demo->title, TRUE))
- continue;
+ n = g_list_model_get_n_items (children);
+ for (i = 0; i < n; i++)
+ {
+ demo = g_list_model_get_item (children, i);
+ g_assert (GTK_IS_DEMO (demo));
- return FALSE;
+ if (filter_demo (demo))
+ {
+ g_object_unref (demo);
+ return TRUE;
+ }
+ g_object_unref (demo);
+ }
}
- return TRUE;
+ demo = gtk_tree_list_row_get_item (row);
+ g_assert (GTK_IS_DEMO (demo));
+
+ return filter_demo (demo);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]