7 Commits

Author SHA1 Message Date
Allan Odgaard
1ef78b3af7 Rename symbols to what’s expected by the 10.14 SDK 2019-06-29 20:14:15 +02:00
Allan Odgaard
75624f7df9 Automatically set “allows key equivalents when hidden” for hidden items
This is limited to hidden items that have a key equivalent assigned to them, although if they don’t, there is probably no harm in enabling this option.
2018-11-01 00:16:04 +07:00
Allan Odgaard
4bec98127e Eliminate the optional menu title argument for MBCreateMenu
If a specific title is required, one can simply let the second argument be: [[NSMenu alloc] initWithTitle:«title»]
2018-10-15 06:11:39 +02:00
Allan Odgaard
b37b857096 Support attributes for separators created via MBCreateMenu
This is useful when we want a reference to a separator, e.g. for where to insert dynamic menu items.
2018-10-15 06:11:39 +02:00
Allan Odgaard
da42c3abd3 Let MenuBuilder support setting menu state 2018-06-28 10:40:27 +02:00
Allan Odgaard
e70791ee89 Rename a bunch of constants to fix deprecation warnings (10.12) 2018-06-16 22:55:30 +02:00
Allan Odgaard
6a0e3d8206 Add a menu builder framework
This allows a simple way to build menus in code which can then be used with pop-up buttons or even the main menu of an application.

For creating the main menu, this should be done in an applicationWillFinish: delegate method. If done later, the Open Recent menu will not work.

There is a MBDumpMenu function which will take a menu as argument and output the MBMenu structure required to build the menu in code.

Can be used like this:

    NSLog(@"\n%@", MBDumpMenu(NSApp.mainMenu));

Some caveats:

1. If you have alternate items *without key equivalents* then you need to ensure that `.modifierFlags` is set to include the modifier flags of the previous item plus an additional modifier key (the one to press to reveal this item).

2. The code does not know about outlets so check your MainMenu.nib in Xcode to see if you connect any outlets to menu items or submenus. If so, you can do `.ref = &menuItemOutlet` or `.submenuRef = &menuOutlet`. The former will store a pointer to the menu item in `menuItemOutlet` where the latter will store a pointer to the menu item’s submenu (and ensure a submenu gets created for this item, even if there are no submenu items defined).

3. The code will insert `«unknown»` for any unknown target or delegate, you will need to manually update this (but if you forget, it’ll result in a compiler error).
2018-04-30 15:30:48 +07:00