From 30f992730e4957d4cf6319524c1054f8ec77c716 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Thu, 14 Jan 2016 19:09:16 +0000 Subject: Re-instate the ability to do a web search for selected text --- amiga/ctxmenu.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'amiga') diff --git a/amiga/ctxmenu.c b/amiga/ctxmenu.c index 42d0da38b..8b3b03a41 100644 --- a/amiga/ctxmenu.c +++ b/amiga/ctxmenu.c @@ -47,6 +47,7 @@ #include "desktop/browser.h" #include "desktop/browser_history.h" #include "desktop/mouse.h" +#include "desktop/searchweb.h" #include "desktop/textinput.h" #include "utils/log.h" @@ -58,6 +59,7 @@ enum { /* Text selection */ AMI_CTX_ID_SELCOPY, + AMI_CTX_ID_WEBSEARCH, /* Links */ AMI_CTX_ID_URLOPENTAB, @@ -104,6 +106,30 @@ HOOKF(void, ami_ctxmenu_item_selcopy, APTR, window, struct IntuiMessage *) browser_window_key_press(gwin->gw->bw, NS_KEY_CLEAR_SELECTION); } +HOOKF(void, ami_ctxmenu_item_websearch, APTR, window, struct IntuiMessage *) +{ + nserror ret = NSERROR_OK; + nsurl *url; + + struct gui_window_2 *gwin = (struct gui_window_2 *)hook->h_Data; + const char *sel = browser_window_get_selection(gwin->gw->bw); + + ret = search_web_omni(sel, SEARCH_WEB_OMNI_SEARCHONLY, &url); + if (ret == NSERROR_OK) { + browser_window_navigate(gwin->gw->bw, + url, + NULL, + BW_NAVIGATE_HISTORY, + NULL, + NULL, + NULL); + nsurl_unref(url); + } + if (ret != NSERROR_OK) { + warn_user(messages_get_errorcode(ret), 0); + } +} + HOOKF(void, ami_ctxmenu_item_urlopentab, APTR, window, struct IntuiMessage *) { struct browser_window *bw; @@ -292,6 +318,7 @@ static uint32 ami_ctxmenu_hook_func(struct Hook *hook, struct Window *window, st ((browser_window_get_editor_flags(gwin->gw->bw) & BW_EDITOR_CAN_COPY))) { ami_ctxmenu_add_item(root_menu, AMI_CTX_ID_SELCOPY, gwin); + ami_ctxmenu_add_item(root_menu, AMI_CTX_ID_WEBSEARCH, gwin); ctxmenu_has_content = true; } @@ -417,6 +444,8 @@ void ami_ctxmenu_init(void) ami_ctxmenu_alloc_item(AMI_CTX_ID_SELCOPY, "CopyNS", "C", "TBImages:list_copy", ami_ctxmenu_item_selcopy); + ami_ctxmenu_alloc_item(AMI_CTX_ID_WEBSEARCH, "SearchWeb", NULL, "TBImages:list_search", + ami_ctxmenu_item_websearch); ami_ctxmenu_alloc_item(AMI_CTX_ID_URLOPENTAB, "LinkNewTab", NULL, "TBImages:list_tab", ami_ctxmenu_item_urlopentab); -- cgit v1.2.3