From: Daniel Carl Date: Mon, 26 May 2014 13:13:44 +0000 (+0200) Subject: Added completion for :shortcut-remove. X-Git-Url: https://git.owens.tech/dummy.html/dummy.html/git?a=commitdiff_plain;h=ed93b58e30d924352a054bdf69b73bc9397305d8;p=vimb.git Added completion for :shortcut-remove. Simplified some of the completions to avoid duplicate code. --- diff --git a/src/bookmark.c b/src/bookmark.c index c5028cc..69151ae 100644 --- a/src/bookmark.c +++ b/src/bookmark.c @@ -151,10 +151,9 @@ gboolean bookmark_fill_completion(GtkListStore *store, const char *input) gboolean bookmark_fill_tag_completion(GtkListStore *store, const char *input) { - gboolean found = false; + gboolean found; unsigned int len, i; - GtkTreeIter iter; - GList *src = NULL, *tags = NULL, *l; + GList *src = NULL, *tags = NULL; Bookmark *bm; /* get all distinct tags from bookmark file */ @@ -172,21 +171,7 @@ gboolean bookmark_fill_tag_completion(GtkListStore *store, const char *input) } /* generate the completion with the found tags */ - if (!input || !*input) { - for (l = tags; 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 (l = tags; l; l = l->next) { - if (g_str_has_prefix(l->data, input)) { - gtk_list_store_append(store, &iter); - gtk_list_store_set(store, &iter, COMPLETION_STORE_FIRST, l->data, -1); - found = true; - } - } - } + found = util_fill_completion(store, input, tags); g_list_free_full(src, (GDestroyNotify)free_bookmark); /* we don't need to free the values, because they where already removed by * freeing the src list - we never allocated new momory for them */ diff --git a/src/ex.c b/src/ex.c index 5450e8a..121bc3d 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_SCR: + sort = true; + found = shortcut_fill_completion(store, token); + break; + case EX_HANDREM: sort = true; found = handler_fill_completion(store, token); diff --git a/src/handlers.c b/src/handlers.c index 5b9c23e..2aed472 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -19,7 +19,6 @@ #include "main.h" #include "handlers.h" -#include "completion.h" #include "util.h" extern VbCore vb; @@ -72,26 +71,8 @@ gboolean handle_uri(const char *uri) 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; - } - } - } + gboolean found = util_fill_completion(store, input, src); g_list_free(src); return found; diff --git a/src/setting.c b/src/setting.c index 75b8fff..deb281e 100644 --- a/src/setting.c +++ b/src/setting.c @@ -241,26 +241,8 @@ gboolean setting_run(char *name, const char *param) gboolean setting_fill_completion(GtkListStore *store, const char *input) { - gboolean found = false; - GtkTreeIter iter; GList *src = g_hash_table_get_keys(settings); - - 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; - } - } - } + gboolean found = util_fill_completion(store, input, src); g_list_free(src); return found; diff --git a/src/shortcut.c b/src/shortcut.c index 1d746e9..0ba1f8c 100644 --- a/src/shortcut.c +++ b/src/shortcut.c @@ -104,6 +104,15 @@ char *shortcut_get_uri(const char *string) return uri; } +gboolean shortcut_fill_completion(GtkListStore *store, const char *input) +{ + GList *src = g_hash_table_get_keys(shortcuts); + gboolean found = util_fill_completion(store, input, src); + g_list_free(src); + + return found; +} + /** * Retrieves th highest placesholder number used in given string. * If no placeholder is found -1 is returned. diff --git a/src/shortcut.h b/src/shortcut.h index 672365e..466f08f 100644 --- a/src/shortcut.h +++ b/src/shortcut.h @@ -26,5 +26,6 @@ gboolean shortcut_add(const char *key, const char *uri); gboolean shortcut_remove(const char *key); gboolean shortcut_set_default(const char *key); char *shortcut_get_uri(const char *key); +gboolean shortcut_fill_completion(GtkListStore *store, const char *input); #endif /* end of include guard: _SHORTCUT_H */ diff --git a/src/util.c b/src/util.c index f4ecfe3..64b2fd2 100644 --- a/src/util.c +++ b/src/util.c @@ -24,6 +24,7 @@ #include "main.h" #include "util.h" #include "ascii.h" +#include "completion.h" char *util_get_config_dir(void) { @@ -415,3 +416,31 @@ char *util_expand(const char *src) return result; } + +/** + * Fills the given list store by matching data of also given src list. + */ +gboolean util_fill_completion(GtkListStore *store, const char *input, GList *src) +{ + gboolean found = false; + GtkTreeIter iter; + + 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; + } + } + } + + return found; +} diff --git a/src/util.h b/src/util.h index a4b51fb..ba74fb2 100644 --- a/src/util.h +++ b/src/util.h @@ -41,5 +41,6 @@ char *util_str_replace(const char* search, const char* replace, const char* stri gboolean util_create_tmp_file(const char *content, char **file); char *util_build_path(const char *path, const char *dir); char *util_expand(const char *src); +gboolean util_fill_completion(GtkListStore *store, const char *input, GList *src); #endif /* end of include guard: _UTIL_H */