diff --git a/content/bookmarks.js b/content/bookmarks.js index bd9661ad..2a2bf3fd 100644 --- a/content/bookmarks.js +++ b/content/bookmarks.js @@ -235,7 +235,7 @@ function Bookmarks() //{{{ "string", "google", { completer: function completer(context) completion.search(context, true), - validator: options.validateCompleter + validator: Option.validateCompleter }); options.add(["preload"], @@ -270,7 +270,7 @@ function Bookmarks() //{{{ "Show jumplist", function () { - var sh = getWebNavigation().sessionHistory; + var sh = window.getWebNavigation().sessionHistory; let entries = [sh.getEntryAtIndex(i, false) for (i in util.range(0, sh.count))]; let list = template.jumps(sh.index, entries); @@ -516,8 +516,8 @@ function Bookmarks() //{{{ function process(resp) { - let json = Components.classes["@mozilla.org/dom/json;1"] - .createInstance(Components.interfaces.nsIJSON); + const json = Components.classes["@mozilla.org/dom/json;1"] + .createInstance(Components.interfaces.nsIJSON); let results = []; try { @@ -557,7 +557,7 @@ function Bookmarks() //{{{ // did not :open once before this.getSearchEngines(); - url = getShortcutOrURI(searchString, aPostDataRef); + url = window.getShortcutOrURI(searchString, aPostDataRef); if (url == searchString) url = null; @@ -642,12 +642,12 @@ function History() //{{{ { if (args) { - var sh = getWebNavigation().sessionHistory; + var sh = window.getWebNavigation().sessionHistory; for (let i = sh.index - 1; i >= 0; i--) { if (sh.getEntryAtIndex(i, false).URI.spec == args) { - getWebNavigation().gotoIndex(i); + window.getWebNavigation().gotoIndex(i); return; } } @@ -664,7 +664,7 @@ function History() //{{{ completer: function completer(context) { let filter = context.filter; - var sh = getWebNavigation().sessionHistory; + var sh = window.getWebNavigation().sessionHistory; var completions = []; for (let i in util.range(sh.index, 0, true)) { @@ -694,12 +694,12 @@ function History() //{{{ { if (args) { - var sh = getWebNavigation().sessionHistory; + var sh = window.getWebNavigation().sessionHistory; for (let i in util.range(sh.index + 1, sh.count)) { if (sh.getEntryAtIndex(i, false).URI.spec == args) { - getWebNavigation().gotoIndex(i); + window.getWebNavigation().gotoIndex(i); return; } } @@ -716,7 +716,7 @@ function History() //{{{ completer: function completer(context) { let filter = context.filter; - var sh = getWebNavigation().sessionHistory; + var sh = window.getWebNavigation().sessionHistory; var completions = []; for (let i in util.range(sh.index + 1, sh.count)) { @@ -786,29 +786,29 @@ function History() //{{{ // TODO: better names and move to buffer.? stepTo: function stepTo(steps) { - let index = getWebNavigation().sessionHistory.index + steps; - if (index >= 0 && index < getWebNavigation().sessionHistory.count) - getWebNavigation().gotoIndex(index); + let index = window.getWebNavigation().sessionHistory.index + steps; + if (index >= 0 && index < window.getWebNavigation().sessionHistory.count) + window.getWebNavigation().gotoIndex(index); else liberator.beep(); }, goToStart: function goToStart() { - let index = getWebNavigation().sessionHistory.index; + let index = window.getWebNavigation().sessionHistory.index; if (index == 0) return liberator.beep(); // really wanted? - getWebNavigation().gotoIndex(0); + window.getWebNavigation().gotoIndex(0); }, goToEnd: function goToEnd() { - let index = getWebNavigation().sessionHistory.index; - if (index == getWebNavigation().sessionHistory.count - 1) + let index = window.getWebNavigation().sessionHistory.index; + if (index == window.getWebNavigation().sessionHistory.count - 1) return liberator.beep(); - getWebNavigation().gotoIndex(max); + window.getWebNavigation().gotoIndex(max); }, // if openItems is true, open the matching history items in tabs rather than display diff --git a/content/buffer.js b/content/buffer.js index 1dac2c43..ff8c4118 100644 --- a/content/buffer.js +++ b/content/buffer.js @@ -146,7 +146,10 @@ function Buffer() //{{{ "stringlist", "\\bprev|previous\\b,^<$,^(<<|«)$,^(<|«),(<|«)$"); options.add(["pageinfo", "pa"], "Desired info on :pa[geinfo]", "charlist", "gfm", - { completer: function (filter) [[k, v[1]] for ([k, v] in Iterator(pageInfo))] }); + { + completer: function (filter) [[k, v[1]] for ([k, v] in Iterator(pageInfo))], + validator: Option.validateCompleter + }); options.add(["scroll", "scr"], "Number of lines to scroll with and commands", @@ -162,7 +165,7 @@ function Buffer() //{{{ ["1", "Show the link in the status line"], ["2", "Show the link in the command line"] ], - validator: options.validateCompleter + validator: Option.validateCompleter }); options.add(["usermode", "um"], @@ -173,7 +176,7 @@ function Buffer() //{{{ { try { - getMarkupDocumentViewer().authorStyleDisabled = value; + window.getMarkupDocumentViewer().authorStyleDisabled = value; } catch (e) {} @@ -183,7 +186,7 @@ function Buffer() //{{{ { try { - return getMarkupDocumentViewer().authorStyleDisabled; + return window.getMarkupDocumentViewer().authorStyleDisabled; } catch (e) {} } @@ -217,7 +220,7 @@ function Buffer() //{{{ mappings.add(myModes, [""], "Stop loading", - function () { BrowserStop(); }); + function () { window.BrowserStop(); }); // scrolling mappings.add(myModes, ["j", "", ""], @@ -517,7 +520,7 @@ function Buffer() //{{{ if (options["usermode"]) options["usermode"] = false; - stylesheetSwitchAll(window.content, args); + window.stylesheetSwitchAll(window.content, args); }, { completer: function (context) completion.alternateStylesheet(context), @@ -567,9 +570,9 @@ function Buffer() //{{{ .getDocumentMetadata("content-disposition"); } catch (e) {} - internalSave(doc.location.href, doc, null, contentDisposition, + window.internalSave(doc.location.href, doc, null, contentDisposition, doc.contentType, false, null, chosenData, doc.referrer ? - makeURI(doc.referrer) : null, true); + window.makeURI(doc.referrer) : null, true); }, { argCount: "?", @@ -579,7 +582,7 @@ function Buffer() //{{{ commands.add(["st[op]"], "Stop loading", - function () { BrowserStop(); }, + function () { window.BrowserStop(); }, { argCount: "0" }); commands.add(["vie[wsource]"], @@ -671,7 +674,7 @@ function Buffer() //{{{ { try { - urlSecurityCheck(data.href, principal, + window.urlSecurityCheck(data.href, principal, Components.interfaces.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL); } catch (e) @@ -793,7 +796,7 @@ function Buffer() //{{{ get alternateStyleSheets() { - var stylesheets = getAllStyleSheets(window.content); + var stylesheets = window.getAllStyleSheets(window.content); return stylesheets.filter( function (stylesheet) /^(screen|all|)$/i.test(stylesheet.media.mediaText) && !/^\s*$/.test(stylesheet.title) @@ -1106,15 +1109,15 @@ function Buffer() //{{{ saveLink: function (elem, skipPrompt) { var doc = elem.ownerDocument; - var url = makeURLAbsolute(elem.baseURI, elem.href); + var url = window.makeURLAbsolute(elem.baseURI, elem.href); var text = elem.textContent; try { - urlSecurityCheck(url, doc.nodePrincipal); + window.urlSecurityCheck(url, doc.nodePrincipal); // we always want to save that link relative to the current working directory options.setPref("browser.download.lastDir", io.getCurrentDirectory().path); - saveURL(url, text, null, true, skipPrompt, makeURI(url, doc.characterSet)); + window.saveURL(url, text, null, true, skipPrompt, makeURI(url, doc.characterSet)); } catch (e) { diff --git a/content/commands.js b/content/commands.js index 7dbd97c6..f5fff23a 100644 --- a/content/commands.js +++ b/content/commands.js @@ -635,7 +635,7 @@ function Commands() //{{{ // check for correct number of arguments if (args.length == 0 && /^[1+]$/.test(argCount) || - literal != null && /[+?]/.test(argCount) && !/\S/.test(args.literalArg || "")) + literal != null && /[1+]/.test(argCount) && !/\S/.test(args.literalArg || "")) { if (!complete) { diff --git a/content/completion.js b/content/completion.js index d31adbd9..1840faa4 100644 --- a/content/completion.js +++ b/content/completion.js @@ -109,7 +109,7 @@ function CompletionContext(editor, name, offset) this.message = null; this.name = name || ""; this._completions = []; // FIXME - this.getKey = function (item, key) (typeof self.keys[key] == "function") ? self.keys[key].call(this, item) : + this.getKey = function (item, key) (typeof self.keys[key] == "function") ? self.keys[key].call(this, item.item) : key in self.keys ? item.item[self.keys[key]] : item.item[key]; } @@ -225,17 +225,36 @@ CompletionContext.prototype = { { this.hasItems = true; this._generate = arg; + liberator.dump(this.name + ": set generate()"); if (this.background && this.regenerate) { + //**/ this.__i = (this.__i || 0) + 1; + //**/ let self = this; + //**/ function dump(msg) liberator.callInMainThread(function () liberator.dump(self.name + ":" + self.__i + ": " + msg)); + //**/ dump("set generate() regenerating"); let lock = {}; this.cache.backgroundLock = lock; this.incomplete = true; - liberator.callAsync(this, function () { - let items = this.generate(); + let thread = this.getCache("backgroundThread", liberator.newThread); + //**/ dump(thread); + liberator.callAsync(thread, this, function () { + //**/ dump("In async"); if (this.cache.backgroundLock != lock) + { + //**/ dump("Lock !ok"); return; + } + let items = this.generate(); + //**/ dump("Generated"); + if (this.cache.backgroundLock != lock) + { + //**/ dump("Lock !ok"); + return; + } this.incomplete = false; + //**/ dump("completions="); this.completions = items; + //**/ dump("completions=="); }); } }, @@ -907,9 +926,9 @@ function Completion() //{{{ let compare = context.compare; context.compare = function (a, b) { - if (!isNaN(a.key) && !isNaN(b.key)) - return a.key - b.key; - return isNaN(b.key) - isNaN(a.key) || compare(a, b); + if (!isNaN(a.item.key) && !isNaN(b.item.key)) + return a.item.key - b.item.key; + return isNaN(b.item.key) - isNaN(a.item.key) || compare(a, b); } if (!context.anchored) // We've already listed anchored matches, so don't list them again here. context.filters.push(function (item) util.compareIgnoreCase(item.text.substr(0, this.filter.length), this.filter)); @@ -1457,7 +1476,7 @@ function Completion() //{{{ let prefs = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefBranch); context.title = ["Firefox Preference", "Value"]; - context.keys = { text: function (item) item.item, description: function (item) options.getPref(item.item) }; + context.keys = { text: function (item) item, description: function (item) options.getPref(item) }; context.completions = prefs.getChildList("", { value: 0 }); }, diff --git a/content/events.js b/content/events.js index 1b69d52e..a5cecd83 100644 --- a/content/events.js +++ b/content/events.js @@ -49,7 +49,7 @@ function AutoCommands() //{{{ "stringlist", "", { completer: function () config.autocommands.concat([["all", "All events"]]), - validator: options.validateCompleter + validator: Option.validateCompleter }); options.add(["focuscontent", "fc"], @@ -808,7 +808,7 @@ function Events() //{{{ // make sure the page is stopped before starting to play the macro try { - getWebNavigation().stop(nsIWebNavigation.STOP_ALL); + window.getWebNavigation().stop(nsIWebNavigation.STOP_ALL); } catch (e) {} @@ -1321,13 +1321,13 @@ function Events() //{{{ // { // //alert(command_line.value.substring(0, command_line.selectionStart)); // command_line.value = command_line.value.substring(0, command_line.selectionStart) + - // readFromClipboard() + + // window.readFromClipboard() + // command_line.value.substring(command_line.selectionEnd, command_line.value.length); // alert(command_line.value); // } // //else // // { - // // openURLs(readFromClipboard()); + // // openURLs(window.readFromClipboard()); // // } // return true; // } }}} diff --git a/content/hints.js b/content/hints.js index f6813a5b..c1f18eb1 100644 --- a/content/hints.js +++ b/content/hints.js @@ -328,15 +328,15 @@ function Hints() //{{{ if (!followFirst) return false; // no return hit; don't examine uniqueness - // OK. return hit. But there's more than one hint. And + // OK. return hit. But there's more than one hint, and // there's no tab-selected current link. Do not follow in mode 2 - if ((options["followhints"] == 2) && validHints.length > 1 && !hintNumber) + if (options["followhints"] == 2 && validHints.length > 1 && !hintNumber) return liberator.beep(); } if (!followFirst) { - var firstHref = validHints[0].getAttribute("href") || null; + let firstHref = validHints[0].getAttribute("href") || null; if (firstHref) { if (validHints.some(function (e) e.getAttribute("href") != firstHref)) @@ -551,7 +551,7 @@ function Hints() //{{{ "string", DEFAULT_HINTTAGS); options.add(["hinttimeout", "hto"], - "Automatically follow non unique numerical hint", + "Timeout before automatically following a non-unique numerical hint", "number", 0, { validator: function (value) value >= 0 }); @@ -560,7 +560,14 @@ function Hints() //{{{ // better one right now. "Change the behaviour of in hint mode", "number", 0, - { validator: function (value) value >= 0 && value < 3 }); + { + completer: function () [ + ["0", "Follow the first hint as soon as typed text uniquely identifies it. Follow the selected hint on [m][m]."], + ["1", "Follow the selected hint on [m][m]."], + ["2", "Follow the selected hint on [m][m] only it's been [m][m]-selected."] + ], + validator: function (value) Option.validateCompleter + }); options.add(["hintmatching", "hm"], "How links are matched", @@ -570,7 +577,7 @@ function Hints() //{{{ { return [[m, ""] for each (m in ["contains", "wordstartswith", "firstletters", "custom"])]; }, - validator: options.validateCompleter + validator: Option.validateCompleter }); options.add(["wordseparators", "wsp"], diff --git a/content/liberator.js b/content/liberator.js index 56868f43..de8932f2 100644 --- a/content/liberator.js +++ b/content/liberator.js @@ -76,7 +76,7 @@ const liberator = (function () //{{{ } catch (e) { - toJavaScriptConsole(); + window.toJavaScriptConsole(); liberator.reportError(e); } } @@ -135,7 +135,7 @@ const liberator = (function () //{{{ ["b", "Bookmark bar"] ].concat(!liberator.has("tabs") ? [] : tabopts); }, - validator: options.validateCompleter + validator: Option.validateCompleter }); options.add(["helpfile", "hf"], @@ -648,17 +648,18 @@ const liberator = (function () //{{{ return false; // so you can do: if (...) return liberator.beep(); }, - callAsync: function (self, func) + newThread: function () threadManager.newThread(0), + + callAsync: function (thread, self, func) { - let thread = threadManager.newThread(0); + hread = thread || threadManager.newThread(0); thread.dispatch(new Runnable(self, func, Array.slice(arguments, 2)), thread.DISPATCH_NORMAL); }, // be sure to call GUI related methods like alert() or dump() ONLY in the main thread callFunctionInThread: function (thread, func) { - if (!thread) - thread = threadManager.newThread(0); + thread = thread || threadManager.newThread(0); // DISPATCH_SYNC is necessary, otherwise strange things will happen thread.dispatch(new Runnable(null, func, Array.slice(arguments, 2)), thread.DISPATCH_SYNC); @@ -1026,54 +1027,54 @@ const liberator = (function () //{{{ if (urls.length == 0) return false; - if (liberator.forceNewTab && liberator.has("tabs")) - where = liberator.NEW_TAB; - else if (!where || !liberator.has("tabs")) - where = liberator.CURRENT_TAB; - - var url = typeof urls[0] == "string" ? urls[0] : urls[0][0]; - var postdata = typeof urls[0] == "string" ? null : urls[0][1]; - var whichwindow = window; - - // decide where to load the first url - switch (where) + function open(urls, where) { - case liberator.CURRENT_TAB: - getBrowser().loadURIWithFlags(url, null, null, null, postdata); - break; + let url = Array.concat(urls)[0]; + let postdata = Array.concat(urls)[1]; + let whichwindow = window; - case liberator.NEW_TAB: - var firsttab = getBrowser().addTab(url, null, null, postdata); - getBrowser().selectedTab = firsttab; - break; + // decide where to load the first url + switch (where) + { + case liberator.CURRENT_TAB: + getBrowser().loadURIWithFlags(url, null, null, null, postdata); + break; - case liberator.NEW_BACKGROUND_TAB: - getBrowser().addTab(url, null, null, postdata); - break; + case liberator.NEW_BACKGROUND_TAB: + case liberator.NEW_TAB: + if (!liberator.has("tabs")) + open(urls, liberator.NEW_WINDOW); - case liberator.NEW_WINDOW: - window.open(); - var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] - .getService(Components.interfaces.nsIWindowMediator); - whichwindow = wm.getMostRecentWindow("navigator:browser"); - whichwindow.loadURI(url, null, postdata); - break; + let tab = getBrowser().addTab(url, null, null, postdata); + if (where == liberator.NEW_TAB) + getBrowser().selectedTab = tab; + break; - default: - liberator.echoerr("Exxx: Invalid 'where' directive in liberator.open(...)"); - return false; + case liberator.NEW_WINDOW: + const wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] + .getService(Components.interfaces.nsIWindowMediator); + window.open(); + whichwindow = wm.getMostRecentWindow("navigator:browser"); + whichwindow.loadURI(url, null, postdata); + break; + + default: + liberator.echoerr("Exxx: Invalid 'where' directive in liberator.open(...)"); + return false; + } } - // only load more than one url if we have tab support - if (!liberator.has("tabs")) - return true; + if (liberator.forceNewTab) + where = liberator.NEW_TAB; + else if (!where) + where = liberator.CURRENT_TAB; - // all other URLs are always loaded in background - for (let i = 1; i < urls.length; i++) + for (let [i, url] in Iterator(urls)) { - url = typeof urls[i] == "string" ? urls[i] : urls[i][0]; - postdata = typeof urls[i] == "string" ? null : urls[i][1]; - whichwindow.getBrowser().addTab(url, null, null, postdata); + open(url, where); + if (i == 0 && !liberator.has("tabs")) + break; + where = liberator.NEW_BACKGROUND_TAB; } return true; @@ -1101,7 +1102,7 @@ const liberator = (function () //{{{ .getService(nsIAppStartup) .quit(nsIAppStartup.eForceQuit); else - goQuitApplication(); + window.goQuitApplication(); }, reportError: function (error) diff --git a/content/mail.js b/content/mail.js index 4c82b831..31886166 100644 --- a/content/mail.js +++ b/content/mail.js @@ -218,7 +218,7 @@ function Mail() //{{{ return value; }, - validator: options.validateCompleter + validator: Option.validateCompleter }); /*options.add(["threads"], @@ -271,7 +271,7 @@ function Mail() //{{{ mappings.add(myModes, ["d", ""], "Move mail to Trash folder", - function () { goDoCommand("cmd_delete"); }); + function () { window.goDoCommand("cmd_delete"); }); mappings.add(myModes, ["j", ""], "Select next message", @@ -351,19 +351,19 @@ function Mail() //{{{ mappings.add(myModes, ["r"], "Reply to sender", - function () { goDoCommand("cmd_reply"); }); + function () { window.goDoCommand("cmd_reply"); }); mappings.add(myModes, ["R"], "Reply to all", - function () { goDoCommand("cmd_replyall"); }); + function () { window.goDoCommand("cmd_replyall"); }); mappings.add(myModes, ["f"], "Forward message", - function () { goDoCommand("cmd_forward"); }); + function () { window.goDoCommand("cmd_forward"); }); mappings.add(myModes, ["F"], "Forward message inline", - function () { goDoCommand("cmd_forwardInline"); }); + function () { window.goDoCommand("cmd_forwardInline"); }); // SCROLLING mappings.add(myModes, [""], @@ -526,11 +526,11 @@ function Mail() //{{{ mappings.add(myModes, ["zr", "zR"], "Expand all threads", - function () { goDoCommand("cmd_expandAllThreads"); }); + function () { window.goDoCommand("cmd_expandAllThreads"); }); mappings.add(myModes, ["zm", "zM"], "Collapse all threads", - function () { goDoCommand("cmd_collapseAllThreads"); }); + function () { window.goDoCommand("cmd_collapseAllThreads"); }); mappings.add(myModes, [""], "Go forward", @@ -728,7 +728,7 @@ function Mail() //{{{ commands.add(["empty[trash]"], "Empty trash of the current account", - function () { goDoCommand("cmd_emptyTrash"); }, + function () { window.goDoCommand("cmd_emptyTrash"); }, { argCount: "0" }); commands.add(["get[messages]"], diff --git a/content/mappings.js b/content/mappings.js index a21bb0e1..b10c4e42 100644 --- a/content/mappings.js +++ b/content/mappings.js @@ -298,7 +298,7 @@ function Mappings() //{{{ addUserMap: function (modes, keys, description, action, extra) { - keys = keys.map(function (key) expandLeader(key)); + keys = keys.map(expandLeader); var map = new Map(modes, keys, description || "User defined mapping", action, extra); // remove all old mappings to this key sequence diff --git a/content/muttator.js b/content/muttator.js index 45aa4c7c..d45de75e 100644 --- a/content/muttator.js +++ b/content/muttator.js @@ -53,23 +53,23 @@ const config = { //{{{ dialogs: [ ["about", "About Thunderbird", - function () { openAboutDialog(); }], + function () { window.openAboutDialog(); }], ["addons", "Manage Add-ons", - function () { openAddonsMgr(); }], + function () { window.openAddonsMgr(); }], ["addressbook", "Address book", - function () { toAddressBook(); }], + function () { window.toAddressBook(); }], ["checkupdates", "Check for updates", - function () { checkForUpdates(); }], + function () { window.checkForUpdates(); }], /*["cleardata", "Clear private data", function () { Components.classes[GLUE_CID].getService(Components.interfaces.nsIBrowserGlue).sanitize(window || null); }],*/ ["console", "JavaScript console", - function () { toJavaScriptConsole(); }], + function () { window.toJavaScriptConsole(); }], /*["customizetoolbar", "Customize the Toolbar", function () { BrowserCustomizeToolbar(); }],*/ ["dominspector", "DOM Inspector", - function () { inspectDOMDocument(content.document); }], + function () { window.inspectDOMDocument(content.document); }], ["downloads", "Manage Downloads", - function () { toOpenWindowByType('Download:Manager', 'chrome://mozapps/content/downloads/downloads.xul', 'chrome,dialog=no,resizable'); }], + function () { window.toOpenWindowByType('Download:Manager', 'chrome://mozapps/content/downloads/downloads.xul', 'chrome,dialog=no,resizable'); }], /*["import", "Import Preferences, Bookmarks, History, etc. from other browsers", function () { BrowserImport(); }], ["openfile", "Open the file selector dialog", @@ -87,9 +87,9 @@ const config = { //{{{ ["print", "Show print dialog", function () { PrintUtils.print(); }], ["saveframe", "Save frame to disk", - function () { saveFrameDocument(); }], + function () { window.saveFrameDocument(); }], ["savepage", "Save page to disk", - function () { saveDocument(window.content.document); }], + function () { window.saveDocument(window.content.document); }], /*["searchengines", "Manage installed search engines", function () { openDialog("chrome://browser/content/search/engineManager.xul", "_blank", "chrome,dialog,modal,centerscreen"); }], ["selectionsource", "View selection source", @@ -135,11 +135,11 @@ const config = { //{{{ mappings.add([modes.COMPOSE], ["y"], "Send message now", - function () { goDoCommand("cmd_sendNow"); }); + function () { window.goDoCommand("cmd_sendNow"); }); mappings.add([modes.COMPOSE], ["Y"], "Send message later", - function () { goDoCommand("cmd_sendLater"); }); + function () { window.goDoCommand("cmd_sendLater"); }); // FIXME: does not really work reliably mappings.add([modes.COMPOSE], diff --git a/content/options.js b/content/options.js index e0c60208..06c180b0 100644 --- a/content/options.js +++ b/content/options.js @@ -281,6 +281,16 @@ Option.prototype = { return "E474: Invalid argument: " + values; this.setValues(newValue, scope); } +}; + // TODO: Run this by default? +Option.validateCompleter = function (values) +{ + let context = CompletionContext(""); + let res = this.completer(context); + if (!res) + res = context.allItems.map(function (item) [item.text]); + return Array.concat(values).every( + function (value) res.some(function (item) item[0] == value)); }; //}}} function Options() //{{{ @@ -504,7 +514,7 @@ function Options() //{{{ } else { - openPreferences(); + window.openPreferences(); } }, { @@ -942,17 +952,6 @@ function Options() //{{{ return ret; }, - // TODO: Run this by default? - validateCompleter: function (values) - { - let context = CompletionContext(""); - let res = this.completer(context); - if (!res) - res = context.allItems.map(function (item) [item.text]); - return Array.concat(values).every( - function (value) res.some(function (item) item[0] == value)); - }, - get store() storage.options, getPref: function (name, forcedDefault) diff --git a/content/tabs.js b/content/tabs.js index 1bfd1b4e..c3e8db8a 100644 --- a/content/tabs.js +++ b/content/tabs.js @@ -130,14 +130,12 @@ function Tabs() //{{{ { tabStrip.collapsed = true; } - else if (value == 1) - { - options.setPref("browser.tabStrip.autoHide", true); - tabStrip.collapsed = false; - } else { - options.setPref("browser.tabStrip.autoHide", false); + let pref = "browser.tabStrip.autoHide"; + if (options.getPref(pref) == null) + pref = "browser.tabs.autoHide"; + options.setPref(pref, value == 1); tabStrip.collapsed = false; } @@ -151,7 +149,7 @@ function Tabs() //{{{ ["2", "Always show tab bar"] ]; }, - validator: options.validateCompleter + validator: Option.validateCompleter }); if (config.name == "Vimperator") @@ -169,7 +167,7 @@ function Tabs() //{{{ ["paste", "P and gP mappings"] ]; }, - validator: options.validateCompleter + validator: Option.validateCompleter }); options.add(["newtab"], @@ -187,7 +185,7 @@ function Tabs() //{{{ ["prefs", ":pref[erences]! or :prefs! command"] ]; }, - validator: options.validateCompleter + validator: Option.validateCompleter }); options.add(["popups", "pps"], @@ -217,7 +215,7 @@ function Tabs() //{{{ ["4", "Open in the same tab unless it has a specific requested size"] ]; }, - validator: options.validateCompleter + validator: Option.validateCompleter }); // TODO: Add option, or only apply when go~=[nN] styles.addSheet("tab-binding", "chrome://browser/content/browser.xul", @@ -361,7 +359,7 @@ function Tabs() //{{{ }, { argCount: "+", - completer: function (context) completion.ex(context.filter), + completer: function (context) completion.ex(context), literal: 0 }); @@ -583,53 +581,37 @@ function Tabs() //{{{ function (args) { let count = args.count; - args = args.string; + args = args[0] if (count < 1) count = 1; if (args) { - let ss = Components.classes["@mozilla.org/browser/sessionstore;1"] - .getService(Components.interfaces.nsISessionStore); - let undoItems = eval("(" + ss.getClosedTabData(window) + ")"); - let found = false; - - for (let i = 0; i < undoItems.length; i++) + count = 0; + for (let [i, item] in Iterator(tabs.closedTabs)) { - if (undoItems[i].state.entries[0].url == args) + if (item.state.entries[0].url == args) { count = i + 1; - found = true; break; } } - if (!found) + if (!count) { liberator.echoerr("Exxx: No matching closed tab"); return; } } - undoCloseTab(count - 1); + window.undoCloseTab(count - 1); }, { completer: function (context) { - // get closed-tabs from nsSessionStore - var ss = Components.classes["@mozilla.org/browser/sessionstore;1"] - .getService(Components.interfaces.nsISessionStore); - var undoItems = eval("(" + ss.getClosedTabData(window) + ")"); - var completions = []; - for (let i = 0; i < undoItems.length; i++) - { - var url = undoItems[i].state.entries[0].url; - var title = undoItems[i].title; - if (completion.match([url, title], context.filter, false)) - completions.push([url, title]); - } - return [0, completions]; + context.keys = { text: function (item) item.state.entries[0].url, description: "title" }; + context.completions = tabs.closedTabs; }, count: true, literal: 0 @@ -639,12 +621,8 @@ function Tabs() //{{{ "Undo closing of all closed tabs", function (args) { - let ss = Components.classes["@mozilla.org/browser/sessionstore;1"] - .getService(Components.interfaces.nsISessionStore); - let undoItems = eval("(" + ss.getClosedTabData(window) + ")"); - - for (let i = 0; i < undoItems.length; i++) - undoCloseTab(); // doesn't work with i as the index to undoCloseTab + for (let i in Itarator(tabs.closedTabs)) + window.undoCloseTab(0); }, { argCount: "0" }); @@ -739,6 +717,15 @@ function Tabs() //{{{ return getBrowser().mTabContainer.selectedItem; }, + get closedTabs() + { + const json = Components.classes["@mozilla.org/dom/json;1"] + .createInstance(Components.interfaces.nsIJSON); + const ss = Components.classes["@mozilla.org/browser/sessionstore;1"] + .getService(Components.interfaces.nsISessionStore); + return json.decode(ss.getClosedTabData(window)); + }, + list: function (filter) { completion.listCompleter("buffer", filter); @@ -764,7 +751,7 @@ function Tabs() //{{{ else { if (buffer.URL != "about:blank" || - getWebNavigation().sessionHistory.count > 0) + window.getWebNavigation().sessionHistory.count > 0) { liberator.open("about:blank", liberator.NEW_BACKGROUND_TAB); getBrowser().removeTab(tab); diff --git a/content/ui.js b/content/ui.js index ebdaf4fb..f5cf01ae 100644 --- a/content/ui.js +++ b/content/ui.js @@ -480,7 +480,7 @@ function CommandLine() //{{{ return engines.map(function (engine) [engine.alias, engine.description]); }, - validator: options.validateCompleter + validator: Option.validateCompleter }); // TODO: these belong in ui.js @@ -489,7 +489,7 @@ function CommandLine() //{{{ "charlist", "sfl", { completer: function completer(filter) [k for each (k in completion.urlCompleters)], - validator: options.validateCompleter + validator: Option.validateCompleter }); options.add(["wildcase", "wic"], @@ -501,7 +501,7 @@ function CommandLine() //{{{ ["match", "Case is always significant"], ["ignore", "Case is never significant"] ], - validator: options.validateCompleter + validator: Option.validateCompleter }); options.add(["wildignore", "wig"], @@ -538,7 +538,7 @@ function CommandLine() //{{{ ["list:longest", "List all and complete common string"] ]; }, - validator: options.validateCompleter, + validator: Option.validateCompleter, checkHas: function (value, val) { let [first, second] = value.split(":", 2); @@ -557,7 +557,7 @@ function CommandLine() //{{{ ["sort", "Always sort the completion list"] ]; }, - validator: options.validateCompleter + validator: Option.validateCompleter }); /////////////////////////////////////////////////////////////////////////////}}} @@ -1422,7 +1422,7 @@ function ItemList(id) //{{{ let haveCompletions = false; let off = 0; - let end = endIndex; + let end = startIndex + maxItems; function getRows(context) { function fix(n) Math.max(0, Math.min(len, n)); @@ -1430,7 +1430,9 @@ function ItemList(id) //{{{ let len = context.items.length; let start = off; off += len; - return [fix(offset - start), fix(endIndex - start)]; + let res = [fix(offset - start), fix(end - start)]; + res[2] = (context.incomplete && res[1] >= offset && off - 1 < end); + return res; } items.contextList.forEach(function fill_eachContext(context) { @@ -1439,17 +1441,17 @@ function ItemList(id) //{{{ return; haveCompletions = true; + let root = nodes.root + let items = nodes.items; + let [start, end, waiting] = getRows(context); + if (context.message) nodes.message.textContent = context.message; nodes.message.style.display = context.message ? "block" : "none"; - nodes.waiting.style.display = context.incomplete ? "block" : "none"; + nodes.waiting.style.display = waiting ? "block" : "none"; nodes.up.style.opacity = "0"; nodes.down.style.display = "none"; - let root = nodes.root - let items = nodes.items; - let [start, end] = getRows(context); - for (let [i, row] in Iterator(context.getRows(start, end, doc))) nodes[i] = row; for (let [i, row] in util.Array.iterator2(nodes)) @@ -1616,7 +1618,7 @@ function StatusLine() //{{{ ["2", "Always display status line"] ]; }, - validator: options.validateCompleter + validator: Option.validateCompleter }); /////////////////////////////////////////////////////////////////////////////}}} @@ -1671,7 +1673,7 @@ function StatusLine() //{{{ // when session information is available, add [+] when we can go backwards if (config.name == "Vimperator") { - let sh = getWebNavigation().sessionHistory; + let sh = window.getWebNavigation().sessionHistory; let modified = ""; if (sh.index > 0) modified += "+"; diff --git a/content/util.js b/content/util.js index d7918fe8..484468c1 100644 --- a/content/util.js +++ b/content/util.js @@ -465,30 +465,26 @@ const util = { //{{{ { let urls = str.split(new RegExp("\s*" + options["urlseparator"] + "\s*")); - for (let url = 0; url < urls.length; url++) - { + return urls.map(function (url) { try { - let file = io.getFile(urls[url]); + let file = io.getFile(url); if (file.exists() && file.isReadable()) - { - urls[url] = file.path; - continue; - } + return file.path; } catch (e) {} // removes spaces from the string if it starts with http:// or something like that - if (/^\w+:\/\//.test(urls[url])) - urls[url] = urls[url].replace(/\s+/g, ""); + if (/^\w+:\/\//.test(url)) + url = url.replace(/\s+/g, ""); // strip each 'URL' - makes things simpler later on - urls[url] = urls[url].replace(/^\s+/, "").replace(/\s+$/, ""); + url = url.replace(/^\s+|\s+$/, ""); // if the string doesn't look like a valid URL (i.e. contains a space // or does not contain any of: .:/) try opening it with a search engine // or keyword bookmark - if (/\s/.test(urls[url]) || !/[.:\/]/.test(urls[url])) + if (/\s/.test(url) || !/[.:\/]/.test(url)) { // TODO: it would be clearer if the appropriate call to // getSearchURL was made based on whether or not the first word was @@ -497,27 +493,22 @@ const util = { //{{{ // like the comments below ;-) // check for a search engine match in the string - let searchURL = bookmarks.getSearchURL(urls[url], false); + let searchURL = bookmarks.getSearchURL(url, false); if (searchURL) { - urls[url] = searchURL; - continue; + return searchURL; } else // no search engine match, search for the whole string in the default engine { - searchURL = bookmarks.getSearchURL(urls[url], true); + searchURL = bookmarks.getSearchURL(url, true); if (searchURL) - { - urls[url] = searchURL; - continue; - } + return searchURL; } } // if we are here let Firefox handle the url and hope it does // something useful with it :) - } - - return urls; + return url; + }); }, xmlToDom: function xmlToDom(node, doc, nodes) diff --git a/content/vimperator.js b/content/vimperator.js index c159b4c0..6a960cd4 100644 --- a/content/vimperator.js +++ b/content/vimperator.js @@ -54,41 +54,41 @@ const config = { //{{{ dialogs: [ ["about", "About Firefox", - function () { openDialog("chrome://browser/content/aboutDialog.xul", "_blank", "chrome,dialog,modal,centerscreen"); }], + function () { window.openDialog("chrome://browser/content/aboutDialog.xul", "_blank", "chrome,dialog,modal,centerscreen"); }], ["addbookmark", "Add bookmark for the current page", function () { PlacesCommandHook.bookmarkCurrentPage(true, PlacesUtils.bookmarksRootId); }], ["addons", "Manage Add-ons", - function () { BrowserOpenAddonsMgr(); }], + function () { window.BrowserOpenAddonsMgr(); }], ["bookmarks", "List your bookmarks", - function () { openDialog("chrome://browser/content/bookmarks/bookmarksPanel.xul", "Bookmarks", "dialog,centerscreen,width=600,height=600"); }], + function () { window.openDialog("chrome://browser/content/bookmarks/bookmarksPanel.xul", "Bookmarks", "dialog,centerscreen,width=600,height=600"); }], ["checkupdates", "Check for updates", - function () { checkForUpdates(); }], + function () { window.checkForUpdates(); }], ["cleardata", "Clear private data", function () { Components.classes[GLUE_CID].getService(Components.interfaces.nsIBrowserGlue).sanitize(window || null); }], ["cookies", "List your cookies", - function () { toOpenWindowByType("Browser:Cookies", "chrome://browser/content/preferences/cookies.xul", "chrome,dialog=no,resizable"); }], + function () { window.toOpenWindowByType("Browser:Cookies", "chrome://browser/content/preferences/cookies.xul", "chrome,dialog=no,resizable"); }], ["console", "JavaScript console", - function () { toJavaScriptConsole(); }], + function () { window.toJavaScriptConsole(); }], ["customizetoolbar", "Customize the Toolbar", - function () { BrowserCustomizeToolbar(); }], + function () { window.BrowserCustomizeToolbar(); }], ["dominspector", "DOM Inspector", - function () { try { inspectDOMDocument(content.document); } catch (e) { liberator.echoerr("DOM Inspector extension not installed"); } }], + function () { try { window.inspectDOMDocument(content.document); } catch (e) { liberator.echoerr("DOM Inspector extension not installed"); } }], ["downloads", "Manage Downloads", - function () { toOpenWindowByType("Download:Manager", "chrome://mozapps/content/downloads/downloads.xul", "chrome,dialog=no,resizable"); }], + function () { window.toOpenWindowByType("Download:Manager", "chrome://mozapps/content/downloads/downloads.xul", "chrome,dialog=no,resizable"); }], ["history", "List your history", - function () { openDialog("chrome://browser/content/history/history-panel.xul", "History", "dialog,centerscreen,width=600,height=600"); }], + function () { window.openDialog("chrome://browser/content/history/history-panel.xul", "History", "dialog,centerscreen,width=600,height=600"); }], ["import", "Import Preferences, Bookmarks, History, etc. from other browsers", - function () { BrowserImport(); }], + function () { window.BrowserImport(); }], ["openfile", "Open the file selector dialog", - function () { BrowserOpenFileWindow(); }], + function () { window.BrowserOpenFileWindow(); }], ["pageinfo", "Show information about the current page", - function () { BrowserPageInfo(); }], + function () { window.BrowserPageInfo(); }], ["pagesource", "View page source", - function () { BrowserViewSourceOfDocument(content.document); }], + function () { window.BrowserViewSourceOfDocument(content.document); }], ["places", "Places Organizer: Manage your bookmarks and history", function () { PlacesCommandHook.showPlacesOrganizer(ORGANIZER_ROOT_BOOKMARKS); }], ["preferences", "Show Firefox preferences dialog", - function () { openPreferences(); }], + function () { window.openPreferences(); }], ["printpreview", "Preview the page before printing", function () { PrintUtils.printPreview(onEnterPrintPreview, onExitPrintPreview); }], ["printsetup", "Setup the page size and orientation before printing", @@ -96,11 +96,11 @@ const config = { //{{{ ["print", "Show print dialog", function () { PrintUtils.print(); }], ["saveframe", "Save frame to disk", - function () { saveFrameDocument(); }], + function () { window.saveFrameDocument(); }], ["savepage", "Save page to disk", - function () { saveDocument(window.content.document); }], + function () { window.saveDocument(window.content.document); }], ["searchengines", "Manage installed search engines", - function () { openDialog("chrome://browser/content/search/engineManager.xul", "_blank", "chrome,dialog,modal,centerscreen"); }], + function () { window.openDialog("chrome://browser/content/search/engineManager.xul", "_blank", "chrome,dialog,modal,centerscreen"); }], ["selectionsource", "View selection source", function () { buffer.viewSelectionSource(); }] ],