• 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
Re: Dynamic NSPopUpButton in NSToolbar
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Dynamic NSPopUpButton in NSToolbar
      • From: Andreas Mayer <email@hidden>
  • Prev by Date: Re: NSTextView, style, and weird Core Data issue
  • Next by Date: Re: How do I pattern an image in a view w/o "scrolling"?
  • Previous by thread: Dynamic NSPopUpButton in NSToolbar
  • Next by thread: Re: Dynamic NSPopUpButton in NSToolbar
  • Index(es):
    • Date
    • Thread