Re: Intercepting Some Keyboard Events for NSTextView
Re: Intercepting Some Keyboard Events for NSTextView
- Subject: Re: Intercepting Some Keyboard Events for NSTextView
- From: Douglas Davidson <email@hidden>
- Date: Mon, 15 Jul 2002 10:48:20 -0700
On Monday, July 15, 2002, at 10:26 AM, John Nairn wrote:
I will try the NSApp method, although I also found another solution.
Although I could not create a custom class for NSTextView in Interface
Builder, I found an example in "Cocoa Programming for Mac OS X
(Hillegass) of subclassing NSTextView when the nib file opens. It has
some nice features such as I can override commands (which after some
testing) worked with
- (void)cancel:(id)sender
- (void)insertNewline:(id)sender
and so on. I can also insert a keyDown method here and act on keys or
pass on to super if needed. I can do all I need, but will this have the
same problems you mentioned below (i.e. swallowing something the input
manager wants)?
Finally, if subclassing NSTextView is a good idea, how come it can not
be done in Interface Builder?
Subclassing NSTextView is good and necessary for certain things, but it
should not be your first resort; delegation should be considered first
and used where appropriate. Subclassing NSTextView is certainly
possible in Interface Builder, although it is not as easy as it could
be; this is not deliberate, it arose from some limitations in the AppKit.
If you do end up subclassing NSTextView, overriding insertNewline:,
cancel:, etc. is fine. The dangerous one is keyDown:, which
unfortunately people tend to want to override first. You can look in
the mailing list archives for my previous posts on this topic, which
describe the path that key events take in the text system.
Douglas Davidson
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.