From: Daniel Carl Date: Wed, 13 Feb 2013 18:57:55 +0000 (+0100) Subject: Allow to open the clipboard content as uri. X-Git-Url: https://git.owens.tech/assets/static/git-logo.png/assets/static/git-logo.png/git?a=commitdiff_plain;h=7a1ac793e28e41db1d1b5c92784ee0e795a21f72;p=vimb.git Allow to open the clipboard content as uri. There are two new keybindings to open the clipboards content in current window (p) and into a new window (P). --- diff --git a/doc/vimp.1.txt b/doc/vimp.1.txt index aa0cc74..f3a07ce 100644 --- a/doc/vimp.1.txt +++ b/doc/vimp.1.txt @@ -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. diff --git a/src/command.c b/src/command.c index d2b8614..98d9731 100644 --- a/src/command.c +++ b/src/command.c @@ -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; diff --git a/src/command.h b/src/command.h index 9e0ee2a..cd9a15a 100644 --- a/src/command.h +++ b/src/command.h @@ -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 */ diff --git a/src/config.h b/src/config.h index cd31bac..853cdda 100644 --- a/src/config.h +++ b/src/config.h @@ -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 =complete"}, {"cmap =complete-back"}, {"hmap =hint-focus-next"}, diff --git a/src/main.h b/src/main.h index 5593bc8..ee82bdb 100644 --- a/src/main.h +++ b/src/main.h @@ -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 */