-
Notifications
You must be signed in to change notification settings - Fork 8
/
NoReturnEditTableView.m
31 lines (26 loc) · 1.24 KB
/
NoReturnEditTableView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#import "NoReturnEditTableView.h"
/*!
* A table view that ends editing when the Return key is pressed, instead of moving
* to the next cell down. The Tab key still moves across the row.
*/
@implementation NoReturnEditTableView
- (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:NSOtherTextMovement] 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];
}
}
@end