Creating submenus

Tags ( )

Mori Math release 2 is almost ready to go, but I'm having some trouble with the menus.

I want to create a Math menu item in the Text menu and then add the actual menu items to the submenu of Math. Currently I have this working by adding Math the normal way and then adding the submenu using only Cocoa methods, i.e. I avoid blocks. Of course, this isn't really how I'm supposed to be doing it.

I couldn't find an example of this in the Mori source code except for creating autofilled submenus. Can someone give me some hints on how to do this?

Here's code to create a

Here's code to create a submenu, declare that submenu, and then insert an item into the submenu. I'll say again BKMenuControllerProtocol is the hardest part of Blocks to use, so if you have any insites on making this easier and more strait forward let me know :) I'm out of ideas at the moment, but certainly agree that it's not easy to figure out.

- (void)declareMenuItems:(id )menuController {
// 1. create menu item to contain submenu. create submenu. connect submenu to submenu item.
NSMenuItem *submenuItem = [[[NSMenuItem alloc] initWithTitle:@"Example Plugin Submenu Item" action:NULL keyEquivalent:@""] autorelease];
NSMenu *submenu = [[[NSMenu alloc] init] autorelease];
[submenuItem setSubmenu:submenu];

// 2. now insert into blocks and declare submenuItem and submenu so that other items can
// be inserted into the menu. Not doing this step isn't neccessarily wrong, it just means that this
// submenu isn't availible for other plugins to add items too.
[menuController insertMenuItem:submenuItem insertPath:@"/Application/PreferencesGroup"];
[menuController declareMenuItem:submenuItem menuItemPath:@"/Application/SubmenuItem"];
[menuController declareMenu:submenu menuPath:@"/Application/Submenu"];

// 3. now insert a menu into our declared submenu. this step would not be possible if step 2 were skipped.
NSMenuItem *itemInSubmenu = [[[NSMenuItem alloc] initWithTitle:@"Item In Submenu" action:@selector(doNothing:) keyEquivalent:@""] autorelease];
[menuController insertMenuItem:itemInSubmenu insertPath:@"/Application/Submenu/TopGroup"];
[menuController declareMenuItem:itemInSubmenu menuItemPath:@"/Application/Submenu/ItemInSubmenu"];
}

Thanks, that got it

Thanks, that got it working.

I think most of my confusion comes from the paths. I can see why they work (provide a way to add menu items without knowing too much about what other menu items are there, let you get menu items by knowing their path), but I'm not sure they are the best way to accomplish this. I think I'd be much happier if the path structure were hidden from me and I interacted with menus and menu item groups. Perhaps the paths could be automatically generated from menu item titles.

The problem with generating

The problem with generating paths from menu titles is that they will (well when I get off my butt) change, and so become invalid, in localized versions. The Adium source code has a similar problem and solves it with this class:

http://trac.adiumx.com/browser/trunk/Source/AIMenuController.h

The problem being that AIMenuController seems hardcoded with a few specific locations. So I'm not sure that it's design really has the flexibility that Blocks needs. But maybe it will give someone ideas for improving Blocks' implementation.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.