Re: NSTextField TAB-Behaviour Overwriting?
Re: NSTextField TAB-Behaviour Overwriting?
- Subject: Re: NSTextField TAB-Behaviour Overwriting?
- From: Douglas Davidson <email@hidden>
- Date: Mon, 17 Jun 2002 10:21:40 -0700
On Monday, June 17, 2002, at 02:56 AM, Manfred Lippert wrote:
how can I overwrite the TAB-behaviour of an NSTextField?
Currently Option+TAB inserts Tabulator characters and TAB moves the
focus to
the next view.
I want to swap this behaviour, so Tabulator characters can be inserted
with
raw TAB key strokes and Focus can be switched with Option+TAB.
I've done this already with an NSTextView. This was easy: I had to
overwrite
keyDown. But this is not possible for an NSTextField.
Overriding keyDown: is probably the wrong thing to do. You will, for
example, confuse input methods that require these keys. Don't subclass
when you can delegate--in this case, both NSTextView and NSControl
provide suitable delegate methods,
- (BOOL)textView:(NSTextView *)textView
doCommandBySelector:(SEL)commandSelector;
and
- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView
doCommandBySelector:(SEL)commandSelector;
respectively. A standard tab is by default bound to the selector
@selector(insertTab:), while option-tab is bound to
@selector(insertTabIgnoringFieldEditor:). To reverse these, all you
need to do is implement the delegate method, look for either of these,
and if you see one, call the other method on the text view, and return
YES. For example (untested):
- (BOOL)textView:(NSTextView *)textView
doCommandBySelector:(SEL)commandSelector {
BOOL result = NO;
if (commandSelector == @selector(insertTab:)) {
[textView insertTabIgnoringFieldEditor:nil];
result = YES;
} else if (commandSelector ==
@selector(insertTabIgnoringFieldEditor:)) {
[textView insertTab:nil];
result = YES;
}
return result;
}
This seems like a good occasion to repost my standard rant on text view
key handling, so I will do that--in a separate message--and I will also
post my WWDC example on this topic.
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.