Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Chirone

macrumors 6502
Original poster
Mar 2, 2009
279
0
NZ
I have a NSTextView and I want something to happen when a button is pushed. That's a very trivial task to do...
I also want it so when someone hits shift+return the selector the button triggers get used.
how would i do that?
 
i imagine if the textview could actually give up it's focus that would work

but shift+return just makes new lines in the nstextview
 
If you want to handle it directly within the NSTextView, you can override insertNewline: in an NSTextView subclass:

Code:
- ([color=#aa0d91]void[/color])insertNewline:([color=#aa0d91]id[/color])sender
{
    [color=#aa0d91]if[/color] ([[[[color=#aa0d91]self[/color] [color=#2e0d6e]window[/color]] [color=#2e0d6e]currentEvent[/color]] [color=#2e0d6e]modifierFlags[/color]] & [color=#2e0d6e]NSShiftKeyMask[/color]) {
        [color=#007400]// do something[/color]
    } [color=#aa0d91]else[/color] {
        [[color=#aa0d91]super[/color] [color=#2e0d6e]insertNewline[/color]:sender];
    }
}
 
works perfectly!
thanks!

the insertNewline: function doesn't appear to be in the documentation...
 
the insertNewline: function doesn't appear to be in the documentation...

NSTextView is a very complex and elaborate class. If you need to implement a behavior, you can look for a vector (method to override) in its superclasses and protocols (when the docs say an object conforms to a protocol, you can expect that it at least implements the required methods for that protocol). In this case, the method in question is in NSResponder.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.