Re: How to end table cell editing by keyboard (return/enter)?
Re: How to end table cell editing by keyboard (return/enter)?
- Subject: Re: How to end table cell editing by keyboard (return/enter)?
- From: Ondra Cada <email@hidden>
- Date: Mon, 4 Jul 2005 05:11:56 +0200
Joern,
On 3.7.2005, at 16:18, email@hidden wrote:
I have a NSTableView setup with a NSTableColumn which consists of
the default NSTextFieldCell. The table is populated using a
NSArrayController (bindings). I allow editing of the entries in the
column via double click and (in another case) sending
editColumn:row:withEvent:select: to the table view.
What I want: Editing a cell and pressing return ends the editing,
setting the selection to the edited entry. Best case: the app/
controller/whatever gets notified about this event.
The impossibility to do this cleanly is, far as I know, one of a
surprisingly small number of faults in the Cocoa-based GUI.
Of course, in a dynamic object system anything goes, albeit sometimes
kinda ugly way :)
The solution looks kind of like this (it's possible there's a better
one: this one used to be arguably the best available a few years ago
-- meantime API was improved, *perhaps* making this hack obsolete):
@interface OCSExtraSelectionTableView:NSTableView @end
@implementation OCSExtraSelectionTableView
// changes the editing behaviour NOT to select the next line if Enter
gets pressed
-(void)textDidEndEditing:(NSNotification*)notification {
if ([[[notification userInfo] objectForKey:@"NSTextMovement"]
intValue]==NSReturnTextMovement) {
// This is ugly, but just about the only way to do it.
NSTableView is determined to select and edit something else, even the
text field that it just finished editing, unless we mislead it about
what key was pressed to end editing.
NSMutableDictionary *newUserInfo=[NSMutableDictionary
dictionaryWithDictionary:[notification userInfo]];
[newUserInfo setObject:[NSNumber
numberWithInt:NSIllegalTextMovement] forKey:@"NSTextMovement"];
[super textDidEndEditing:[NSNotification
notificationWithName:[notification name] object:[notification object]
userInfo:newUserInfo]];
// For some reason we lost firstResponder status when when
we did the above.
[[self window] makeFirstResponder:self];
} else [super textDidEndEditing:notification];
}
+(void)load {
[self poseAsClass:[self superclass]];
}
@end
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
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