Skip navigation.
 
mlDynamic NSPopUpButton in NSToolbar
FROM : Greg Hoover
DATE : Wed Jul 26 23:18:45 2006

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

Related mailsAuthorDate
mlDynamic NSPopUpButton in NSToolbar Greg Hoover Jul 26, 23:18
mlRe: Dynamic NSPopUpButton in NSToolbar Greg Hoover Jul 28, 01:33
mlRe: Dynamic NSPopUpButton in NSToolbar Andreas Mayer Jul 28, 02:00