commit: 3f164de8eb38f06138d908536b198dcd507a3a74
parent a7ba36264f3a62013d393075bd992ac252d3e51a
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sun, 3 Nov 2019 22:44:18 +0100
bookmarks.c: Wildcard-based suggestion matching
Diffstat:
1 file changed, 19 insertions(+), 0 deletions(-)
diff --git a/bookmarks.c b/bookmarks.c
@@ -6,11 +6,30 @@
#include <gtk/gtk.h>
#include <libxml/xpath.h>
+gboolean
+location_completion_matches(GtkEntryCompletion *completion, const gchar *key, GtkTreeIter *iter, gpointer user_data)
+{
+ (void)user_data;
+ gchar *buffer;
+ gchar *pattern;
+ gboolean result;
+
+ pattern = g_strdup_printf("*%s*", key);
+
+ gtk_tree_model_get(gtk_entry_completion_get_model(completion), iter, 0, &buffer, -1);
+ result = g_pattern_match_simple(pattern, buffer);
+
+ g_free(buffer);
+ g_free(pattern);
+ return result;
+}
+
void
location_completion_setup(GtkListStore *list_store)
{
gtk_entry_completion_set_model(location_completion, GTK_TREE_MODEL(list_store));
gtk_entry_completion_set_text_column(location_completion, 0);
+ gtk_entry_completion_set_match_func(location_completion, location_completion_matches, NULL, NULL);
}
void