[gtk/wip/otte/whatever: 2/3] gtk-demo: Add incremental filtering to words demo
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/whatever: 2/3] gtk-demo: Add incremental filtering to words demo
- Date: Tue, 30 Jun 2020 11:28:54 +0000 (UTC)
commit 3d010e81e8865d79c311c2f27b699d1d2e3a9f3b
Author: Benjamin Otte <otte redhat com>
Date: Tue Jun 30 04:03:07 2020 +0200
gtk-demo: Add incremental filtering to words demo
demos/gtk-demo/listview_words.c | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
---
diff --git a/demos/gtk-demo/listview_words.c b/demos/gtk-demo/listview_words.c
index 7966d0ceb64..c8aab2360d9 100644
--- a/demos/gtk-demo/listview_words.c
+++ b/demos/gtk-demo/listview_words.c
@@ -27,16 +27,21 @@ const char *factory_text =
"</interface>\n";
static void
-update_title_cb (GListModel *model,
- guint position,
- guint removed,
- guint added,
- GtkWindow *win)
+update_title_cb (GtkFilterListModel *model)
{
char *title;
+ guint pending;
- title = g_strdup_printf ("%u Words\n", g_list_model_get_n_items (model));
- gtk_window_set_title (win, title);
+ pending = gtk_filter_list_model_get_pending (model);
+ if (pending)
+ {
+ guint total = g_list_model_get_n_items (gtk_filter_list_model_get_model (model));
+ title = g_strdup_printf ("%u Words (%u%% done)", g_list_model_get_n_items (G_LIST_MODEL (model)),
+ (total - pending) * 100 / total);
+ }
+ else
+ title = g_strdup_printf ("%u Words\n", g_list_model_get_n_items (G_LIST_MODEL (model)));
+ gtk_window_set_title (GTK_WINDOW (window), title);
g_free (title);
}
@@ -70,6 +75,7 @@ do_listview_words (GtkWidget *do_widget)
gtk_string_filter_set_expression (GTK_STRING_FILTER (filter), expression);
gtk_expression_unref (expression);
filter_model = gtk_filter_list_model_new (G_LIST_MODEL (stringlist), filter);
+ gtk_filter_list_model_set_incremental (filter_model, TRUE);
window = gtk_window_new ();
gtk_window_set_title (GTK_WINDOW (window), "Words");
@@ -97,8 +103,9 @@ do_listview_words (GtkWidget *do_widget)
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listview);
gtk_list_view_set_model (GTK_LIST_VIEW (listview), G_LIST_MODEL (filter_model));
- g_signal_connect (filter_model, "items-changed", G_CALLBACK (update_title_cb), window);
- update_title_cb (G_LIST_MODEL (filter_model), 0, 0, 0, GTK_WINDOW (window));
+ g_signal_connect (filter_model, "items-changed", G_CALLBACK (update_title_cb), NULL);
+ g_signal_connect (filter_model, "notify::pending", G_CALLBACK (update_title_cb), NULL);
+ update_title_cb (filter_model);
g_object_unref (filter_model);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]