diff --git a/chrome/content/vimperator/bookmarks.js b/chrome/content/vimperator/bookmarks.js
index d2a1f809..a188628a 100644
--- a/chrome/content/vimperator/bookmarks.js
+++ b/chrome/content/vimperator/bookmarks.js
@@ -224,7 +224,7 @@ function Bookmarks() //{{{
this.list = function(filter, fullmode)
{
if (fullmode)
- openURLsInNewTab("chrome://browser/content/bookmarks/bookmarksPanel.xul", true);
+ vimperator.open("chrome://browser/content/bookmarks/bookmarksPanel.xul", vimperator.NEW_TAB);
else
{
var items = vimperator.bookmarks.get(filter);
@@ -433,7 +433,7 @@ function History() //{{{
this.list = function(filter, fullmode)
{
if (fullmode)
- openURLsInNewTab("chrome://browser/content/history/history-panel.xul", true);
+ vimperator.open("chrome://browser/content/history/history-panel.xul", vimperator.NEW_TAB);
else
{
var items = vimperator.history.get(filter);
@@ -612,7 +612,7 @@ function Marks() //{{{
pending_jumps.push(slice);
// NOTE: this obviously won't work on generated pages using
// non-unique URLs, like Vimperator's help :(
- openURLsInNewTab(slice.location, true);
+ vimperator.open(slice.location, vimperator.NEW_TAB);
return;
}
var index = vimperator.tabs.index(slice.tab);
@@ -728,14 +728,9 @@ function QuickMarks() //{{{
{
var url = marks[mark];
if (url)
- {
- if (newtab)
- openURLsInNewTab(url, true);
- else
- openURLs(url);
- }
+ vimperator.open(url, newtab ? vimperator.NEW_TAB : vimperator.CURRENT_TAB);
else
- vimperator.echoerr("E20: QuickMark not set"); // FIXME: move up?
+ vimperator.echoerr("E20: QuickMark not set");
}
this.list = function()
diff --git a/chrome/content/vimperator/commands.js b/chrome/content/vimperator/commands.js
index 09a3a7ee..a008ea98 100644
--- a/chrome/content/vimperator/commands.js
+++ b/chrome/content/vimperator/commands.js
@@ -196,7 +196,7 @@ function Commands() //{{{
/////////////////////////////////////////////////////////////////////////////{{{
addDefaultCommand(new Command(["addo[ns]"],
- function() { openURLsInNewTab("chrome://mozapps/content/extensions/extensions.xul", true); },
+ function() { vimperator.open("chrome://mozapps/content/extensions/extensions.xul", vimperator.NEW_TAB); },
{
short_help: "Show available Browser Extensions and Themes",
help: "You can add/remove/disable browser extensions from this dialog.
Be aware that not all Firefox extensions work, because Vimperator overrides some keybindings and changes Firefox's GUI."
@@ -399,7 +399,7 @@ function Commands() //{{{
));
addDefaultCommand(new Command(["downl[oads]", "dl"],
- function() { openURLsInNewTab("chrome://mozapps/content/downloads/downloads.xul", true); },
+ function() { vimperator.open("chrome://mozapps/content/downloads/downloads.xul", vimperator.NEW_TAB); },
{
short_help: "Show progress of current downloads",
help: "Open the original Firefox download dialog in a new tab.
" +
@@ -486,7 +486,7 @@ function Commands() //{{{
function(args, special)
{
if (special) // open javascript console
- openURLsInNewTab("chrome://global/content/console.xul", true);
+ vimperator.open("chrome://global/content/console.xul", vimperator.NEW_TAB);
else
try
{
@@ -674,7 +674,7 @@ function Commands() //{{{
function(args, special)
{
if (args.length > 0)
- openURLs(args);
+ vimperator.open(args);
else
{
if (special)
@@ -773,14 +773,15 @@ function Commands() //{{{
{
if (args == "")
{
- var func = openURLs;
+ // TODO: copy these snippets to more function which should work with :tab xxx
+ var where = vimperator.CURRENT_TAB;
if (arguments[3] && arguments[3].inTab)
- func = openURLsInNewTab;
+ where = vimperator.NEW_TAB;
if (special) // open firefox settings gui dialog
- func.call(this, "chrome://browser/content/preferences/preferences.xul", true);
+ vimperator.open("chrome://browser/content/preferences/preferences.xul", where);
else
- func.call(this, "about:config", true);
+ vimperator.open("about:config", where);
}
else
{
@@ -951,9 +952,9 @@ function Commands() //{{{
function(args, special)
{
if (args.length > 0)
- openURLsInNewTab(args, !special);
+ vimperator.open(args, special ? vimperator.NEW_BACKGROUND_TAB : vimperator.NEW_TAB);
else
- openURLsInNewTab("about:blank", true);
+ vimperator.open("about:blank", vimperator.NEW_TAB);
},
{
usage: ["tabopen [url] [| url]"],
@@ -989,13 +990,20 @@ function Commands() //{{{
addDefaultCommand(new Command(["qmarka[dd]", "qma[dd]"],
function(args)
{
- var split = args.split(/\s+/);
- vimperator.quickmarks.add(split[0], split[1] ? split[1] : getCurrentLocation());
+ var matches1 = args.match(/([a-zA-Z0-9])\s+(.+)/);
+ var matches2 = args.match(/([a-zA-Z0-9])\s*$/);
+ if (matches1 && matches1[1])
+ vimperator.quickmarks.add(matches1[1], matches1[2]);
+ else if (matches2 && matches2)
+ vimperator.quickmarks.add(matches2[1], getCurrentLocation());
+ else
+ vimperator.echoerr("E488: Trailing characters");
},
{
usage: ["qmarka[dd] {a-zA-Z0-9} [url]"],
short_help: "Mark a URL with a letter for quick access",
- help: "TODO.",
+ help: "You can also mark whole groups like this:
"+
+ ":qmarkadd f http://forum1.com, http://forum2.com, imdb some artist",
completer: function(filter) { return [["a", ""], ["b", ""]]; }
}
));
@@ -1041,7 +1049,7 @@ function Commands() //{{{
function(args, special)
{
if (special)
- openURLs("about:");
+ vimperator.open("about:");
else
vimperator.echo("Vimperator version: " + vimperator.version);
},
@@ -1172,38 +1180,6 @@ function execute(string)
return execute_command.apply(this, tokens);
}
-/////////////////////////////////////////////////////////////////////}}}
-// url functions ///////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////{{{
-
-function openURLs(str)
-{
- var urls = str.toURLArray();
- if (urls.length == 0)
- return false;
-
- getBrowser().loadURI(urls[0]);
-
- for (var url=1; url < urls.length; url++)
- getBrowser().addTab(urls[url]);
-
- return true;
-}
-
-function openURLsInNewTab(str, activate)
-{
- var urls = str.toURLArray();
- if (urls.length == 0)
- return null;
-
- var firsttab = getBrowser().addTab(urls[0]);
- if (activate)
- getBrowser().selectedTab = firsttab;
- for (var url = 1; url < urls.length; url++)
- gBrowser.addTab(urls[url]);
-
- return firsttab;
-}
/* takes a string like 'google bla| www.osnews.com'
* and returns an array ['www.google.com/search?q=bla', 'www.osnews.com']
diff --git a/chrome/content/vimperator/help.js b/chrome/content/vimperator/help.js
index df3cb78e..74f9b2ee 100644
--- a/chrome/content/vimperator/help.js
+++ b/chrome/content/vimperator/help.js
@@ -35,9 +35,9 @@ vimperator.help = function(section, easter) //{{{
}
if ((arguments[3] && arguments[3].inTab))// || !window.content.document.open)
- openURLsInNewTab("", true);
+ vimperator.open("about:blank", vimperator.NEW_TAB);
else
- openURLs("about:blank");
+ vimperator.open("about:blank");
/* commands = array where help information is located
* beg = string which is printed before the commmand/option/mapping name
@@ -214,7 +214,7 @@ vimperator.help = function(section, easter) //{{{
if (arguments[3] && arguments[3].recursive)
return false;
- openURLs("about:blank");
+ vimperator.open("about:blank");
setTimeout(function () { vimperator.help(section, false, null, {recursive: true}); }, 250);
return;
}
diff --git a/chrome/content/vimperator/hints.js b/chrome/content/vimperator/hints.js
index a0265f0e..6f8b341a 100644
--- a/chrome/content/vimperator/hints.js
+++ b/chrome/content/vimperator/hints.js
@@ -101,16 +101,17 @@ function Hints() //{{{
function genElemCoords(elem)
{
// NOTE: experiment for making the function faster, report problems
- try {
- var box = window.content.document.getBoxObjectFor(elem);
- elem.absoLeft = box.x;
- elem.absoTop = box.y;
- elem.validCoord = elem.ownerDocument.validCoords;
- } catch(e) {
- elem.absoLeft = 0;
- elem.absoTop = 0;
- }
- return;
+ // -> does not work on www.orf.at with frames
+ // try {
+ // var box = window.content.document.getBoxObjectFor(elem);
+ // elem.absoLeft = box.x;
+ // elem.absoTop = box.y;
+ // elem.validCoord = elem.ownerDocument.validCoords;
+ // } catch(e) {
+ // elem.absoLeft = 0;
+ // elem.absoTop = 0;
+ // }
+ // return;
if (typeof(elem.validCoord) != "undefined")
{
if (elem.validCoord == elem.ownerDocument.validCoords)
diff --git a/chrome/content/vimperator/mappings.js b/chrome/content/vimperator/mappings.js
index 954d1dba..820222b3 100644
--- a/chrome/content/vimperator/mappings.js
+++ b/chrome/content/vimperator/mappings.js
@@ -369,7 +369,7 @@ function Mappings() //{{{
}
));
addDefaultMap(new Map(vimperator.modes.NORMAL, ["gH"],
- function(count) { openURLsInNewTab("", true); BrowserHome(); },
+ function(count) { vimperator.open("", vimperator.NEW_TAB); BrowserHome(); },
{
short_help: "Go home in a new tab",
help: "Opens the homepage in a new tab."
@@ -395,7 +395,7 @@ function Mappings() //{{{
}
));
addDefaultMap(new Map(vimperator.modes.NORMAL, ["gP"],
- function(count) { openURLsInNewTab(readFromClipboard(), false); },
+ function(count) { vimperator.open(readFromClipboard(), vimperator.NEW_BACKGROUND_TAB); },
{
short_help: "Open (put) a URL based on the current clipboard contents in a new buffer",
help: "Works like P, but inverts the 'activate' option."
@@ -478,14 +478,14 @@ function Mappings() //{{{
}
));
addDefaultMap(new Map(vimperator.modes.NORMAL, ["p", ""],
- function(count) { openURLs(readFromClipboard()); },
+ function(count) { vimperator.open(readFromClipboard()); },
{
short_help: "Open (put) a URL based on the current clipboard contents in the current buffer",
help: "You can also just select some non-URL text, and search for it with the default search engine or keyword (specified by the 'defsearch' option) with p."
}
));
addDefaultMap(new Map(vimperator.modes.NORMAL, ["P"],
- function(count) { openURLsInNewTab(readFromClipboard(), true); },
+ function(count) { vimperator.open(readFromClipboard(), vimperator.NEW_TAB); },
{
short_help: "Open (put) a URL based on the current clipboard contents in a new buffer",
help: "Works like p, but opens a new tab.
" +
@@ -735,7 +735,7 @@ function Mappings() //{{{
for (var i = 0; i < count - 1; i++)
gocmd += "../";
- openURLs(gocmd);
+ vimperator.open(gocmd);
},
{
short_help: "Go to parent directory",
@@ -744,7 +744,7 @@ function Mappings() //{{{
}
));
addDefaultMap(new Map(vimperator.modes.NORMAL, ["gU", ""],
- function(count) { openURLs("..."); },
+ function(count) { vimperator.open("..."); },
{
short_help: "Go to the root of the website",
help: "gU on http://www.example.com/dir1/dir2/file.htm opens http://www.example.com/.
" +
diff --git a/chrome/content/vimperator/ui.js b/chrome/content/vimperator/ui.js
index bc6b926a..a97dca87 100644
--- a/chrome/content/vimperator/ui.js
+++ b/chrome/content/vimperator/ui.js
@@ -772,9 +772,9 @@ function InformationList(id, options) //{{{
var index = (widget.selectedIndex * 2) + 0;
var val = listcells[index].getAttribute("label");
if (val && event.button == 0 && event.type == "dblclick") // left double click
- openURLs(val);
+ vimperator.open(val);
else if (val && event.button == 1) // middle click
- openURLsInNewTab(val);
+ vimperator.open(val, vimperator.NEW_TAB);
else
return false;
}
diff --git a/chrome/content/vimperator/vimperator.js b/chrome/content/vimperator/vimperator.js
index f21ee0a6..c4877f73 100644
--- a/chrome/content/vimperator/vimperator.js
+++ b/chrome/content/vimperator/vimperator.js
@@ -111,6 +111,13 @@ const vimperator = (function() //{{{
modes: modes,
+ //openflags: { // XXX: maybe move these consts in a subnamespace?
+ CURRENT_TAB: 1,
+ NEW_TAB: 2,
+ NEW_BACKGROUND_TAB: 3,
+ //},
+
+ // ###VERSION### and ###DATE### are replaced by the Makefile
version: "###VERSION### CVS (created: ###DATE###)",
input: {
@@ -242,6 +249,53 @@ const vimperator = (function() //{{{
this.log(string, level);
},
+ // open one or more URLs
+ //
+ // @param urls: either a string or an array of urls
+ // @param where: if ommited, CURRENT_TAB is assumed
+ // @param callback: not implmented, will be allowed to specifiy a callback function
+ // which is called, when the page finished loading
+ // @returns true when load was initiated, or false on error
+ open: function(urls, where, callback)
+ {
+ // convert the string to an array of converted URLs
+ // -> see String.prototype.toURLArray for more details
+ if (typeof urls == "string")
+ urls = urls.toURLArray();
+
+ if (urls.length == 0)
+ return false;
+
+ if (!where)
+ where = vimperator.CURRENT_TAB;
+
+ // decide where to load the first tab
+ if (where == vimperator.CURRENT_TAB)
+ getBrowser().loadURI(urls[0]);
+ else if (where == vimperator.NEW_TAB)
+ {
+ var firsttab = getBrowser().addTab(urls[0]);
+ getBrowser().selectedTab = firsttab;
+ }
+ else if (where == vimperator.NEW_BACKGROUND_TAB)
+ {
+ getBrowser().addTab(urls[0]);
+ }
+ else
+ {
+ vimperator.echoerr("Exxx: Invalid where directive in vimperator.open(...)");
+ return false;
+ }
+
+ // all other URLs are always loaded in background
+ for (var url=1; url < urls.length; url++)
+ getBrowser().addTab(urls[url]);
+
+ // TODO: register callbacks
+
+ return true;
+ },
+
// quit vimperator, no matter how many tabs/windows are open
quit: function(save_session)
{
@@ -471,11 +525,6 @@ const vimperator = (function() //{{{
vimperator.registerCallback("submit", vimperator.modes.EX, function(command) { /*vimperator.*/execute(command); } );
vimperator.registerCallback("complete", vimperator.modes.EX, function(str) { return exTabCompletion(str); } );
- // this function adds all our required listeners to react on events
- // also stuff like window.onScroll is handled there.
- //addEventListeners();
- //vimperator.events();
-
// work around firefox popup blocker
popup_allowed_events = Options.getFirefoxPref('dom.popup_allowed_events', 'change click dblclick mouseup reset submit');
if (!popup_allowed_events.match("keypress"))