Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Intercepting Keys in NSOutlineView Cell Editing

Intercepting Keys in NSOutlineView Cell Editing
Thread Tools
Forum Regular
Join Date: Apr 1999
Location: London, UK
Status: Offline
Reply With Quote
Nov 26, 2002, 05:36 AM
 
I'm trying to create an OutlineView where after editing a cell, I intercept the Cancel, Return and Enter keys to add custom behaviour.

Is this difficult to do? The only way I can think of is to create a subclass of NSOutlineView that uses a custom subclass of NSTextView for cell editing.

Any help appreciated!

Amar
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Nov 26, 2002, 03:20 PM
 
Well, there are two general ways you could do this. Which one is easier or cleaner depends on what keys you want to catch.

If you just want to intercept every keypress, you'll have to use a custom NSText subclass that implements -keyDown: instead of the normal field editor. Getting this subclass to be used requires either setting a special NSCell subclass as the cell for the table column, or implementing the NSWindow delegate method -windowWillReturnFieldEditor:toObject:. The latter is probably a better approach.

If you want to catch keys which have special UI functions (Esc = cancel, Return/Enter = newline, arrows = move cursor, etc.) and care more about the functions than the keys, it's probably easiest to catch those events in the delegate method -control:textView:doCommandBySelector:. By examining the selector you're passed, you can do different things for different standard key actions (like -insertNewline, even if the user has changed their key bindings.

However, it sounds like none of the above may be necessary. If all you want to do is hook into the text field's behavior when the user either confirms or rejects their changes to its contents, there are simpler hooks into that process. See the various didEndEditing, willEndEditing, etc. delegate methods on NSControl for that.
Rick Roe
icons.cx | weblog
     
asagoo  (op)
Forum Regular
Join Date: Apr 1999
Location: London, UK
Status: Offline
Reply With Quote
Nov 27, 2002, 04:00 AM
 
Thanks a lot, Rick!

Sounds like returning a custom editor in -windowWillReturnFieldEditor:toObject: is what I need, as I would like to distinguish between return and enter, for instance. I will have a go at this.

Cheers

Amar
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Nov 27, 2002, 04:17 AM
 
Sounds like returning a custom editor in -windowWillReturnFieldEditor:toObject: is what I need, as I would like to distinguish between return and enter, for instance. I will have a go at this.
Not necessarily. In a method that uses -insertNewline: to identify a Return/Enter event, you could test [NSApp currentEvent] to figure out which of the two keys that generate that event it is. (We've done that in a few places.)
Rick Roe
icons.cx | weblog
     
asagoo  (op)
Forum Regular
Join Date: Apr 1999
Location: London, UK
Status: Offline
Reply With Quote
Nov 27, 2002, 06:11 AM
 
Great, even better!

This is the kind of thing that I think makes Cocoa a bit hard to learn, especially if you come from a more subclassing-based OOP background.
The class structure is "wide" rather than "deep", and classes interact more, which makes finding ways of doing things very hard as a beginner.

Thanks

Amar
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:24 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2