1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-31 13:55:46 +01:00

:emenu: Hide hidden items, disable disabled items. Closes issue #582.

This commit is contained in:
Kris Maglione
2011-07-29 03:42:31 -04:00
parent 3b3d155986
commit 2c59c01232
5 changed files with 38 additions and 30 deletions

View File

@@ -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;
};

View File

@@ -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

View File

@@ -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];

View File

@@ -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;

View File

@@ -197,7 +197,7 @@ var Template = Module("Template", {
- from pushing the baseline down and enlarging
- the row.
-->
<li highlight="CompResult">{text}&#xa0;</li>
<li highlight={"CompResult " + item.highlight}>{text}&#xa0;</li>
<li highlight="CompDesc">{desc}&#xa0;</li>
</div>;
// </e4x>