Re: Detecting 'nop' clicks on an NSPopUpButton?
Re: Detecting 'nop' clicks on an NSPopUpButton?
- Subject: Re: Detecting 'nop' clicks on an NSPopUpButton?
- From: "email@hidden" <email@hidden>
- Date: Sat, 10 Jul 2010 11:54:21 +0100
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 (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