Allow to yank hinted link url.
authorDaniel Carl <danielcarl@gmx.de>
Mon, 24 Dec 2012 02:29:23 +0000 (03:29 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Mon, 24 Dec 2012 02:46:29 +0000 (03:46 +0100)
doc/config
src/command.c
src/hints.c
src/hints.h

index 89dbe81..dda7453 100644 (file)
@@ -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
index 247bb80..d94a14b 100644 (file)
@@ -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;
 }
 
index 213dd5d..90e93c5 100644 (file)
@@ -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;
     }
 }
index b5390b0..a911978 100644 (file)
@@ -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);