Re: NSTableView : editable cells & return key
Re: NSTableView : editable cells & return key
- Subject: Re: NSTableView : editable cells & return key
- From: Kurt Revis <email@hidden>
- Date: Wed, 16 Jan 2002 15:51:17 -0800
On Wednesday, January 16, 2002, at 03:36 PM, Bruno Blondeau wrote:
I'm using a NSTableView which text cells are user-editable.
However, when a user presses the return key, the edit field moves to the
next row, which is not the behavior a Mac user expects from most
applications. (the row should remain selected, not select the next row
and
start editing it).
This question has come up many times before on this list; I recommend
checking the archives.
Anyway, here's what I use. (I admit that I can't remember if this was
the "best" way or not.) Subclass NSTableView and override this method:
- (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;
NSNotification *newNotification;
newUserInfo = [NSMutableDictionary
dictionaryWithDictionary:[notification userInfo]];
[newUserInfo setObject:[NSNumber
numberWithInt:NSIllegalTextMovement] forKey:@"NSTextMovement"];
newNotification = [NSNotification
notificationWithName:[notification name] object:[notification object]
userInfo:newUserInfo];
[super textDidEndEditing:newNotification];
// For some reason we lose firstResponder status when when we do
the above.
[[self window] makeFirstResponder:self];
} else {
[super textDidEndEditing:notification];
}
}
--
Kurt Revis
email@hidden