Dynamic NSPopUpButton in NSToolbar
Dynamic NSPopUpButton in NSToolbar
- Subject: Dynamic NSPopUpButton in NSToolbar
- From: Greg Hoover <email@hidden>
- Date: Wed, 26 Jul 2006 14:18:45 -0700
I'm trying to embed an NSPopUpButton (pull-down) inside of a
NSToolbar. I create the menu, popup button, and return an
NSToolbarItem using the following code:
NSMenu *menu = [[[NSMenu alloc] initWithTitle:@"Groups"] autorelease];
NSMenuItem *newItem = [[[NSMenuItem alloc] initWithTitle:@"Groups"
action:nil keyEquivalent:@""] autorelease];
[menu addItem:newItem];
NSArray *groups = [[[window windowController] appConnection] groups];
newItem = [[[NSMenuItem alloc] initWithTitle:@"All" action:nil
keyEquivalent:@""] autorelease];
[newItem setEnabled:YES];
[menu addItem:newItem];
[menu addItem:[NSMenuItem separatorItem]];
int i;
for (i = 0; i < [groups count]; i++) {
NSString *itemName = [groups objectAtIndex:i];
newItem = [[[NSMenuItem alloc] initWithTitle:itemName action:nil
keyEquivalent:@""] autorelease];
[newItem setEnabled:YES];
[menu addItem:newItem];
}
NSPopUpButton *button = [[NSPopUpButton alloc]
initWithFrame:NSMakeRect(0,0,100,22) pullsDown:YES];
[[button cell] setControlSize:NSSmallControlSize];
[button setFont:[NSFont systemFontOfSize:[NSFont
systemFontSizeForControlSize:NSSmallControlSize]]];
[button setMenu:menu];
item = [[NSToolbarItem alloc] initWithItemIdentifier:@"accounts"];
[item setView:button];
[item setMinSize:NSMakeSize(100,22)];
[item setTarget:[window delegate]];
My problem is that the menu should update dynamically. Is there a
way to force a NSToolbar to recall its toolbarItemForIdentifier so
that the menu is regenerated? Is there another way of achieving the
same goal?
Thank you.
-Greg
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden