From c429297cedfe1a393ff122199b16bf761261f7b6 Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Mon, 26 May 2014 14:54:02 +0200 Subject: [PATCH] Added completion for :handler-remove command (#82). --- src/ex.c | 5 +++++ src/handlers.c | 28 ++++++++++++++++++++++++++++ src/handlers.h | 1 + 3 files changed, 34 insertions(+) diff --git a/src/ex.c b/src/ex.c index 24d3925..5450e8a 100644 --- a/src/ex.c +++ b/src/ex.c @@ -1024,6 +1024,11 @@ static gboolean complete(short direction) found = bookmark_fill_tag_completion(store, token); break; + case EX_HANDREM: + sort = true; + found = handler_fill_completion(store, token); + break; + default: break; } diff --git a/src/handlers.c b/src/handlers.c index 0ecd0b6..5b9c23e 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -19,6 +19,7 @@ #include "main.h" #include "handlers.h" +#include "completion.h" #include "util.h" extern VbCore vb; @@ -69,6 +70,33 @@ gboolean handle_uri(const char *uri) return true; } +gboolean handler_fill_completion(GtkListStore *store, const char *input) +{ + gboolean found = false; + GtkTreeIter iter; + GList *src = g_hash_table_get_keys(handlers); + + if (!input || !*input) { + for (GList *l = src; l; l = l->next) { + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, COMPLETION_STORE_FIRST, l->data, -1); + found = true; + } + } else { + for (GList *l = src; l; l = l->next) { + char *value = (char*)l->data; + if (g_str_has_prefix(value, input)) { + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, COMPLETION_STORE_FIRST, l->data, -1); + found = true; + } + } + } + g_list_free(src); + + return found; +} + static char *handler_lookup(const char *uri) { char *p, *handler = NULL; diff --git a/src/handlers.h b/src/handlers.h index df71b98..39b4c20 100644 --- a/src/handlers.h +++ b/src/handlers.h @@ -25,5 +25,6 @@ void handlers_cleanup(void); gboolean handler_add(const char *key, const char *uri); gboolean handler_remove(const char *key); gboolean handle_uri(const char *uri); +gboolean handler_fill_completion(GtkListStore *store, const char *input); #endif /* end of include guard: _HANDLERS_H */ -- 2.20.1