Added completion for :handler-remove command (#82).
authorDaniel Carl <danielcarl@gmx.de>
Mon, 26 May 2014 12:54:02 +0000 (14:54 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Mon, 26 May 2014 12:54:02 +0000 (14:54 +0200)
src/ex.c
src/handlers.c
src/handlers.h

index 24d3925..5450e8a 100644 (file)
--- 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;
             }
index 0ecd0b6..5b9c23e 100644 (file)
@@ -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;
index df71b98..39b4c20 100644 (file)
@@ -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 */