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

add :emenu for accessing menubar menu items from the command line

This commit is contained in:
Doug Kearns
2008-08-14 05:01:18 +00:00
parent be5c793f4f
commit b145689c14
3 changed files with 71 additions and 0 deletions

1
NEWS
View File

@@ -15,6 +15,7 @@
generous donation which made this behavior possible) generous donation which made this behavior possible)
* IMPORTANT: ctrl-x/a never take possible negative URLs into account, it was just * IMPORTANT: ctrl-x/a never take possible negative URLs into account, it was just
too unpredictable too unpredictable
* add :emenu for accessing the Firefox main menu items from the command line
* add 'shell' and 'shellcmdflag' options * add 'shell' and 'shellcmdflag' options
* :tabprevious, :bprevious, :tabnext, :bnext and friends now accept a prefix count * :tabprevious, :bprevious, :tabnext, :bnext and friends now accept a prefix count
* add :comclear and :delcommand * add :comclear and :delcommand

View File

@@ -152,6 +152,66 @@ const liberator = (function () //{{{
} }
}); });
// TODO: move this
function getMenuItems()
{
var menubar = document.getElementById("main-menubar");
var items = [];
for (var i = 0; i < menubar.childNodes.length; i++)
{
(function (item, path)
{
if (item.childNodes.length == 0 && item.localName == "menuitem"
&& !/rdf:http:/.test(item.label)) // FIXME
{
item.fullMenuPath = path += item.label;
items.push(item);
}
else
{
if (item.localName == "menu")
path += item.label + ".";
for (var j = 0; j < item.childNodes.length; j++)
arguments.callee(item.childNodes[j], path);
}
})(menubar.childNodes[i], "");
}
return items;
}
liberator.commands.addUserCommand(["em[enu]"],
"Execute the specified menu item from the command line",
function (args)
{
var item = args.string;
var items = getMenuItems();
if (!items.some(function (i) { return i.fullMenuPath == item; }))
{
liberator.echoerr("E334: Menu not found: " + item);
return;
}
for (var i = 0; i < items.length; i++)
{
if (items[i].fullMenuPath == item)
items[i].doCommand();
}
},
{
argCount: "+", // NOTE: single arg may contain unescaped whitespace
completer: function (filter)
{
var completions = getMenuItems().map(function (item) {
return [item.fullMenuPath, item.label];
});
return [0, liberator.completion.filter(completions, filter)];
}
});
liberator.commands.add(["exe[cute]"], liberator.commands.add(["exe[cute]"],
"Execute the argument as an Ex command", "Execute the argument as an Ex command",
function (args) { liberator.execute(args); }); function (args) { liberator.execute(args); });

View File

@@ -116,6 +116,16 @@ Play a system beep.
________________________________________________________________________________ ________________________________________________________________________________
|:emenu| +
||:emenu {menu}||
________________________________________________________________________________
Execute {menu} from the command line. This command provides command line
access to all menu items available from the main Firefox menubar. {menu} is a
hierachical path to the menu item with each submenu separated by a period.
E.g. :emenu File.Open File...
________________________________________________________________________________
|:dia| |:dialog| |:dia| |:dialog|
||:dia[log] [firefox-dialog]|| + ||:dia[log] [firefox-dialog]|| +
________________________________________________________________________________ ________________________________________________________________________________