diff options
author | Daniel Carl <danielcarl@gmx.de> | 2012-12-24 03:29:23 +0100 |
---|---|---|
committer | Daniel Carl <danielcarl@gmx.de> | 2012-12-24 03:46:29 +0100 |
commit | 0ce4ec6550966a0a3037f5534342a2acf0f408fb (patch) | |
tree | c775b8b23b8b306ef754ef93bb7d002471cb3382 | |
parent | 3e8abe7ee081dcb9e06bf0eb3ab2526b6a70621c (diff) |
Allow to yank hinted link url.
-rw-r--r-- | doc/config | 1 | ||||
-rw-r--r-- | src/command.c | 31 | ||||
-rw-r--r-- | src/hints.c | 6 | ||||
-rw-r--r-- | src/hints.h | 2 |
4 files changed, 29 insertions, 11 deletions
@@ -27,6 +27,7 @@ nmap f hint-link nmap F hint-link-new nmap ;o hint-input-open nmap ;t hint-input-tabopen +nmap ;y hint-yank nmap y yank-uri nmap Y yank-selection cmap <tab> complete diff --git a/src/command.c b/src/command.c index 247bb80..d94a14b 100644 --- a/src/command.c +++ b/src/command.c @@ -68,6 +68,7 @@ static CommandInfo cmd_list[] = { {"hint-link-new", command_hints, {HINTS_TYPE_LINK | HINTS_TARGET_BLANK, ","}, VP_MODE_HINTING}, {"hint-input-open", command_hints, {HINTS_TYPE_LINK | HINTS_PROCESS | HINTS_PROCESS_INPUT, ";o"}, VP_MODE_HINTING}, {"hint-input-tabopen", command_hints, {HINTS_TYPE_LINK | HINTS_TARGET_BLANK | HINTS_PROCESS | HINTS_PROCESS_INPUT, ";t"}, VP_MODE_HINTING}, + {"hint-yank", command_hints, {HINTS_TYPE_LINK | HINTS_PROCESS | HINTS_PROCESS_YANK, ";y"}, VP_MODE_HINTING}, {"hint-focus-next", command_hints_focus, {0}, VP_MODE_HINTING}, {"hint-focus-prev", command_hints_focus, {1}, VP_MODE_HINTING}, {"yank-uri", command_yank, {COMMAND_YANK_PRIMARY | COMMAND_YANK_SECONDARY | COMMAND_YANK_URI}, VP_MODE_NORMAL}, @@ -300,24 +301,34 @@ gboolean command_yank(const Arg* arg) text = gtk_clipboard_wait_for_text(SECONDARY_CLIPBOARD()); } if (text) { + /* TODO is this the rigth place to switch the focus */ + gtk_widget_grab_focus(GTK_WIDGET(vp.gui.webview)); vp_echo(VP_MSG_NORMAL, FALSE, "Yanked: %s", text); g_free(text); return TRUE; } + + return FALSE; + } + /* use current arg.s a new clipboard content */ + Arg a = {arg->i}; + if (arg->i & COMMAND_YANK_URI) { + /* yank current url */ + a.s = g_strdup(CURRENT_URL()); } else { - /* use current arg.s a new clipboard content */ - Arg a = {arg->i, arg->s}; - if (arg->i & COMMAND_YANK_URI) { - /* yank current url */ - a.s = (gchar*)CURRENT_URL(); - } - if (vp_set_clipboard(&a)) { - vp_echo(VP_MSG_NORMAL, FALSE, "Yanked: %s", a.s); + a.s = arg->s ? g_strdup(arg->s) : NULL; + } + if (a.s) { + vp_set_clipboard(&a); + /* TODO is this the rigth place to switch the focus */ + gtk_widget_grab_focus(GTK_WIDGET(vp.gui.webview)); + vp_echo(VP_MSG_NORMAL, FALSE, "Yanked: %s", a.s); + g_free(a.s); - return TRUE; - } + return TRUE; } + return FALSE; } diff --git a/src/hints.c b/src/hints.c index 213dd5d..90e93c5 100644 --- a/src/hints.c +++ b/src/hints.c @@ -389,6 +389,12 @@ static void hints_process_fired_hint(guint mode, const gchar* uri) case HINTS_PROCESS_YANK: /* TODO not implemented */ + a.i = COMMAND_YANK_PRIMARY | COMMAND_YANK_SECONDARY; + a.s = g_strdup(uri); + command_yank(&a); + g_free(a.s); + /* TODO add a command that do the mode switching instead */ + vp_set_mode(VP_MODE_NORMAL, FALSE); break; } } diff --git a/src/hints.h b/src/hints.h index b5390b0..a911978 100644 --- a/src/hints.h +++ b/src/hints.h @@ -51,7 +51,7 @@ enum { typedef enum { HINTS_PROCESS_INPUT = (1 << 4), - HINTS_PROCESS_YANK + HINTS_PROCESS_YANK = (1 << 5), } HintsProcess; void hints_init(void); |