On Nov 4, 2009, at 3:38 PM, Matt Neuburg wrote:

On Wed, 4 Nov 2009 11:26:16 -0500, Eric Gorr <mail...@ericgorr.net> 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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to