summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Carl <danielcarl@gmx.de>2013-09-06 22:41:52 +0200
committerDaniel Carl <danielcarl@gmx.de>2013-09-06 22:41:52 +0200
commit6ae1f47d8eab6229c96f4ff0ec2a51b83aa1ab75 (patch)
tree54f2d0ba9a201cd281db5ec517ca5c1024614ef8 /src
parent6ab7ecfc5c8c5aa238d45421382aeab5018604a5 (diff)
Added completion for bookmark tags.
This allows to get already used bookmark tags for new bookmarks ':bma <tab>' or ':bookmark-add <tab>'.
Diffstat (limited to 'src')
-rw-r--r--src/bookmark.c46
-rw-r--r--src/bookmark.h1
-rw-r--r--src/completion.c2
-rw-r--r--src/main.c2
-rw-r--r--src/main.h15
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) {
diff --git a/src/main.c b/src/main.c
index 1d98781..24d1863 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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},
diff --git a/src/main.h b/src/main.h
index f856909..3cbdce8 100644
--- a/src/main.h
+++ b/src/main.h
@@ -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 {