Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSWindow, press key ENTER: how to limit the key listening to the focused NSControl?

I have an NSWindow with a main "OK" button. This button has as "key equivalent" property in interface builder, the key ENTER i.e .

It works good, but now I have a new NSComboBox, which is supposed to invoke a method when the user selects a list item, or he preses Enter / .

However, when I press Enter, the main Button receive the notification and the window close. How to prevent this?

like image 488
aneuryzm Avatar asked Sep 29 '22 07:09

aneuryzm


1 Answers

This is the normal behavior what you are getting, but you can hack a bit, by removing and adding the key-equivalent.

Add following delegates of NSComboBox:

- (void)comboBoxWillPopUp:(NSNotification *)notification;{
    [self.closeButton setKeyEquivalent:@""];
}


- (void)comboBoxWillDismiss:(NSNotification *)notification;{
    [self.closeButton setKeyEquivalent:@"\r"];
}
like image 127
Anoop Vaidya Avatar answered Oct 03 '22 06:10

Anoop Vaidya