1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 07:58:00 +01:00

Fix menuItem completer, use it for :emenu

This commit is contained in:
Kris Maglione
2009-01-07 17:56:53 -05:00
parent 0aeee25e65
commit d9418ff43b
2 changed files with 38 additions and 40 deletions

View File

@@ -1614,14 +1614,16 @@ function Completion() //{{{
// FIXME: Line/Column doesn't make sense with %
context.title = ["Mark", "Line Column File"];
context.keys = {
text: 0,
description: function ([,m]) percent(m.position.y) + "% " + percent(m.position.x) + "% " + m.location
};
context.keys.description = function ([,m]) percent(m.position.y) + "% " + percent(m.position.x) + "% " + m.location;
context.completions = marks.all;
},
menuItem: function menuItem(filter) commands.get("emenu").completer(filter), // XXX
menuItem: function menuItem(context)
{
context.title = ["Menu Path", "Label"];
context.keys = { text: "fullMenuPath", description: "label" };
context.completions = liberator.menuItems;
},
option: function option(context, scope)
{

View File

@@ -206,6 +206,34 @@ const liberator = (function () //{{{
function () { liberator.quit(true); });
});
// TODO: move this
function getMenuItems()
{
function addChildren(node, parent)
{
for (let [,item] in Iterator(node.childNodes))
{
if (item.childNodes.length == 0 && item.localName == "menuitem"
&& !/rdf:http:/.test(item.label)) // FIXME
{
item.fullMenuPath = parent + item.label;
items.push(item);
}
else
{
let path = parent;
if (item.localName == "menu")
path += item.label + ".";
addChildren(item, path);
}
}
}
let items = [];
addChildren(document.getElementById(config.guioptions["m"][1]), "");
return items;
}
registerObserver("load_commands", function ()
{
commands.add(["addo[ns]"],
@@ -256,34 +284,6 @@ const liberator = (function () //{{{
completer: function (context, args) completion.dialog(context)
});
// TODO: move this
function getMenuItems()
{
function addChildren(node, parent)
{
for (let [,item] in Iterator(node.childNodes))
{
if (item.childNodes.length == 0 && item.localName == "menuitem"
&& !/rdf:http:/.test(item.label)) // FIXME
{
item.fullMenuPath = parent + item.label;
items.push(item);
}
else
{
let path = parent;
if (item.localName == "menu")
path += item.label + ".";
addChildren(item, path);
}
}
}
let items = [];
addChildren(document.getElementById(config.guioptions["m"][1]), "");
return items;
}
commands.add(["em[enu]"],
"Execute the specified menu item from the command line",
function (args)
@@ -305,13 +305,7 @@ const liberator = (function () //{{{
},
{
argCount: "1",
// TODO: add this as a standard menu completion function
completer: function (context)
{
context.title = ["Menu Path", "Label"];
context.keys = { text: "fullMenuPath", description: "label" };
context.completions = getMenuItems();
},
completer: function (context) completion.menuItem(context),
literal: 0
});
@@ -597,6 +591,8 @@ const liberator = (function () //{{{
get mode() modes.main,
set mode(value) modes.main = value,
get menuItems() getMenuItems(),
// Global constants
CURRENT_TAB: 1,
NEW_TAB: 2,