Menu proposals

3 views
Skip to first unread message

Chris Granger

unread,
Jun 26, 2013, 12:41:20 PM6/26/13
to node-...@googlegroups.com
I'm looking into using node-webkits menus more extensively in Light Table and have found some issues that I'm happy to try and fix myself, but wanted to get some feedback on how we should design the solutions.

For one, I wanted to change the mac menus such that instead of adding the standard menus by default, you have pre-built menuitems that you can add to the menubar if you choose to. This would allow you to manipulate those default menus and prevents the issue where if you set the menu on a window twice it will duplicate those builtins. In order to do this, however, we'll need to expose some functionality that is specific to Mac and I'm not sure what @rogerwang's plan is for platform specific helpers. Another thing that will have to be added to support this is the ability to set accelerator keys. On OSX this is pretty straightforward, but it wasn't obvious how you do that on the windows/linux side of things.

Another enhancement is that I want to be able to set a menu and potentially remove the menu later. I've implemented it right now that if you pass null when setting a menu on a window it removes it - I don't think we need an explicit API for this one.

Thoughts?

Cheers,
Chris.

Trevor Linton

unread,
Jun 26, 2013, 1:26:15 PM6/26/13
to node-...@googlegroups.com
I've already implemented a change to node-webkit that allows you to modify the default apple menus.

The application starts with the default menu, you can grab the current menu in macosx then modify it and reset it.  It adds a new property to menuitem called selector thats only valid in macosx that calls a default macosx behavior (only about 15 have been implemented).  You can also override selector behaviors with onclick.  

This allows you modify the app menu, edit, window, etc.. I should note if you do decide to override selectors for menu items the behavior of the application can become unstable (e.g., if you override copy/paste/select your code becomes responsible for these calls).  Use at your own risk. 

Roger

unread,
Jun 26, 2013, 9:18:39 PM6/26/13
to Chris Granger, node-...@googlegroups.com
Chris Granger <ibd...@gmail.com> writes:

> In order to do this, however, we'll need to expose some functionality
> that is specific to Mac and I'm not sure what @rogerwang's plan is for
> platform specific helpers.

Welcome the contribution :) Platform specific code are OK as long as
it's implementing platform specific feature, or it has to be implemented
on all the 3 platforms before merging into master.
--
Roger

Chris Granger

unread,
Jun 26, 2013, 9:25:04 PM6/26/13
to node-...@googlegroups.com
Here's what I just did: https://github.com/Kodowa/node-webkit/compare/menus

The basic gist is that if you don't set a menu you get the same default menus you have now. If you do set one, you must explicitly add those menus yourself (which I think is the reasonable solution, trying to modify provided menus seems like more effort than it's probably worth).

@trevor - I think this is a bit cleaner, instead of trying to enumerate the possible selectors.

Cheers,
Chris.



--
You received this message because you are subscribed to the Google Groups "node-webkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-webkit...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Chris Granger

unread,
Jun 26, 2013, 9:26:42 PM6/26/13
to node-...@googlegroups.com
Forgot to mention that this also adds in the ability to specify the modifiers and accelerator key so you can accurately replicate the menus. If anyone wants to figure out how to do that for windows/linux that would be wonderful - I still haven't managed to get builds working on either of those.

Cheers,
Chris.

Trevor Linton

unread,
Jun 27, 2013, 1:28:14 PM6/27/13
to node-...@googlegroups.com
@Chris

I completely agree, very clean. How did you get the NSSelectorFromString working on versions prior to 0.6 and on Mountain Lion? I tried that approach but it botched on Mountain Lion with a reference error and locked up. Thus wrapping the if/then statements and having to target specific targets for the action rather than having OSX find an optimal match for the target.

Chris Granger

unread,
Jun 27, 2013, 1:38:08 PM6/27/13
to node-...@googlegroups.com
@Trevor did you change the target for the selectors? If you don't it tries to send it to the menu_item_delegate instead of whatever the default handler is. With that it'd blow up all over the place saying that the methods aren't available. I work on Mountain Lion and it seems all good there :)

Cheers,
Chris.

Roger Wang

unread,
Mar 26, 2014, 3:25:33 AM3/26/14
to node-...@googlegroups.com, Chris Granger
Hi Chris,

I'm looking to complete this feature on Win and Linux. Would you please create a PR for your work on OSX?

Thanks in advance.

Roger
Reply all
Reply to author
Forward
0 new messages