-
Notifications
You must be signed in to change notification settings - Fork 209
Menus
rawcreative edited this page May 17, 2014
·
4 revisions
This method now allows for adding root level menu items as well as specifying the menu position, with the additional 'index' argument.
//Syntax: addItem(Label, Shorcut Keys, Callback, Index);
//Add a root level menu
macgap.menu.addItem('Foo', 'cmd+g', function() { alert('yay'); }, 1);
//Add an item to existing menu
macgap.menu.getItem('File').submenu().addItem('Foo', 'cmd+g', function() { alert('yay'); }, 1);
// Add a new submenu for a menu item.
macgap.menu.getItem("File").submenu().getItem('Foo').addSubmenu().addItem("Foofoo", "cmd+opt+h", function() { alert("Foofoo!"); })
The index parameter is optional for both root level and submenus. Excluding it will add the menu item to the end of the menu.
Menu item keyboard shortcuts can include any of the following modifiers: caps
, shift
, cmd
, ctrl
, opt
, alt
Add a menu item separator.
macgap.menu.getItem("File").submenu().addSeparator();
Remove a menu item or an entire menu.
Remove the file menu
macgap.menu.getItem("File").remove();
Remove the file menu's "foo" item
macgap.menu.getItem("File").submenu().getItem("Foo").remove();
Remove a menu item.
macgap.menu.getItem("File").submenu().getItem("Close").remove();
Change the callback for a menu item.
macgap.menu.getItem("File").submenu().getItem("Foo").setCallback(function(){alert('Foo new');});
Change the key command for a menu item.
macgap.menu.getItem("File").submenu().getItem("Foo").setKey('cmd-opt-ctrl-g');
Change the title of a menu item.
macgap.menu.getItem("File").submenu().getItem("Foo").setTitle('Foonew');
This is a convenience/shortcut method for .remove() when removing top level menus.
macgap.menu.removeMenu('File');
Enable a disabled menu menu item
macgap.menu.getItem('File').submenu().getItem('Save').enable();
Disable a menu item
macgap.menu.getItem('File').submenu().getItem('Save').disable();