mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-03-23 09:13:33 +01:00
:emenu: Hide hidden items, disable disabled items. Closes issue #582.
This commit is contained in:
@@ -119,7 +119,28 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
|||||||
set: function mode(val) modes.main = val
|
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
|
// Global constants
|
||||||
CURRENT_TAB: "here",
|
CURRENT_TAB: "here",
|
||||||
@@ -1538,29 +1559,6 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
|||||||
catch (e) {}
|
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 () {
|
events: function () {
|
||||||
@@ -1787,14 +1785,16 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
|||||||
"Execute the specified menu item from the command line",
|
"Execute the specified menu item from the command line",
|
||||||
function (args) {
|
function (args) {
|
||||||
let arg = args[0] || "";
|
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));
|
_("emenu.notFound", arg));
|
||||||
|
|
||||||
for (let [, item] in Iterator(items)) {
|
for (let [, item] in Iterator(items)) {
|
||||||
if (item.fullMenuPath == arg)
|
if (item.dactylPath == arg) {
|
||||||
|
dactyl.assert(!item.disabled, _("error.disabled", item.dactylPath));
|
||||||
item.doCommand();
|
item.doCommand();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
argCount: "1",
|
argCount: "1",
|
||||||
@@ -2112,7 +2112,11 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
|||||||
completion.menuItem = function menuItem(context) {
|
completion.menuItem = function menuItem(context) {
|
||||||
context.title = ["Menu Path", "Label"];
|
context.title = ["Menu Path", "Label"];
|
||||||
context.anchored = false;
|
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;
|
context.completions = dactyl.menuItems;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -331,6 +331,8 @@ error.clipboardEmpty = No clipboard data
|
|||||||
error.countRequired-1 = Count required for %S
|
error.countRequired-1 = Count required for %S
|
||||||
error.cantOpen-2 = Error opening %S: %S
|
error.cantOpen-2 = Error opening %S: %S
|
||||||
error.error-1 = Error: %S
|
error.error-1 = Error: %S
|
||||||
|
error.disabled = Item is disabled
|
||||||
|
error.disabled-1 = '%S' is disabled
|
||||||
error.interrupted = Interrupted
|
error.interrupted = Interrupted
|
||||||
error.invalidSort-1 = Invalid sort order: %S
|
error.invalidSort-1 = Invalid sort order: %S
|
||||||
error.missingQuote-1 = E114: Missing quote: %S
|
error.missingQuote-1 = E114: Missing quote: %S
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ var CompletionContext = Class("CompletionContext", {
|
|||||||
* The prototype object for items returned by {@link items}.
|
* The prototype object for items returned by {@link items}.
|
||||||
*/
|
*/
|
||||||
get itemPrototype() {
|
get itemPrototype() {
|
||||||
let res = {};
|
let res = { highlight: "" };
|
||||||
function result(quote) {
|
function result(quote) {
|
||||||
yield ["result", quote ? function () quote[0] + util.trapErrors(1, quote, this.text) + quote[2]
|
yield ["result", quote ? function () quote[0] + util.trapErrors(1, quote, this.text) + quote[2]
|
||||||
: function () this.text];
|
: function () this.text];
|
||||||
|
|||||||
@@ -468,6 +468,8 @@ var ConfigBase = Class("ConfigBase", {
|
|||||||
color: red !important; background: white !important;
|
color: red !important; background: white !important;
|
||||||
StatusWarningMsg /* A warning message in the status line */ \
|
StatusWarningMsg /* A warning message in the status line */ \
|
||||||
color: red !important; background: transparent !important;
|
color: red !important; background: transparent !important;
|
||||||
|
Disabled /* Disabled items */ \
|
||||||
|
color: gray !important;
|
||||||
|
|
||||||
CmdLine;>*;;FontFixed /* The command line */ \
|
CmdLine;>*;;FontFixed /* The command line */ \
|
||||||
padding: 1px !important;
|
padding: 1px !important;
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ var Template = Module("Template", {
|
|||||||
- from pushing the baseline down and enlarging
|
- from pushing the baseline down and enlarging
|
||||||
- the row.
|
- the row.
|
||||||
-->
|
-->
|
||||||
<li highlight="CompResult">{text} </li>
|
<li highlight={"CompResult " + item.highlight}>{text} </li>
|
||||||
<li highlight="CompDesc">{desc} </li>
|
<li highlight="CompDesc">{desc} </li>
|
||||||
</div>;
|
</div>;
|
||||||
// </e4x>
|
// </e4x>
|
||||||
|
|||||||
Reference in New Issue
Block a user