Re: Home and end keys and NSTableView, not handled automatically?
Re: Home and end keys and NSTableView, not handled automatically?
- Subject: Re: Home and end keys and NSTableView, not handled automatically?
- From: "Sean McBride" <email@hidden>
- Date: Fri, 17 Sep 2004 13:55:55 -0400
Matt Neuburg (email@hidden) on Fri, Sep 17, 2004 12:25 said:
>>So I'm trying to make home/end work in the 'right' way....
>
>I'm not quite clear what the big deal is here. I simply catch
>NSHomeFunctionKey and NSEndFunctionKey and call scrollRowToVisible:. Maybe
>this isn't the "right" way but it took two minutes to write the code, it
>worked, and I just went on to something else. m.
Fair enough. But since you asked, I'm merely trying to make my app the
best I can, and, last time I checked, sweating the details was a good
thing, plus it helps me learn more about Cocoa. Also, there are several
Cocoa bugs here, so the better I understand them, the better my bug
reports will be.
My code is currently doing basically what you said above, but I learnt in
this thread (thanks Allan Odgaard) that the problem is that it works by
testing for a specific physical key. If a user has changed their key
bindings the code can do the wrong thing.
So my thought was to implement scrollToBeginningOfDocument: and
scrollToEndOfDocument: (which are in the key bindings plist,
Defaultkeybidnings.dict, but apparently missing from the NSResponder
docs/headers) in my NSTableView subclass. Then implement keyDown as
described in the docs:
"pass the event to Cocoa's text input management system by invoking the
interpretKeyEvents: method. The input management system checks the
pressed key against entries in all relevant key-binding dictionaries and,
if there is a match, sends a doCommandBySelector: message back to the view"
That is,
- (void)keyDown:(NSEvent*)event
{
[self interpretKeyEvents:[NSArray arrayWithObject:event]];
}
- (void)scrollToBeginningOfDocument:(id)sender
{
[self scrollRowToVisible:0];
}
- (void)scrollToEndOfDocument:(id)sender
{
[self scrollRowToVisible:[self numberOfRows]-1];
}
And now home/end work! Alas, page up/down, arrow keys, etc. no longer
work. :( I'm trying to understand why...
The docs say "If you implement keyDown: to send interpretKeyEvents: to
the input manager but do not implement the scrollPageDown: action method,
the document view will still be scrolled within the scroll view when the
user presses the Page Down key (or whatever key binding is in effect for
that function). This happens because each next responder in the responder
chain is queried to see if it responds to scrollPageDown:. The
NSScrollView class provides a default implementation, so this
implementation is invoked."
Any ideas? Thanks.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden