diff --git a/ChangeLog b/ChangeLog index b8a2a547..1e2817ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,9 @@
+2007-05-02: + * version ??? + * Added keyword support for bookmarks to the :[tab]open commands + * many small bug fixes + 2007-05-02: * version 0.4.1 * Fixed bug that :open google.com/mail opened ".com/mail" in google search diff --git a/Donators b/Donators index c5ff869f..d36eb2b8 100644 --- a/Donators +++ b/Donators @@ -5,6 +5,8 @@ * Ben Klemens * Sjoerd Siebinga * Cillian de Roiste +* Miron Tewfik +* Robert Heckel I want to say a big THANK YOU for all people which supported this project in this way.diff --git a/Makefile b/Makefile index 65aa8194..cab6cf1f 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,13 @@ VERSION = 0.4.1 OS = $(shell uname -s) BUILD_DATE = $(shell date "+%Y/%m/%d %H:%M:%S") -JAR_FILES = ${shell find chrome/content -type f -a ! -path '*CVS*' ! -name 'tags'} chrome.manifest +JAR_FILES = ${shell find chrome/content -type f \ + -a ! -path '*CVS*' \ + -a \( -path '*.js' \ + -o -path '*.css' \ + -o -path '*.xul' \ + -o -path '*.rdf' \ + \) } chrome.manifest JAR_DIRS = $(foreach f,${JAR_FILES},$(dir $f)) JAR = chrome/vimperator.jar diff --git a/chrome/content/vimperator/bookmarks.js b/chrome/content/vimperator/bookmarks.js index 6054a846..f8c2c173 100644 --- a/chrome/content/vimperator/bookmarks.js +++ b/chrome/content/vimperator/bookmarks.js @@ -151,50 +151,93 @@ function parseBookmarkString(str, res) return true; } -/* also ensures that each search engine has a vimperator-friendly alias */ -function getSearchEngines() -{ - var search_engines = []; - const nsSS = Components.classes["@mozilla.org/browser/search-service;1"]. - getService(Components.interfaces.nsIBrowserSearchService); - var firefox_engines = nsSS.getVisibleEngines({ }); - for(var i in firefox_engines) - { - if (!firefox_engines[i].alias || !firefox_engines[i].alias.match(/^[a-z0-9_]+$/)) - { - var alias = firefox_engines[i].name.replace(/^\W*(\w+).*/, "$1").toLowerCase(); - firefox_engines[i].alias = alias; - } - search_engines.push([firefox_engines[i].alias, firefox_engines[i].description]); - } - return search_engines; -} - -function Search() +function Bookmarks() { const search_service = Components.classes["@mozilla.org/browser/search-service;1"]. - getService(Components.interfaces.nsIBrowserSearchService); + getService(Components.interfaces.nsIBrowserSearchService); - this.getDefaultEngine = function() + /* also ensures that each search engine has a vimperator-friendly alias */ + this.getSearchEngines = function() { - return search_service.currentEngine; + var search_engines = []; + var firefox_engines = search_service.getVisibleEngines({ }); + for(var i in firefox_engines) + { + if (!firefox_engines[i].alias || !firefox_engines[i].alias.match(/^[a-z0-9_]+$/)) + { + var alias = firefox_engines[i].name.replace(/^\W*(\w+).*/, "$1").toLowerCase(); + firefox_engines[i].alias = alias; + } + search_engines.push([firefox_engines[i].alias, firefox_engines[i].description]); + } + + return search_engines; } - this.setDefaultEngine = function(alias) + // FIXME: for now g_keywords is generated by get_bookmarks_completion, WILL HAVE TO CHANGE + // format of returned array: + // [keyword, helptext, url] + this.getKeywords = function() { - var engine = search_service.getEngineByAlias(alias); + return g_keywords; + } + + // xxx: probably remove these functions + // this.getDefaultEngine = function() + // { + // return search_service.currentEngine; + // } + // this.setDefaultEngine = function(alias) + // { + // var engine = search_service.getEngineByAlias(alias); + // if(engine) + // search_service.currentEngine = engine; + // else + // echoerr("Error: Search engine with alias '" + alias + "' does not exist"); + // } + // this.getEngine = function(alias) + // { + // var engine = search_service.getEngineByAlias(alias); + // return engine; + // } + + // if the engine name is null, it uses the default search engine + // returns a url for the search string + this.getSearchURL = function(text, engine_name) + { + var url = null; + if(!engine_name || engine_name == "") + engine_name = get_pref("defsearch", "google"); + + // first checks the search engines for a match + var engine = search_service.getEngineByAlias(engine_name); if(engine) - search_service.currentEngine = engine; - else - echoerr("Error: Search engine with alias '" + alias + "' does not exist"); - } + { + if(text) + url = engine.getSubmission(text, null).uri.spec; + else + url = engine.searchForm; + } + else // check for keyword urls + { + for (var i in g_keywords) + { + if(g_keywords[i][0] == engine_name) + { + if (text == null) + text = ""; + url = g_keywords[i][2].replace(/%s/g, encodeURIComponent(text)); + break; + } + } + } - this.getEngine = function(alias) - { - var engine = search_service.getEngineByAlias(alias); - return engine; + // if we came here, the engine_name is neither + return url; } + logMessage("Bookmarks initialized."); } -var search = new Search(); // FIXME, must it really be here? doesn't work in vimperator.js + +var bookmarks = new Bookmarks(); // FIXME, must it really be here? doesn't work in vimperator.js // vim: set fdm=marker sw=4 ts=4 et: diff --git a/chrome/content/vimperator/commands.js b/chrome/content/vimperator/commands.js index d7e5e8d7..c2bb16eb 100644 --- a/chrome/content/vimperator/commands.js +++ b/chrome/content/vimperator/commands.js @@ -239,11 +239,11 @@ var g_commands = [/*{{{*/ "Open one ore more URLs in the current tab", "Multiple URLs can be separated with the | character.
:open wiki linus torvalds will open the wikipedia entry for linux torvalds).:open wikipedia linus torvalds will open the wikipedia entry for linux torvalds).'defsearch' setting) if the first word is no search engine (:open linus torvalds will open a google search for linux torvalds).:open ... with current location \"http://www.example.com/dir1/dir2/file.html\" will open \"http://www.example.com\":open ./foo.html with current location \"http://www.example.com/dir1/dir2/file.html\" will open \"http://www.example.com/dir1/dir2/foo.html\":open linus torvalds will open a google search for linux torvalds).:open www.osnews.com | www.slashdot.org will open OSNews in the current, and Slashdot in a new background tab).:open [-T \"linux\"] torvalds<Tab> to complete bookmarks with tag \"linux\" and which contain \"torvalds\". Note that -T support is only available for tab completion, not for the actual command.<Tab> are specified in the 'complete' option.p",
+ "You can also just select some non-URL text, and search for it with the default search engine or keyword (specified by the 'defsearch' setting) with p",
function(count) { openURLs(readFromClipboard()); }
],
[
@@ -1301,55 +1301,6 @@ function stringToURLs(str)
var urls = str.split(/\s*\|\s*/);
begin: for(var url=0; url < urls.length; url++)
{
- /*for(var i=0; i < g_searchengines.length; i++)
- {
- var regex = new RegExp("^" + g_searchengines[i][0] + "\\s+" + "(.+)");
- matches = urls[url].match(regex);
- if(matches != null)
- {
- urls[url] = g_searchengines[i][1].replace(/%s/, encodeURIComponent(matches[1]));
- break begin;
- }
- }*/
-
- // first check if the first word is a search engine
- var matches = urls[url].match(/^\s*(\w+)(\s+|$)(.*)/);
- var alias = null;
- var text = null;
- if (matches && matches[1])
- alias = matches[1];
- if (matches && matches[3] && matches[3].length >= 1)
- text = matches[3];
-
- if (alias)
- {
- var engine = search.getEngine(alias);
- if (engine)
- {
- if(text)
- urls[url] = engine.getSubmission(text, null).uri.spec;
- else
- urls[url] = engine.searchForm;
-
- continue;
- }
- }
-
- /* if the string contains a space or does not contain any of: .:/
- * open it with default search engine */
- if (urls[url].match(/\s+/) || urls[url].match(/\.|:|\//) == null)
- {
- // defaultEngine is always the same (Google), therefor let's use the currentEngine
- //var default_engine = search_service.currentEngine;
- var default_engine = search.getDefaultEngine();
- if (default_engine)
- {
- urls[url] = default_engine.getSubmission(urls[url], null).uri.spec;
- continue;
- }
- }
-
-
// check for ./ and ../ (or even .../) to go to a file in the upper directory
if (urls[url].match(/^(\.$|\.\/\S*)/))
{
@@ -1359,6 +1310,7 @@ function stringToURLs(str)
newLocation += urls[url].replace(/^\.(\/\S+)/, "$1");
urls[url] = newLocation;
+ continue;
}
else if (urls[url].match(/^(\.\.$|\.\.\/[\S]*)/))
{
@@ -1368,6 +1320,7 @@ function stringToURLs(str)
newLocation += urls[url].replace(/^\.\.\/(\S+)/, "$1");
urls[url] = newLocation;
+ continue;
}
else if (urls[url].match(/^(\.\.\.$|\.\.\.\/[\S]*)/))
{
@@ -1377,15 +1330,47 @@ function stringToURLs(str)
newLocation += urls[url].replace(/^\.\.\.\/(\S+)/, "$1");
urls[url] = newLocation;
+ continue;
}
+ /* if the string contains a space or does not contain any of: .:/
+ * open it with default search engine */
+ if (urls[url].match(/\s+/) || urls[url].match(/\.|:|\//) == null)
+ {
+ // check if the first word is a search engine
+ var matches = urls[url].match(/^\s*(.*?)(\s+|$)(.*)/);
+ var alias = null;
+ var text = null;
+ if (matches && matches[1])
+ alias = matches[1];
+ if (matches && matches[3] && matches[3].length >= 1)
+ text = matches[3];
+
+ var search_url = bookmarks.getSearchURL(text, alias);
+ if (search_url && search_url.length >= 1)
+ {
+ urls[url] = search_url;
+ continue;
+ }
+ else // the first word was not a search engine, search for the whole string in the default engine
+ {
+ search_url = bookmarks.getSearchURL(urls[url], null);
+ if (search_url && search_url.length >= 1)
+ {
+ urls[url] = search_url;
+ continue;
+ }
+ }
+ }
+
+ // if we are here let Firefox handle the url and hope it does
+ // something useful with it :)
}
return urls;
}
/* returns true if the currently loaded URI is
* a directory or false if it is a file
- * if passed 'url' is null, use current directory
*/
function isDirectory(url)
{
diff --git a/chrome/content/vimperator/completion.js b/chrome/content/vimperator/completion.js
index 8f9fc6ee..f03e48f8 100644
--- a/chrome/content/vimperator/completion.js
+++ b/chrome/content/vimperator/completion.js
@@ -12,6 +12,9 @@ var bookmarks_loaded = false;
var g_history = [];
var history_loaded = false;
+// array of our bookmark keywords
+var g_keywords = [];
+
// variables for the tab completion and command history:
// -1: filled, but no selection made
// >= 0: index of current item in the g_completions array
@@ -390,7 +393,9 @@ function filter_url_array(urls, filter)/*{{{*/
function get_search_completions(filter)/*{{{*/
{
- var engines = getSearchEngines();
+ //var engines = bookmarks.getSearchEngines();//.concat(bookmarks.getKeywords());
+ //var engines = bokmarks.getKeywords();//.concat(bookmarks.getKeywords());
+ var engines = bookmarks.getSearchEngines().concat(bookmarks.getKeywords());
if (!filter) return engines.map(function($_) {
return [$_[0], $_[1]];
@@ -459,20 +464,27 @@ function get_bookmark_completions(filter)/*{{{*/
// update our bookmark cache
var RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService( Components.interfaces.nsIRDFService );
var root = RDF.GetResource( "NC:BookmarksRoot" );
- bookmarks = []; // here getAllChildren will store the bookmarks
+ var bmarks = []; // here getAllChildren will store the bookmarks
g_bookmarks = []; // also clear our bookmark cache
- BookmarksUtils.getAllChildren(root, bookmarks);
+ // FIXME: wrong location
+ g_keywords = [];
+
+ BookmarksUtils.getAllChildren(root, bmarks);
// alert(bookmarks[0].length);
- for(var i = 0; i < bookmarks.length; i++)
+ for(var i = 0; i < bmarks.length; i++)
{
- if (bookmarks[i][0] && bookmarks[i][1])
+ if (bmarks[i][0] && bmarks[i][1])
{
- g_bookmarks.push([bookmarks[i][1].Value, bookmarks[i][0].Value ]);
+ g_bookmarks.push([bmarks[i][1].Value, bmarks[i][0].Value ]);
}
// for(var j=0; j < bookmarks[i].length; j++)
// {
-// if(bookmarks[i][2])
-// alert("2: " + bookmarks[i][2].Value);
+ // keyword
+ if(bmarks[i][1] && bmarks[i][2])
+ g_keywords.push([bmarks[i][2].Value, bmarks[i][0].Value, bmarks[i][1].Value]);
+ //g_keywords.push([bookmarks[i][2].Value, bookmarks[i][0].Value + " (" + bookmarks[i][1].Value + ")"]);
+ //g_keywords.push([[bookmarks[i][2].Value, bookmarks[i][1].Value], bookmarks[i][0].Value]);
+ //alert("2: " + bookmarks[i][2].Value);
// if(bookmarks[i][3])
// alert("3: " + bookmarks[i][3].Value);
// if(bookmarks[i][4])
diff --git a/chrome/content/vimperator/help.js b/chrome/content/vimperator/help.js
index e0605a2b..2b62e7d1 100644
Binary files a/chrome/content/vimperator/help.js and b/chrome/content/vimperator/help.js differ
diff --git a/chrome/content/vimperator/settings.js b/chrome/content/vimperator/settings.js
index d1a3e19e..d8fdab22 100644
--- a/chrome/content/vimperator/settings.js
+++ b/chrome/content/vimperator/settings.js
@@ -63,7 +63,7 @@ var g_settings = [/*{{{*/
["complete", "cpt"],
"Items which are completed at the :[tab]open prompt",
"Available items: