Re: Dynamic NSPopUpButton in NSToolbar
Re: Dynamic NSPopUpButton in NSToolbar
- Subject: Re: Dynamic NSPopUpButton in NSToolbar
- From: Greg Hoover <email@hidden>
- Date: Thu, 27 Jul 2006 16:33:54 -0700
For anyone interested in the solution to this, I managed to solve the
problem by removing the item from the toolbar and re-inserting it.
This causes the toolbar to call the toolbarItemForIdentifier method
again which creates the dynamic menu.
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