MacGapProject / MacGap1

Desktop WebKit wrapper for HTML/CSS/JS applications.
Other
3.55k stars 208 forks source link

Menu API Enhancements #116

Closed rawcreative closed 10 years ago

rawcreative commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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