Reputation: 81
In my app I display a sheet with an NSComboBox in it. If the user uses the arrow keys to choose an entry from the menu and then Return to select it the sheet's OK button is also actioned, as it has Return as its key equivalent. I'd like to stop these Return keys acting as OK clicks.
After trying lots of things (apart from subclassing NSComboBox which started turning into a nightmare) I'm trying to ignore OK clicks if the combo box is the first responder and the current event is a return key key-up, but the NSPanel that the sheet is subclassed from always returns itself as the current first responder. I was expecting a field editor but all I get is the NSPanel.
1) Is there a better way of doing this? The user REALLY wants keyboard based data entry rather than mousing around.
2) If this is the best way, how can I tell that the combo box is the first responder?
Any help gratefully accepted. Surely this has been dealt with before?
Rev. Andy
Upvotes: 1
Views: 400
Reputation: 670
There is a workaround, its not pretty but it will work:
Register for both notifications NSComboBoxWillPopUpNotification and NSComboBoxWillDismissNotification.
- (void)comboBoxWillPopUp:(NSNotification *)notification
{
okButton.keyEquivalent = @"";
}
- (void)comboBoxWillDismiss:(NSNotification *)notification
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0), dispatch_get_main_queue(), ^{
okButton.keyEquivalent = @"\r";
});
}
Upvotes: 1