building a lazy NSMenu
building a lazy NSMenu
- Subject: building a lazy NSMenu
- From: Jesse Grosjean <email@hidden>
- Date: Thu, 29 Jan 2004 11:37:34 -0500
I'm trying to dynamically build a menu in a lazy fashion. I know how to
build a menu dynamically, but I only know how to build it all at once
this way. If the menu may have many many items then building the whole
thing at once takes to much time and space. For instance if I want to
make a menu that mirrors the file system then building it all at once
is not the way to do things.
So instead I'll like to build it only as the users traverses it. So
when the menu is first shown I will just show the files listed in the
root directory. And for the menu items that represent folders in the
root directory i'll add empty submenus... and these submenus should not
be populated until they are actually show.
Right now I'm trying to accomplish this by subclassing NSMenuItem. My
goal is for this code to create an infinite number of submenus, but
only on an ass needed basis. But right now it crashes when some
internal cocoa method "_flattenMenu" tries to traverse the entire
structure.
- (NSMenu *)submenu {
NSMenu *submenu = [super submenu];
if ([submenu numberOfItems] == 0) {
[submenu addItemWithTitle:@"no submenu" action:@selector(wow:)
keyEquivalent:@""];
[submenu addItemWithTitle:@"no submenu 2" action:@selector(wow:)
keyEquivalent:@""];
NSMenuItem *branchItem = [[[NBOutlineMenuItem alloc] init] autorelease]
NSMenu *branchSubmenu = [[[NSMenu alloc] init] autorelease];
[branchItem setTitle:NSLocalizedString(@"Branch", @"")];
[submenu setSubmenu:branchSubmenu forItem:branchItem];
[submenu addItem:branchItem];
}
return submenu;
}
Can anyone suggest how best to accomplish this?
Thanks,
Jesse
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.