diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bookmark.c | 46 | ||||
-rw-r--r-- | src/bookmark.h | 1 | ||||
-rw-r--r-- | src/completion.c | 2 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/main.h | 15 |
5 files changed, 59 insertions, 7 deletions
diff --git a/src/bookmark.c b/src/bookmark.c index 2fecaa7..3cbd281 100644 --- a/src/bookmark.c +++ b/src/bookmark.c @@ -149,6 +149,52 @@ gboolean bookmark_fill_completion(GtkListStore *store, const char *input) return found; } +gboolean bookmark_fill_tag_completion(GtkListStore *store, const char *input) +{ + gboolean found = false; + unsigned int len, i; + GtkTreeIter iter; + GList *src = NULL, *tags = NULL, *l; + Bookmark *bm; + + /* get all distinct tags from bookmark file */ + src = load(vb.files[FILES_BOOKMARK]); + for (GList *l = src; l; l = l->next) { + bm = (Bookmark*)l->data; + len = (bm->tags) ? g_strv_length(bm->tags) : 0; + for (i = 0; i < len; i++) { + char *tag = bm->tags[i]; + /* add tag only if it isn't already in the list */ + if (!g_list_find_custom(tags, tag, (GCompareFunc)strcmp)) { + tags = g_list_prepend(tags, tag); + } + } + } + + /* generate the completion with the found tags */ + if (!input || *input == '\0') { + 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; + } + } + } + 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 */ + g_list_free(tags); + + return found; +} + #ifdef FEATURE_QUEUE /** * Push a uri to the end of the queue. diff --git a/src/bookmark.h b/src/bookmark.h index a346905..d7a8e56 100644 --- a/src/bookmark.h +++ b/src/bookmark.h @@ -23,6 +23,7 @@ gboolean bookmark_add(const char *uri, const char *title, const char *tags); gboolean bookmark_remove(const char *uri); gboolean bookmark_fill_completion(GtkListStore *store, const char *input); +gboolean bookmark_fill_tag_completion(GtkListStore *store, const char *input); #ifdef FEATURE_QUEUE gboolean bookmark_queue_push(const char *uri); gboolean bookmark_queue_unshift(const char *uri); diff --git a/src/completion.c b/src/completion.c index 663fb07..1f8aa14 100644 --- a/src/completion.c +++ b/src/completion.c @@ -94,6 +94,8 @@ gboolean completion_complete(gboolean back) res = command_fill_completion(store, command); } else if (type == VB_INPUT_SEARCH_FORWARD || type == VB_INPUT_SEARCH_BACKWARD) { res = history_fill_completion(store, HISTORY_SEARCH, suffix); + } else if (type == VB_INPUT_BOOKMARK_ADD) { + res = bookmark_fill_tag_completion(store, suffix); } if (!res) { @@ -419,6 +419,8 @@ VbInputType vb_get_input_parts(const char* input, unsigned int use, {VB_INPUT_OPEN, ":open ", 6}, {VB_INPUT_TABOPEN, ":tabopen ", 9}, {VB_INPUT_SET, ":set ", 5}, + {VB_INPUT_BOOKMARK_ADD, ":bma ", 5}, + {VB_INPUT_BOOKMARK_ADD, ":bookmark-add ", 14}, {VB_INPUT_COMMAND, ":", 1}, {VB_INPUT_SEARCH_FORWARD, "/", 1}, {VB_INPUT_SEARCH_BACKWARD, "?", 1}, @@ -120,13 +120,14 @@ typedef enum _vb_mode { typedef enum { VB_INPUT_UNKNOWN, - VB_INPUT_SET = 1<<0, - VB_INPUT_OPEN = 1<<1, - VB_INPUT_TABOPEN = 1<<2, - VB_INPUT_COMMAND = 1<<3, - VB_INPUT_SEARCH_FORWARD = 1<<4, - VB_INPUT_SEARCH_BACKWARD = 1<<5, - VB_INPUT_ALL = VB_INPUT_OPEN | VB_INPUT_TABOPEN | VB_INPUT_SET | VB_INPUT_COMMAND | VB_INPUT_SEARCH_FORWARD | VB_INPUT_SEARCH_BACKWARD, + VB_INPUT_SET = 0x01, + VB_INPUT_OPEN = 0x02, + VB_INPUT_TABOPEN = 0x04, + VB_INPUT_COMMAND = 0x08, + VB_INPUT_SEARCH_FORWARD = 0x10, + VB_INPUT_SEARCH_BACKWARD = 0x20, + VB_INPUT_BOOKMARK_ADD = 0x40, + VB_INPUT_ALL = 0xff, /* map to match all input types */ } VbInputType; enum { |