Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu API Enhancements #116

Merged
merged 1 commit into from
May 17, 2014
Merged

Menu API Enhancements #116

merged 1 commit into from
May 17, 2014

Conversation

rawcreative
Copy link
Member

Adds additional functionality and flexibility to the menu API as well as fixing #110

Changes

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

The index parameter is optional for both root level and submenus, excluding it will add the menu item to the end of the menu.

Additions

removeMenu(ID)

Added removeMenu shortcut which now allows:

macgap.menu.removeMenu('File');

instead of the more verbose

macgap.menu.getItem('File').remove(). 

MenuItemProxy now uses this method to remove items as well.

enable() & disable()

Added enable() and disable() methods to MenuItemProxy which allows for enabling and disabling menu items via js

// Disable the Save menu item
macgap.menu.getItem('File').submenu().getItem('Save').disable();

// Enable the Save menu item
macgap.menu.getItem('File').submenu().getItem('Save').enable();

I debated removing the need to use .submenu() and instead return the submenu automatically when calling getItem() but decided to keep it in for now as it would remove the ability to change the title/accelerator keys and callbacks for the root level menu items unless additional methods were implemented to deal with those.

Ideally I'd like to make creating/editing menus much easier by passing a simply JS object with the desired menu configuration but doing so would require writing a ton of C code to parse the object and it just doesn't seem to be worthwhile to do for the time being. It can easily be done with the 10.9 JavascriptCore api so it may be something to look into for the MacGapNode project.

jeff-h added a commit that referenced this pull request May 17, 2014
@jeff-h jeff-h merged commit 58d52f6 into MacGapProject:master May 17, 2014
@jeff-h
Copy link
Member

jeff-h commented May 17, 2014

Awesome!

I've taken your notes on this and put them into the wiki.

The good stuff in 10.9 is a little frustrating; I'd be interested to know just how big a deal pre-10.9 compatibility is though, especially now that:

a) it's a free upgrade

b) it's been out for a year

c) every Mac released in the past 5-7 years can run it (See here).

Anyway, thanks for your work on this.

@rawcreative
Copy link
Member Author

I think for now pre 10.9 compat is a must-have, at least until 10.10 is released later this year. Reason being, 10.9 really isn't one of those updates with alot of 'must-have' features (for average users) and alot of people just haven't bothered to upgrade. My main dev machine is still running ML, not so much for dev/testing/compat purposes, but simply because it boots from an external SSD which is a PITA to upgrade, and I just haven't had the time to spend half a day messing with it.

I think once 10.10 is released you'll see alot of people ditch 10.8 and either upgrade to 10.10 or 10.9. This will probably happen once alot of App store apps start using the new features in 10.9 and whatever is introduced in 10.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants