I have a situation where I need to enter text into a text field, but another user may press some other buttons on the same window (using keyboard commands) while I’m in the middle of typing, and I need it not to interfere with my text field data entry. The text field is set as first responder, and it holds focus when I press other normal momentary buttons (via keyboard commands), but if I press a radio button (via a keyboard command) I lose focus on the text field. Is there a way to prevent this? What’s interesting is if I just click on the radio button with the mouse, instead of using the key command, the text field focus is maintained. I also seem to lose the ability to tab between my text fields after I have pressed one of the radio buttons (via a keyboard command). Perhaps there is something wrong with the way I’m doing the keyboard assignments? The radio buttons seem to behave differently depending on if I click with a mouse, or use the keyboard shortcut. If I click on them, I keep my text field focus and can tab between text fields, but if I use a keyboard command, I lose focus and can no longer tab between them. The workaround of simply re-issuing the first reponder command with the onClicked won’t work because the text field comes up selected, and I’d lose everything I just typed up to that point if I’m in the middle of typing. Thanks so much for any advice. Hopefully it’s possible.
The same method wouldn’t succeed with a text field since it uses it’s window’s field editor for editing. For a solution a custom field editor was needed as far as I can see …
Sorry, my mistake - I should have written ‘override’ not ‘overwrite’. To override a method of a subclasses’ super class you just write an identically named method in the subclass.
In my example your MYSubclass.m file should look like this:
Ok, got that to work, thanks so much, but now is there any way to retain the “OnAction” when I hit enter in the text view? It looks like text views don’t work that way…
Is there a way to have an action on “enter” with a text view the way a text field can? I was using on button down, but I discovered a flaw in the way I’m implementing it, and having the action run on enter is much better. I hope it is possible…
it’s probably possible to influence a text view’s behaviour to simulate a text field but I think I might have found a better solution for you - using text fields as you requested at first (sorry - I haven’t thought of this when answering the first time …)
My idea is simple - instead of letting the matrix refuse it’s first responder status (which will mean that the field editor already has lost it’s first responder status) we use a subclass of NSWindow that refuses to switch the first responder to your matrix.
But - this solution has two limitations:
text fields and matrix have to be in the same window
and the behaviour will affect all text fields of that window
would that be ok for your project? Then this could be the solution:
BRILLIANT!!! Exactly what I needed. Everything is indeed in the same window, and I really just wanted to take the matrix out as a first responder so this did the trick. Thanks SO much.