X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=common%2Fcontent%2Fdactyl.js;h=1a244ff641412240d89ec6c7c4726bdcd993529e;hb=70740024f9c028c1fd63e1a1850ab062ff956054;hp=6296b9ac6d26a5db35ccee446d4ecd3c606de94d;hpb=eeed0be1a8abf7e3c97f43b63c1d595e940fef21;p=dactyl.git diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 6296b9a..1a244ff 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -12,9 +12,6 @@ default xml namespace = XHTML; XML.ignoreWhitespace = false; XML.prettyPrinting = false; -var userContext = { __proto__: modules }; -var _userContext = newContext(userContext); - var EVAL_ERROR = "__dactyl_eval_error"; var EVAL_RESULT = "__dactyl_eval_result"; var EVAL_STRING = "__dactyl_eval_string"; @@ -41,9 +38,25 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { }; styles.registerSheet("resource://dactyl-skin/dactyl.css"); + + this.cleanups = []; + this.cleanups.push(util.overlayObject(window, { + focusAndSelectUrlBar: function focusAndSelectUrlBar() { + switch (options.get("strictfocus").getKey(document.documentURIObject || util.newURI(document.documentURI), "moderate")) { + case "laissez-faire": + if (!Events.isHidden(window.gURLBar, true)) + return focusAndSelectUrlBar.superapply(this, arguments); + default: + // Evil. Ignore. + } + } + })); }, cleanup: function () { + for (let cleanup in values(this.cleanups)) + cleanup.call(this); + delete window.dactyl; delete window.liberator; @@ -57,21 +70,36 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { autocommands.trigger("Leave", {}); }, + // initially hide all GUI elements, they are later restored unless the user + // has :set go= or something similar in his config + hideGUI: function () { + let guioptions = config.guioptions; + for (let option in guioptions) { + guioptions[option].forEach(function (elem) { + try { + document.getElementById(elem).collapsed = true; + } + catch (e) {} + }); + } + }, + + observers: { - "dactyl-cleanup": function dactyl_cleanup() { + "dactyl-cleanup": function dactyl_cleanup(subject, reason) { let modules = dactyl.modules; for (let mod in values(modules.moduleList.reverse())) { mod.stale = true; if ("cleanup" in mod) - this.trapErrors("cleanup", mod); + this.trapErrors("cleanup", mod, reason); if ("destroy" in mod) - this.trapErrors("destroy", mod); + this.trapErrors("destroy", mod, reason); } for (let mod in values(modules.ownPropertyValues.reverse())) if (mod instanceof Class && "INIT" in mod && "cleanup" in mod.INIT) - this.trapErrors(mod.cleanup, mod, dactyl, modules, window); + this.trapErrors(mod.cleanup, mod, dactyl, modules, window, reason); for (let name in values(Object.getOwnPropertyNames(modules).reverse())) try { @@ -98,7 +126,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { }), /** - * @property {number} The current main mode. + * @property {Modes.Mode} The current main mode. * @see modes#mainModes */ mode: deprecated("modes.main", { @@ -106,7 +134,37 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { set: function mode(val) modes.main = val }), - get menuItems() Dactyl.getMenuItems(), + get menuItems() { + function dispatch(node, name) { + let event = node.ownerDocument.createEvent("Events"); + event.initEvent(name, false, false); + node.dispatchEvent(event); + } + + function addChildren(node, parent) { + if (~["menu", "menupopup"].indexOf(node.localName) && node.children.length) + dispatch(node, "popupshowing"); + + for (let [, item] in Iterator(node.childNodes)) { + if (item.childNodes.length == 0 && item.localName == "menuitem" + && !item.hidden + && !/rdf:http:/.test(item.getAttribute("label"))) { // FIXME + item.dactylPath = parent + item.getAttribute("label"); + items.push(item); + } + else { + let path = parent; + if (item.localName == "menu") + path += item.getAttribute("label") + "."; + addChildren(item, path); + } + } + } + + let items = []; + addChildren(document.getElementById(config.guioptions["m"][1]), ""); + return items; + }, // Global constants CURRENT_TAB: "here", @@ -184,14 +242,16 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { }, addUsageCommand: function (params) { + function keys(item) (item.names || [item.name]).concat(item.description, item.columns || []); + let name = commands.add(params.name, params.description, function (args) { let results = array(params.iterate(args)) .sort(function (a, b) String.localeCompare(a.name, b.name)); - let filters = args.map(function (arg) RegExp("\\b" + util.regexp.escape(arg) + "\\b", "i")); + let filters = args.map(function (arg) util.regexp("\\b" + util.regexp.escape(arg) + "\\b", "i")); if (filters.length) - results = results.filter(function (item) filters.every(function (re) re.test(item.name + " " + item.description))); + results = results.filter(function (item) filters.every(function (re) keys(item).some(re.closure.test))); commandline.commandOutput( template.usage(results, params.format)); @@ -200,9 +260,9 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { argCount: "*", completer: function (context, args) { context.keys.text = util.identity; - context.keys.description = function () seen[this.text] + " matching items"; + context.keys.description = function () seen[this.text] + /*L*/" matching items"; let seen = {}; - context.completions = array(item.description.toLowerCase().split(/[()\s]+/) + context.completions = array(keys(item).join(" ").toLowerCase().split(/[()\s]+/) for (item in params.iterate(args))) .flatten().filter(function (w) /^\w[\w-_']+$/.test(w)) .map(function (k) { @@ -221,7 +281,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { let tags = services["dactyl:"].HELP_TAGS; for (let obj in values(results)) { let res = dactyl.generateHelp(obj, null, null, true); - if (!set.has(tags, obj.helpTag)) + if (!Set.has(tags, obj.helpTag)) res[1].@tag = obj.helpTag; yield res; @@ -311,7 +371,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { clipboardHelper.copyString(str); if (verbose) { - let message = { message: "Yanked " + str }; + let message = { message: _("dactyl.yank", str) }; try { message.domains = [util.newURI(str).host]; } @@ -346,7 +406,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { echoerr: function echoerr(str, flags) { flags |= commandline.APPEND_TO_MESSAGES; - if (isinstance(str, ["Error", "Exception"])) + if (isinstance(str, ["DOMException", "Error", "Exception"]) || isinstance(str, ["XPCWrappedNative_NoHelper"]) && /^\[Exception/.test(str)) dactyl.reportError(str); if (isObject(str) && "echoerr" in str) str = str.echoerr; @@ -414,7 +474,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { ({ file: fileName, line: lineNumber, context: ctxt }) = info; if (!context && fileName && fileName[0] !== "[") - context = _userContext || ctxt; + context = ctxt || _userContext; if (isinstance(context, ["Sandbox"])) return Cu.evalInSandbox(str, context, "1.8", fileName, lineNumber); @@ -559,7 +619,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { * @param {string} feature The feature name. * @returns {boolean} */ - has: function (feature) set.has(config.features, feature), + has: function (feature) Set.has(config.features, feature), /** * Returns the URL of the specified help *topic* if it exists. @@ -608,6 +668,10 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { * Initialize the help system. */ initHelp: function (force) { + // Waits for the add-on to become available, if necessary. + config.addon; + config.version; + if (force || !this.helpInitialized) { if ("noscriptOverlay" in window) { noscriptOverlay.safeAllow("chrome-data:", true, false); @@ -665,34 +729,38 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { let body = XML(); for (let [, context] in Iterator(plugins.contexts)) - if (context && context.INFO instanceof XML) { - let info = context.INFO; - if (info.*.@lang.length()) { - let lang = config.bestLocale(String(a) for each (a in info.*.@lang)); + try { + let info = contexts.getDocs(context); + if (info instanceof XML) { + if (info.*.@lang.length()) { + let lang = config.bestLocale(String(a) for each (a in info.*.@lang)); - info.* = info.*.(function::attribute("lang").length() == 0 || @lang == lang); + info.* = info.*.(function::attribute("lang").length() == 0 || @lang == lang); - for each (let elem in info.NS::info) - for each (let attr in ["@name", "@summary", "@href"]) - if (elem[attr].length()) - info[attr] = elem[attr]; + for each (let elem in info.NS::info) + for each (let attr in ["@name", "@summary", "@href"]) + if (elem[attr].length()) + info[attr] = elem[attr]; + } + body +=

{info.@summary}

+ + info; } - body +=

{context.INFO.@summary}

+ - context.INFO; + } + catch (e) { + util.reportError(e); } let help = '\n' + '\n' + '\n' + - unescape(encodeURI( // UTF-8 handling hack. -

Using Plugins

+

{_("help.title.Using Plugins")}

{body} -
.toXMLString())); + .toXMLString(); fileMap["plugins"] = function () ['text/xml;charset=UTF-8', help]; fileMap["versions"] = function () { @@ -725,6 +793,8 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { default xml namespace = NS; function rec(text, level, li) { + XML.ignoreWhitespace = XML.prettyPrinting = false; + let res = <>; let list, space, i = 0; @@ -735,7 +805,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { if (!list) res += list =