Re: Search from location bar
Johannes Hofmann <[email protected]>
| Newsgroups | gmane.comp.web.dillo.devel |
|---|---|
| Message-ID | <[email protected]> |
On Wed, Nov 23, 2011 at 10:52:54AM -0500, Benjamin Johnson wrote: > corvid wrote: > > >Stephen wrote: > >>Would there be any interest in enabling Dillo to search the default > >>(read: first in dillorc) search engine when a non-URI is typed into > >>the location bar? This is especially useful for things like > >>yubnub.org, which I use heavily. > > > >There has been some talk in the past of how it would be nice if > >one could type various commands into the location bar... > > I've been meaning to do that forever, probably along the lines of > Opera's search shortcuts. (e.g., "g foo" to search Google, "w foo" > to search Wikipedia, etc.) You get used to that and it really > spoils you... Attached is a quick hack to test this. I have to say, that it feels quite handy. The dillorc interface seems not optimal though (suggestions?). Cheers, Johannes _______________________________________________ Dillo-dev mailing list [email protected] http://lists.auriga.wearlab.de/cgi-bin/mailman/listinfo/dillo-dev
search_shortcuts.diff
(text/plain, 4.5 KB)
diff -r 929b584ad3ac dillorc
--- a/dillorc Thu Nov 17 07:57:01 2011 +0000
+++ b/dillorc Thu Nov 24 21:37:11 2011 +0100
@@ -113,10 +113,15 @@
# You can enable multiple search_url strings at once and select from among
# them at runtime, with the first being the default.
search_url="http://duckduckgo.com/lite/?kp=-1&q=%s"
+search_shortcut="d"
search_url="Scroogle https://ssl.scroogle.org/cgi-bin/nbbwssl.cgi?Gw=%s"
+search_shortcut="s"
search_url="Wikipedia http://www.wikipedia.org/w/index.php?search=%s&go=Go"
+search_shortcut="w"
search_url="Free Dictionary http://www.thefreedictionary.com/%s"
+search_shortcut="free"
search_url="Google http://www.google.com/search?ie=UTF-8&oe=UTF-8&q=%s"
+search_shortcut="g"
# If set, dillo will ask web servers to send pages in this language.
# This setting does NOT change dillo's user interface.
diff -r 929b584ad3ac src/prefs.c
--- a/src/prefs.c Thu Nov 17 07:57:01 2011 +0000
+++ b/src/prefs.c Thu Nov 24 21:37:11 2011 +0100
@@ -80,6 +80,7 @@
dList_append(prefs.search_urls, dStrdup(PREFS_SEARCH_URL));
dList_append(prefs.search_urls, NULL); /* flags a default search URL */
prefs.search_url_idx = 0;
+ prefs.search_shortcuts = dList_new(16);
prefs.show_back = TRUE;
prefs.show_bookmarks = TRUE;
prefs.show_clear_url = TRUE;
@@ -128,6 +129,9 @@
for (i = 0; i < dList_length(prefs.search_urls); ++i)
dFree(dList_nth_data(prefs.search_urls, i));
dList_free(prefs.search_urls);
+ for (i = 0; i < dList_length(prefs.search_shortcuts); ++i)
+ dFree(dList_nth_data(prefs.search_shortcuts, i));
+ dList_free(prefs.search_shortcuts);
a_Url_free(prefs.start_page);
dFree(prefs.theme);
}
diff -r 929b584ad3ac src/prefs.h
--- a/src/prefs.h Thu Nov 17 07:57:01 2011 +0000
+++ b/src/prefs.h Thu Nov 24 21:37:11 2011 +0100
@@ -89,6 +89,7 @@
bool_t right_click_closes_tab;
bool_t search_url_idx;
Dlist *search_urls;
+ Dlist *search_shortcuts;
char *save_dir;
bool_t show_msg;
bool_t show_extra_warnings;
diff -r 929b584ad3ac src/prefsparser.cc
--- a/src/prefsparser.cc Thu Nov 17 07:57:01 2011 +0000
+++ b/src/prefsparser.cc Thu Nov 24 21:37:11 2011 +0100
@@ -88,6 +88,7 @@
{ "parse_embedded_css", &prefs.parse_embedded_css, PREFS_BOOL },
{ "save_dir", &prefs.save_dir, PREFS_STRING },
{ "search_url", &prefs.search_urls, PREFS_STRINGS },
+ { "search_shortcut", &prefs.search_shortcuts, PREFS_STRINGS },
{ "show_back", &prefs.show_back, PREFS_BOOL },
{ "show_bookmarks", &prefs.show_bookmarks, PREFS_BOOL },
{ "show_clear_url", &prefs.show_clear_url, PREFS_BOOL },
diff -r 929b584ad3ac src/ui.cc
--- a/src/ui.cc Thu Nov 17 07:57:01 2011 +0000
+++ b/src/ui.cc Thu Nov 24 21:37:11 2011 +0100
@@ -282,7 +282,7 @@
UI *ui = (UI*)data;
_MSG("location_cb()\n");
- a_UIcmd_open_urlstr(a_UIcmd_get_bw_by_widget(i), i->value());
+ a_UIcmd_open_url_or_search_str(a_UIcmd_get_bw_by_widget(i), i->value());
if (ui->temporaryPanels())
ui->panels_toggle();
diff -r 929b584ad3ac src/uicmd.cc
--- a/src/uicmd.cc Thu Nov 17 07:57:01 2011 +0000
+++ b/src/uicmd.cc Thu Nov 24 21:37:11 2011 +0100
@@ -913,6 +913,33 @@
}
/*
+ * Open a new URL in the given browser window.
+ *
+ * Search shortcuts are expanded.
+ *
+ */
+void a_UIcmd_open_url_or_search_str(void *vbw, const char *urlstr)
+{
+ char *search_url = NULL;
+
+ for (int i = 0; i < dList_length(prefs.search_shortcuts); i++) {
+ char *shortcut = (char *)dList_nth_data(prefs.search_shortcuts, i);
+ if (i >= dList_length(prefs.search_urls))
+ break;
+
+ if (strncmp(shortcut, urlstr, strlen(shortcut)) == 0 &&
+ strlen(urlstr) > strlen(shortcut) &&
+ urlstr[strlen(shortcut)] == ' ') {
+ prefs.search_url_idx = i;
+ urlstr = search_url = UIcmd_make_search_str(urlstr + strlen(shortcut) + 1);
+ }
+ }
+
+ a_UIcmd_open_urlstr(vbw, urlstr);
+ free(search_url);
+}
+
+/*
* Get password for user
*/
const char *a_UIcmd_get_passwd(const char *user)
diff -r 929b584ad3ac src/uicmd.hh
--- a/src/uicmd.hh Thu Nov 17 07:57:01 2011 +0000
+++ b/src/uicmd.hh Thu Nov 24 21:37:11 2011 +0100
@@ -13,6 +13,7 @@
BrowserWindow *a_UIcmd_get_bw_by_widget(void *v_wid);
void a_UIcmd_send_event_to_tabs_by_wid(int e, void *v_wid);
void a_UIcmd_open_urlstr(void *vbw, const char *urlstr);
+void a_UIcmd_open_url_or_search_str(void *vbw, const char *urlstr);
void a_UIcmd_open_url(BrowserWindow *bw, const DilloUrl *url);
void a_UIcmd_open_url_nw(BrowserWindow *bw, const DilloUrl *url);
void a_UIcmd_open_url_nt(void *vbw, const DilloUrl *url, int focus);