FROM : Jerry Krinock
DATE : Mon Feb 04 00:30:36 2008
I've implemented the following method in my NSTableView subclass which
makes the 'return' key begin editing, like Finder does. It works, but
I don't like that hard-coded keycode 0xd for 'carriage return'.
Is there a better way to do this? I tried to implement -
insertNewline:, but it never gets invoked.
Thanks,
Jerry Krinock
- (void)keyDown:(NSEvent*)event {
NSString *s = [event charactersIgnoringModifiers] ;
unichar keyChar = 0 ;
BOOL didDo = NO ;
if ([s length] == 1) {
keyChar = [s characterAtIndex:0] ;
if (keyChar == 0xd) {
// Unless editing is already in process, which is not the
// case we're trying to handle here, an entire row will
// be selected and therefore [self selectedColumn] will
// be the "no selection" indicator, -1. So, we edit column
// 0. If the user wants a different column, they can
// easily tab to it.
[self editColumn:0
row:[self selectedRow]
withEvent:nil
select:YES] ;
didDo = YES ;
}
}
if (!didDo) {
[super keyDown:event] ;
}
}
DATE : Mon Feb 04 00:30:36 2008
I've implemented the following method in my NSTableView subclass which
makes the 'return' key begin editing, like Finder does. It works, but
I don't like that hard-coded keycode 0xd for 'carriage return'.
Is there a better way to do this? I tried to implement -
insertNewline:, but it never gets invoked.
Thanks,
Jerry Krinock
- (void)keyDown:(NSEvent*)event {
NSString *s = [event charactersIgnoringModifiers] ;
unichar keyChar = 0 ;
BOOL didDo = NO ;
if ([s length] == 1) {
keyChar = [s characterAtIndex:0] ;
if (keyChar == 0xd) {
// Unless editing is already in process, which is not the
// case we're trying to handle here, an entire row will
// be selected and therefore [self selectedColumn] will
// be the "no selection" indicator, -1. So, we edit column
// 0. If the user wants a different column, they can
// easily tab to it.
[self editColumn:0
row:[self selectedRow]
withEvent:nil
select:YES] ;
didDo = YES ;
}
}
if (!didDo) {
[super keyDown:event] ;
}
}
| Related mails | Author | Date |
|---|---|---|
| Jerry Krinock | Feb 4, 00:30 | |
| Ricky Sharp | Feb 4, 00:37 | |
| Jerry Krinock | Feb 4, 19:33 |






Cocoa mail archive

