mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 22:42:26 +01:00
add :emenu for accessing menubar menu items from the command line
This commit is contained in:
1
NEWS
1
NEWS
@@ -15,6 +15,7 @@
|
||||
generous donation which made this behavior possible)
|
||||
* IMPORTANT: ctrl-x/a never take possible negative URLs into account, it was just
|
||||
too unpredictable
|
||||
* add :emenu for accessing the Firefox main menu items from the command line
|
||||
* add 'shell' and 'shellcmdflag' options
|
||||
* :tabprevious, :bprevious, :tabnext, :bnext and friends now accept a prefix count
|
||||
* add :comclear and :delcommand
|
||||
|
||||
@@ -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]"],
|
||||
"Execute the argument as an Ex command",
|
||||
function (args) { liberator.execute(args); });
|
||||
|
||||
@@ -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[log] [firefox-dialog]|| +
|
||||
________________________________________________________________________________
|
||||
|
||||
Reference in New Issue
Block a user