mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-28 06:21:14 +00:00
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.
This commit is contained in:
parent
032302c358
commit
b4096cee64
@ -966,21 +966,9 @@ selection_cb (GtkSingleSelection *sel,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
demo_filter_by_name (GtkTreeListRow *row,
|
filter_demo (GtkDemo *demo)
|
||||||
GtkFilterListModel *model)
|
|
||||||
{
|
{
|
||||||
GtkDemo *demo;
|
int i;
|
||||||
guint i;
|
|
||||||
|
|
||||||
/* Show all items if search is empty */
|
|
||||||
if (!search_needle || !search_needle[0] || !*search_needle[0])
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
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 */
|
/* Show only if the name maches every needle */
|
||||||
for (i = 0; search_needle[i]; i++)
|
for (i = 0; search_needle[i]; i++)
|
||||||
@ -997,6 +985,45 @@ demo_filter_by_name (GtkTreeListRow *row,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
demo_filter_by_name (GtkTreeListRow *row,
|
||||||
|
GtkFilterListModel *model)
|
||||||
|
{
|
||||||
|
GListModel *children;
|
||||||
|
GtkDemo *demo;
|
||||||
|
guint i, n;
|
||||||
|
|
||||||
|
/* Show all items if search is empty */
|
||||||
|
if (!search_needle || !search_needle[0] || !*search_needle[0])
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
g_assert (GTK_IS_TREE_LIST_ROW (row));
|
||||||
|
g_assert (GTK_IS_FILTER_LIST_MODEL (model));
|
||||||
|
|
||||||
|
children = gtk_tree_list_row_get_children (row);
|
||||||
|
if (children)
|
||||||
|
{
|
||||||
|
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));
|
||||||
|
|
||||||
|
if (filter_demo (demo))
|
||||||
|
{
|
||||||
|
g_object_unref (demo);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
g_object_unref (demo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
demo = gtk_tree_list_row_get_item (row);
|
||||||
|
g_assert (GTK_IS_DEMO (demo));
|
||||||
|
|
||||||
|
return filter_demo (demo);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
demo_search_changed_cb (GtkSearchEntry *entry,
|
demo_search_changed_cb (GtkSearchEntry *entry,
|
||||||
GtkFilter *filter)
|
GtkFilter *filter)
|
||||||
|
Loading…
Reference in New Issue
Block a user