On 9 Jul 2010, at 20:14, Sean McBride wrote:

> Hi all,
> 
> If the user clicks a popup button and reselects the existing selection,
> the button still sends its action.  I'd like to treat that as a nop.
> 
> Is there a way to detect, from my action method, that the new selection
> is the same as the previous selection?
> 

This subclass might cut the mustard:

@interface MGSPopUpButton : NSPopUpButton <NSMenuDelegate> {
        NSMenuItem *prevSelectedItem;
}
- (BOOL)isDuplicateAction;
@end

@implementation MGSPopUpButton

- (void)awakeFromNib
{
        [[self menu] setDelegate:self];
}       
- (void)menuWillOpen:(NSMenu *)menu
{
        prevSelectedItem = [self selectedItem];
}
- (BOOL)isDuplicateAction
{
        return (prevSelectedItem == [self selectedItem]);
}
@end

The action:

- (IBAction)popupAction:(id) sender
{
        if ([(MGSPopUpButton *)sender isDuplicateAction]) {
                NSLog(@"duplicate action");
                return;
        }
        NSLog(@"unique action");
}

Regards

Jonathan
_______________________________________________

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