On Wed, 4 Nov 2009 11:26:16 -0500, Eric Gorr <[email protected]> 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.


-- 
matt neuburg, phd = [email protected], <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.tidbits.com/matt/default.html#applescriptthings



_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to