Skip to content
rawcreative edited this page May 17, 2014 · 4 revisions

addItem()

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

addSeparator()

Add a menu item separator.

macgap.menu.getItem("File").submenu().addSeparator();

remove()

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();

setCallback()

Change the callback for a menu item.

macgap.menu.getItem("File").submenu().getItem("Foo").setCallback(function(){alert('Foo new');});

setKey()

Change the key command for a menu item.

macgap.menu.getItem("File").submenu().getItem("Foo").setKey('cmd-opt-ctrl-g');

setTitle()

Change the title of a menu item.

macgap.menu.getItem("File").submenu().getItem("Foo").setTitle('Foonew');

removeMenu(ID)

This is a convenience/shortcut method for .remove() when removing top level menus.

macgap.menu.removeMenu('File');

enable()

Enable a disabled menu menu item

macgap.menu.getItem('File').submenu().getItem('Save').enable();

disable()

Disable a menu item

macgap.menu.getItem('File').submenu().getItem('Save').disable();