mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 12:58:00 +01:00
:emenu invocation efficiency enhancement.
This commit is contained in:
@@ -135,30 +135,26 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
|||||||
set: function mode(val) modes.main = val
|
set: function mode(val) modes.main = val
|
||||||
}),
|
}),
|
||||||
|
|
||||||
get menuItems() {
|
getMenuItems: function getMenuItems(targetPath) {
|
||||||
function dispatch(node, name) {
|
|
||||||
let event = node.ownerDocument.createEvent("Events");
|
|
||||||
event.initEvent(name, false, false);
|
|
||||||
node.dispatchEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
function addChildren(node, parent) {
|
function addChildren(node, parent) {
|
||||||
DOM(node).createContents();
|
DOM(node).createContents();
|
||||||
|
|
||||||
if (~["menu", "menupopup"].indexOf(node.localName) && node.children.length)
|
if (~["menu", "menupopup"].indexOf(node.localName) && node.children.length)
|
||||||
dispatch(node, "popupshowing");
|
DOM(node).popupshowing({ bubbles: false });
|
||||||
|
|
||||||
for (let [, item] in Iterator(node.childNodes)) {
|
for (let [, item] in Iterator(node.childNodes)) {
|
||||||
if (item.childNodes.length == 0 && item.localName == "menuitem"
|
if (item.childNodes.length == 0 && item.localName == "menuitem"
|
||||||
&& !item.hidden
|
&& !item.hidden
|
||||||
&& !/rdf:http:/.test(item.getAttribute("label"))) { // FIXME
|
&& !/rdf:http:/.test(item.getAttribute("label"))) { // FIXME
|
||||||
item.dactylPath = parent + item.getAttribute("label");
|
item.dactylPath = parent + item.getAttribute("label");
|
||||||
|
if (!targetPath || targetPath.indexOf(item.dactylPath) == 0)
|
||||||
items.push(item);
|
items.push(item);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let path = parent;
|
let path = parent;
|
||||||
if (item.localName == "menu")
|
if (item.localName == "menu")
|
||||||
path += item.getAttribute("label") + ".";
|
path += item.getAttribute("label") + ".";
|
||||||
|
if (!targetPath || targetPath.indexOf(path) == 0)
|
||||||
addChildren(item, path);
|
addChildren(item, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,6 +165,8 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
|||||||
return items;
|
return items;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
get menuItems() this.getMenuItems(),
|
||||||
|
|
||||||
// Global constants
|
// Global constants
|
||||||
CURRENT_TAB: "here",
|
CURRENT_TAB: "here",
|
||||||
NEW_TAB: "tab",
|
NEW_TAB: "tab",
|
||||||
@@ -1510,7 +1508,7 @@ 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.menuItems;
|
let items = dactyl.getMenuItems(arg);
|
||||||
|
|
||||||
dactyl.assert(items.some(function (i) i.dactylPath == arg),
|
dactyl.assert(items.some(function (i) i.dactylPath == arg),
|
||||||
_("emenu.notFound", arg));
|
_("emenu.notFound", arg));
|
||||||
|
|||||||
Reference in New Issue
Block a user