diff options
bookmarks.c: Wildcard-based suggestion matching
1 files changed, 19 insertions, 0 deletions
| -rw-r--r-- | bookmarks.c | 19 |
diff --git a/bookmarks.c b/bookmarks.c index 23cb558..4bbfb8a 100644 --- 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 |