From 252e7450f1801a3a2580be0ec6a82a6f8f8491da Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Fri, 3 Dec 2010 18:11:05 -0500 Subject: [PATCH] Crude source line linkification in :*usage. --- common/content/buffer.js | 18 ++++++++++++++++++ common/content/commands.js | 6 +++++- common/content/dactyl.js | 16 ++++++++-------- common/content/mappings.js | 1 + common/content/options.js | 2 ++ common/modules/template.jsm | 9 ++++++++- 6 files changed, 42 insertions(+), 10 deletions(-) diff --git a/common/content/buffer.js b/common/content/buffer.js index 2a00661a..69e147f8 100644 --- a/common/content/buffer.js +++ b/common/content/buffer.js @@ -142,6 +142,11 @@ const Buffer = Module("buffer", { return Array.map(metaNodes, function (node) [(node.name || node.httpEquiv), template.highlightURL(node.content)]) .sort(function (a, b) util.compareIgnoreCase(a[0], b[0])); }); + + dactyl.commands["buffer.viewSource"] = function (event) { + let elem = event.originalTarget; + buffer.viewSource([elem.getAttribute("href"), Number(elem.getAttribute("line"))]) + }; }, destroy: function () { @@ -951,6 +956,19 @@ const Buffer = Module("buffer", { viewSource: function (url, useExternalEditor) { let doc = buffer.focusedFrame.document; + if (isArray(url)) { + let chrome = "chrome://global/content/viewSource.xul"; + window.openDialog(chrome, "_blank", "all,dialog=no", + url[0], null, null, url[1]); + /* FIXME + let win = dactyl.open(chrome)[0]; + while (win.document.documentURI != chrome) + util.threadYield(false, true); + win.arguments = [url[0], null, null, url[1]]; + */ + return; + } + if (useExternalEditor) this.viewSourceExternally(url || doc); else { diff --git a/common/content/commands.js b/common/content/commands.js index d4af8f28..01481fe7 100644 --- a/common/content/commands.js +++ b/common/content/commands.js @@ -451,10 +451,14 @@ const Commands = Module("commands", { repeat: null, _addCommand: function (args, replace) { + if (!args[3]) + args[3] = {}; + args[3].definedAt = Components.stack.caller.caller; + let names = array.flatten(Command.parseSpecs(args[0])); dactyl.assert(!names.some(function (name) name in this._exMap && !this._exMap[name].user, this), "E182: Can't replace non-user command: " + args[0][0]); - if (!replace || !(args[3] && args[3].user)) + if (!replace || !args[3].user) dactyl.assert(!names.some(function (name) name in this._exMap, this), "Not replacing command " + args[0]); for (let name in values(names)) { diff --git a/common/content/dactyl.js b/common/content/dactyl.js index b46ad7b3..c9c06eae 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -888,24 +888,23 @@ const Dactyl = Module("dactyl", { switch (where) { case dactyl.CURRENT_TAB: browser.loadURIWithFlags(url, flags, null, null, postdata); - break; + return browser.contentWindow; case dactyl.NEW_TAB: if (!dactyl.has("tabs")) return open(urls, dactyl.NEW_WINDOW); - prefs.withContext(function () { + return prefs.withContext(function () { prefs.set("browser.tabs.loadInBackground", true); - browser.loadOneTab(url, null, null, postdata, background); + return browser.loadOneTab(url, null, null, postdata, background).linkedBrowser.contentDocument; }); - break; case dactyl.NEW_WINDOW: window.open(); let win = services.windowMediator.getMostRecentWindow("navigator:browser"); win.loadURI(url, null, postdata); browser = win.getBrowser(); - break; + return win.content; } } catch (e) {} @@ -921,11 +920,12 @@ const Dactyl = Module("dactyl", { else if (!where) where = dactyl.CURRENT_TAB; - for (let [, url] in Iterator(urls)) { - open(url, where); + return urls.map(function (url) { + let res = open(url, where); where = dactyl.NEW_TAB; background = true; - } + return res; + }); }, pluginFiles: {}, diff --git a/common/content/mappings.js b/common/content/mappings.js index 37ac49e5..592ac8e3 100644 --- a/common/content/mappings.js +++ b/common/content/mappings.js @@ -140,6 +140,7 @@ const Mappings = Module("mappings", { _addMap: function (map) { let where = map.user ? this._user : this._main; + map.definedAt = Components.stack.caller.caller; map.modes.forEach(function (mode) { if (!(mode in where)) where[mode] = []; diff --git a/common/content/options.js b/common/content/options.js index 5abe8c62..d682c787 100644 --- a/common/content/options.js +++ b/common/content/options.js @@ -642,6 +642,8 @@ const Options = Module("options", { if (!extraInfo) extraInfo = {}; + extraInfo.definedAt = Components.stack.caller; + let name = names[0]; if (name in this._optionMap) { dactyl.log("Warning: " + name.quote() + " already exists: replacing existing option.", 1); diff --git a/common/modules/template.jsm b/common/modules/template.jsm index 09d0d0df..c510c0eb 100644 --- a/common/modules/template.jsm +++ b/common/modules/template.jsm @@ -294,7 +294,14 @@ const Template = Module("Template", { { this.map(iter, function (item) - {item.name || item.names[0]} + { + let (name = item.name || item.names[0], frame = item.definedAt) + frame ? + + {name} + : name + } {item.description} ) }