Re: NSPopUpButton, Bindings & separator items
Re: NSPopUpButton, Bindings & separator items
- Subject: Re: NSPopUpButton, Bindings & separator items
- From: Eric Gorr <email@hidden>
- Date: Wed, 4 Nov 2009 15:42:05 -0500
On Nov 4, 2009, at 3:38 PM, Matt Neuburg wrote:
On Wed, 4 Nov 2009 11:26:16 -0500, Eric Gorr <email@hidden>
said:
I found this old message, but there was no answer posted and have the
same question...
http://lists.apple.com/archives/cocoa-dev/2005/Jan/msg00886.html
Is there a way to add separator Items to an NSPopUpButton using
bindings?
Here's an easy way; this is how I do it in my NotLight app.
First, #define MYMENUSEPARATORSTRING somewhere where everyone who
needs to
can see it.
Now, subclass NSMenu and override as follows:
- (id <NSMenuItem>)addItemWithTitle:(NSString *)aString
action:(SEL)aSelector
keyEquivalent:(NSString *)keyEquiv {
if ([aString isEqual: MYMENUSEPARATORSTRING]) {
id <NSMenuItem> sep = [NSMenuItem separatorItem];
[self addItem:sep];
return sep;
}
return [super addItemWithTitle:aString action:aSelector
keyEquivalent:keyEquiv];
}
Now use that NSMenu subclass where needed. The bound object uses
addItemWithTitle to construct the menu, so our overridden method
will be
called and a separator item will appear wherever MYMENUSEPARATORSTRING
occurs as the title in the bound content. m.
Cool. That looks like a good solution.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden