• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Dynamic NSPopUpButton in NSToolbar
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Fwd: NSString** in scanners
  • Next by Date: Re: How would you convert a \r to its UTF-8 counterpart ?
  • Previous by thread: Re: NSTextView, style, and weird Core Data issue
  • Next by thread: Re: Dynamic NSPopUpButton in NSToolbar
  • Index(es):
    • Date
    • Thread