Preventing textfield in table from clicking default button
Preventing textfield in table from clicking default button
- Subject: Preventing textfield in table from clicking default button
- From: Seth Willits <email@hidden>
- Date: Sat, 16 Aug 2014 19:53:19 -0700
When editing in a NSTextField and return is pressed, it fires the text field's action and also sends performKeyEquivalent: to the window, which clicks the default button. Usually that's just fine, but in the case where a view-based table view has editable NSTextFields in it, this makes no sense.
Anybody figured out how to prevent this?
---
It happens in NSTextField textDidEndEditing, so there's no stopping performKeyEquivalent: from being called short of subclassing NSTextField and reimplementing that method. (Eww)
You also can't disable the key equivalent on the button in controlTextDidBeginEditing and re-enable it in controlTextDidEndEditing, because the performKeyEquivalent: is called after the controlTextDidEndEditing notification is sent.
I thought maybe I could so some light NSTExtField subclassing and use NSWindow's disableKeyEquivalentForDefaultButtonCell...
@implementation MyTableCellTextField
- (void)textDidBeginEditing:(NSNotification *)notification;
{
[self.window disableKeyEquivalentForDefaultButtonCell];
[super textDidBeginEditing:notification];
}
- (void)textDidEndEditing:(NSNotification *)notification;
{
[super textDidEndEditing:notification];
[self.window enableKeyEquivalentForDefaultButtonCell];
}
@end
Sadly, that doesn't work. My default button is still clicked when [super textDidEndEditing:] calls performKeyEquivalent:, despite the defaultButtonCell being the right button… As a matter of fact, looking at the implementation of those NSWindow methods shows they're identical to each other… which makes absolutely no sense. So obviously that doesn't do what one would expect.
This is leaving me little choice but to do something very specialized and ugly.
Am I missing something?
--
Seth Willits
_______________________________________________
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