--- a/gplugin-gtk4/data/view.ui Mon Dec 06 22:37:08 2021 -0600
+++ b/gplugin-gtk4/data/view.ui Mon Dec 06 22:37:09 2021 -0600
@@ -4,11 +4,12 @@
<template class="GPluginGtkView" parent="GtkBox">
<property name="orientation">vertical</property>
- <object class="GtkSearchBar">
+ <object class="GtkSearchBar" id="search_bar"> <property name="key-capture-widget">list_box</property>
<property name="show-close-button">1</property>
<object class="GtkSearchEntry" id="search_entry">
+ <signal name="search-changed" handler="gplugin_gtk_view_search_changed"/> --- a/gplugin-gtk4/gplugin-gtk-plugin-row.c Mon Dec 06 22:37:08 2021 -0600
+++ b/gplugin-gtk4/gplugin-gtk-plugin-row.c Mon Dec 06 22:37:09 2021 -0600
@@ -473,3 +473,44 @@
return g_strdup(gtk_label_get_text(GTK_LABEL(row->title)));
+ * gplugin_gtk_plugin_row_matches_search: + * @row: The plugin row instance. + * @text: The text to search for. + * Matches this row instance against some text to be searched for. + * Returns: Whether the row matches the text or not. +gplugin_gtk_plugin_row_matches_search( + GPluginGtkPluginRow *row, + const gchar *value = NULL; + g_return_val_if_fail(GPLUGIN_GTK_IS_PLUGIN_ROW(row), FALSE); + value = gtk_label_get_text(GTK_LABEL(row->title)); + if(g_strstr_len(value, -1, text)) { + value = gtk_label_get_text(GTK_LABEL(row->summary)); + if(g_strstr_len(value, -1, text)) { + value = gtk_label_get_text(GTK_LABEL(row->description)); + if(g_strstr_len(value, -1, text)) { + value = gtk_label_get_text(GTK_LABEL(row->filename)); + if(g_strstr_len(value, -1, text)) { --- a/gplugin-gtk4/gplugin-gtk-plugin-row.h Mon Dec 06 22:37:08 2021 -0600
+++ b/gplugin-gtk4/gplugin-gtk-plugin-row.h Mon Dec 06 22:37:09 2021 -0600
@@ -47,6 +47,9 @@
GPluginPlugin *gplugin_gtk_plugin_row_get_plugin(GPluginGtkPluginRow *row);
gchar *gplugin_gtk_plugin_row_get_sort_key(GPluginGtkPluginRow *row);
+gboolean gplugin_gtk_plugin_row_matches_search( + GPluginGtkPluginRow *row, --- a/gplugin-gtk4/gplugin-gtk-view.c Mon Dec 06 22:37:08 2021 -0600
+++ b/gplugin-gtk4/gplugin-gtk-view.c Mon Dec 06 22:37:09 2021 -0600
@@ -34,6 +34,7 @@
@@ -79,15 +80,15 @@
G_GNUC_UNUSED gpointer data)
- GPluginGtkPluginRow *view1 = NULL, *view2 = NULL;
+ GPluginGtkPluginRow *plugin_row1 = NULL, *plugin_row2 = NULL; gchar *key1 = NULL, *key2 = NULL;
- view1 = GPLUGIN_GTK_PLUGIN_ROW(row1);
- key1 = gplugin_gtk_plugin_row_get_sort_key(view1);
+ plugin_row1 = GPLUGIN_GTK_PLUGIN_ROW(row1); + key1 = gplugin_gtk_plugin_row_get_sort_key(plugin_row1); - view2 = GPLUGIN_GTK_PLUGIN_ROW(row2);
- key2 = gplugin_gtk_plugin_row_get_sort_key(view2);
+ plugin_row2 = GPLUGIN_GTK_PLUGIN_ROW(row2); + key2 = gplugin_gtk_plugin_row_get_sort_key(plugin_row2); ret = g_strcmp0(key1, key2);
@@ -97,6 +98,34 @@
+gplugin_gtk_view_filter_func(GtkListBoxRow *row, gpointer data) + GPluginGtkView *view = GPLUGIN_GTK_VIEW(data); + gboolean visible = TRUE; + if(gtk_search_bar_get_search_mode(GTK_SEARCH_BAR(view->search_bar))) { + gtk_editable_get_text(GTK_EDITABLE(view->search_entry)); + if(text != NULL && text[0] != '\0') { + GPluginGtkPluginRow *plugin_row = GPLUGIN_GTK_PLUGIN_ROW(row); + visible = gplugin_gtk_plugin_row_matches_search(plugin_row, text); +gplugin_gtk_view_search_changed( + G_GNUC_UNUSED GtkSearchEntry *entry, + GPluginGtkView *view = GPLUGIN_GTK_VIEW(data); + gtk_list_box_invalidate_filter(GTK_LIST_BOX(view->list_box)); /******************************************************************************
*****************************************************************************/
@@ -181,8 +210,16 @@
gtk_widget_class_bind_template_child(
+ gtk_widget_class_bind_template_child( + gtk_widget_class_bind_template_callback( + gplugin_gtk_view_search_changed); @@ -217,6 +254,11 @@
gtk_widget_init_template(GTK_WIDGET(self));
+ gtk_list_box_set_filter_func( + GTK_LIST_BOX(self->list_box), + gplugin_gtk_view_filter_func, gtk_list_box_set_sort_func(
GTK_LIST_BOX(self->list_box),
gplugin_gtk_view_sort_func,