forked from rentzsch/SafariSessionSaver
/
NSTableView+CocoaBindingsDeleteKey.m
executable file
·37 lines (34 loc) · 1.17 KB
/
NSTableView+CocoaBindingsDeleteKey.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
32
33
34
35
36
37
#import <Cocoa/Cocoa.h>
@interface NSTableViewPlusCocoaBindingsDeleteKey : NSTableView {}
@end
@implementation NSTableViewPlusCocoaBindingsDeleteKey
+ (void)load {
[NSTableViewPlusCocoaBindingsDeleteKey poseAsClass:[NSTableView class]];
}
- (void)keyDown:(NSEvent*)event_ {
NSString *eventCharacters = [event_ characters];
if ([eventCharacters length]) {
switch ([eventCharacters characterAtIndex:0]) {
case NSDeleteFunctionKey:
case NSDeleteCharFunctionKey:
case NSDeleteCharacter: {
NSArray *columns = [self tableColumns];
unsigned columnIndex = 0, columnCount = [columns count];
NSDictionary *valueBindingDict = nil;
for (; !valueBindingDict && columnIndex < columnCount; ++columnIndex) {
valueBindingDict = [[columns objectAtIndex:columnIndex] infoForBinding:@"value"];
}
if (valueBindingDict && [[valueBindingDict objectForKey:@"NSObservedObject"] isKindOfClass:[NSArrayController class]]) {
// Found a column bound to an array controller.
[[valueBindingDict objectForKey:@"NSObservedObject"] remove:self];
} else {
[super keyDown:event_];
}
} break;
default:
[super keyDown:event_];
break;
}
}
}
@end