From 2c59c01232593776f296086c609f84123708c615 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Fri, 29 Jul 2011 03:42:31 -0400 Subject: [PATCH] :emenu: Hide hidden items, disable disabled items. Closes issue #582. --- common/content/dactyl.js | 60 +++++++++++++------------ common/locale/en-US/messages.properties | 2 + common/modules/completion.jsm | 2 +- common/modules/config.jsm | 2 + common/modules/template.jsm | 2 +- 5 files changed, 38 insertions(+), 30 deletions(-) diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 131380c1..fd2aa6d5 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -119,7 +119,28 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { set: function mode(val) modes.main = val }), - get menuItems() Dactyl.getMenuItems(), + get menuItems() { + function addChildren(node, parent) { + 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", @@ -1538,29 +1559,6 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { catch (e) {} }); } - }, - - // TODO: move this - getMenuItems: function () { - function addChildren(node, parent) { - for (let [, item] in Iterator(node.childNodes)) { - if (item.childNodes.length == 0 && item.localName == "menuitem" - && !/rdf:http:/.test(item.getAttribute("label"))) { // FIXME - item.fullMenuPath = 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; } }, { events: function () { @@ -1787,14 +1785,16 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { "Execute the specified menu item from the command line", function (args) { let arg = args[0] || ""; - let items = Dactyl.getMenuItems(); + let items = dactyl.menuItems; - dactyl.assert(items.some(function (i) i.fullMenuPath == arg), + dactyl.assert(items.some(function (i) i.dactylPath == arg), _("emenu.notFound", arg)); for (let [, item] in Iterator(items)) { - if (item.fullMenuPath == arg) + if (item.dactylPath == arg) { + dactyl.assert(!item.disabled, _("error.disabled", item.dactylPath)); item.doCommand(); + } } }, { argCount: "1", @@ -2112,7 +2112,11 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { completion.menuItem = function menuItem(context) { context.title = ["Menu Path", "Label"]; context.anchored = false; - context.keys = { text: "fullMenuPath", description: function (item) item.getAttribute("label") }; + context.keys = { + text: "dactylPath", + description: function (item) item.getAttribute("label"), + highlight: function (item) item.disabled ? "Disabled" : "" + }; context.completions = dactyl.menuItems; }; diff --git a/common/locale/en-US/messages.properties b/common/locale/en-US/messages.properties index 080336ca..e9c29911 100644 --- a/common/locale/en-US/messages.properties +++ b/common/locale/en-US/messages.properties @@ -331,6 +331,8 @@ error.clipboardEmpty = No clipboard data error.countRequired-1 = Count required for %S error.cantOpen-2 = Error opening %S: %S error.error-1 = Error: %S +error.disabled = Item is disabled +error.disabled-1 = '%S' is disabled error.interrupted = Interrupted error.invalidSort-1 = Invalid sort order: %S error.missingQuote-1 = E114: Missing quote: %S diff --git a/common/modules/completion.jsm b/common/modules/completion.jsm index 2871d4f3..9671e95a 100644 --- a/common/modules/completion.jsm +++ b/common/modules/completion.jsm @@ -338,7 +338,7 @@ var CompletionContext = Class("CompletionContext", { * The prototype object for items returned by {@link items}. */ get itemPrototype() { - let res = {}; + let res = { highlight: "" }; function result(quote) { yield ["result", quote ? function () quote[0] + util.trapErrors(1, quote, this.text) + quote[2] : function () this.text]; diff --git a/common/modules/config.jsm b/common/modules/config.jsm index 7f30adcc..11dd9488 100644 --- a/common/modules/config.jsm +++ b/common/modules/config.jsm @@ -468,6 +468,8 @@ var ConfigBase = Class("ConfigBase", { color: red !important; background: white !important; StatusWarningMsg /* A warning message in the status line */ \ color: red !important; background: transparent !important; + Disabled /* Disabled items */ \ + color: gray !important; CmdLine;>*;;FontFixed /* The command line */ \ padding: 1px !important; diff --git a/common/modules/template.jsm b/common/modules/template.jsm index d81ec595..6e18dc50 100644 --- a/common/modules/template.jsm +++ b/common/modules/template.jsm @@ -197,7 +197,7 @@ var Template = Module("Template", { - from pushing the baseline down and enlarging - the row. --> -
  • {text} 
  • +
  • {text} 
  • {desc} 
  • ; //