Allow to open the clipboard content as uri.
authorDaniel Carl <danielcarl@gmx.de>
Wed, 13 Feb 2013 18:57:55 +0000 (19:57 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Wed, 13 Feb 2013 18:57:55 +0000 (19:57 +0100)
There are two new keybindings to open the clipboards content in current window
(p) and into a new window (P).

doc/vimp.1.txt
src/command.c
src/command.h
src/config.h
src/main.h

index aa0cc74..f3a07ce 100644 (file)
@@ -64,17 +64,14 @@ Open the give url into current window.
 .B tabopen
 Open the give url into a new window.
 .TP
-.B open-home
-Opens the configured 'home-page' into current window.
+.B (tab)open-home
+Opens the configured 'home-page'.
 .TP
-.B tabopen-home
-Opens the home page into a new window.
+.B (tab)open-closed
+Open the last closed page.
 .TP
-.B open-closed
-Open the last closed page into current window.
-.TP
-.B tabopen-closed
-Open the last closed page into new window.
+.B (tab)open-clipboard
+Open the url from clipboard.
 .SS Input
 Switches the browser into Command Mode and prefill the inputbox on th bottom of
 the browser with various prefilled content.
index d2b8614..98d9731 100644 (file)
@@ -80,6 +80,8 @@ static CommandInfo cmd_list[] = {
     {"hint-focus-prev",     command_hints_focus, {1}},
     {"yank-uri",            command_yank,        {COMMAND_YANK_PRIMARY | COMMAND_YANK_SECONDARY | COMMAND_YANK_URI}},
     {"yank-selection",      command_yank,        {COMMAND_YANK_PRIMARY | COMMAND_YANK_SECONDARY | COMMAND_YANK_SELECTION}},
+    {"open-clipboard",      command_paste,       {VP_CLIPBOARD_PRIMARY | VP_CLIPBOARD_SECONDARY | VP_TARGET_CURRENT}},
+    {"tabopen-clipboard",   command_paste,       {VP_CLIPBOARD_PRIMARY | VP_CLIPBOARD_SECONDARY | VP_TARGET_NEW}},
     {"search-forward",      command_search,      {VP_SEARCH_FORWARD}},
     {"search-backward",     command_search,      {VP_SEARCH_BACKWARD}},
 };
@@ -382,6 +384,25 @@ gboolean command_yank(const Arg* arg)
     return FALSE;
 }
 
+gboolean command_paste(const Arg* arg)
+{
+    Arg a = {.i = arg->i & VP_TARGET_NEW};
+    if (arg->i & VP_CLIPBOARD_PRIMARY) {
+        a.s = gtk_clipboard_wait_for_text(PRIMARY_CLIPBOARD());
+    }
+    if (!a.s && arg->i & VP_CLIPBOARD_SECONDARY) {
+        a.s = gtk_clipboard_wait_for_text(SECONDARY_CLIPBOARD());
+    }
+
+    if (a.s) {
+        vp_load_uri(&a);
+        g_free(a.s);
+
+        return TRUE;
+    }
+    return FALSE;
+}
+
 gboolean command_search(const Arg* arg)
 {
     State* state     = &vp.state;
index 9e0ee2a..cd9a15a 100644 (file)
@@ -57,6 +57,7 @@ gboolean command_inspect(const Arg* arg);
 gboolean command_hints(const Arg* arg);
 gboolean command_hints_focus(const Arg* arg);
 gboolean command_yank(const Arg* arg);
+gboolean command_paste(const Arg* arg);
 gboolean command_search(const Arg* arg);
 
 #endif /* end of include guard: COMMAND_H */
index cd31bac..853cdda 100644 (file)
@@ -68,6 +68,8 @@ const struct {
     {"nmap ;y=hint-yank"},
     {"nmap y=yank-uri"},
     {"nmap Y=yank-selection"},
+    {"nmap p=open-clipboard"},
+    {"nmap P=tabopen-clipboard"},
     {"cmap <tab>=complete"},
     {"cmap <shift-tab>=complete-back"},
     {"hmap <tab>=hint-focus-next"},
index 5593bc8..ee82bdb 100644 (file)
@@ -176,8 +176,8 @@ typedef enum {
 } Type;
 
 enum {
-    VP_CLIPBOARD_PRIMARY   = (1<<0),
-    VP_CLIPBOARD_SECONDARY = (1<<1)
+    VP_CLIPBOARD_PRIMARY   = (1<<1),
+    VP_CLIPBOARD_SECONDARY = (1<<2)
 };
 
 /* structs */