blob: 9fa66f6a6fcd44f7af7d15274e15e2470d0df363 (
plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
#import "LiTableView.h"
@implementation LiTableView
+ (void)load
{
[self poseAsClass: [NSTableView class]];
}
- methodSignatureForSelector: (SEL)aSelector
{
id signature;
signature = [super methodSignatureForSelector: aSelector];
if (signature == nil) {
NSString *selString;
selString = NSStringFromSelector(aSelector);
if ([selString isEqualToString: @"validateMenuItem:"]) {
signature = [[self delegate] methodSignatureForSelector: @selector(validateMenuItem:)];
} else if ([selString isEqualToString: @"delete:"]) {
if ([self isKindOfClass: [NSOutlineView class]])
signature = [[self dataSource] methodSignatureForSelector: @selector(deleteSelectedRowsInOutlineView:)];
else
signature = [[self dataSource] methodSignatureForSelector:
@selector(deleteSelectedRowsInTableView:)];
} else if ([[self delegate] respondsToSelector: aSelector])
signature = [[self delegate] methodSignatureForSelector: aSelector];
}
return signature;
}
- (void)forwardInvocation: (NSInvocation *)anInvocation
{
NSString *selString;
selString = NSStringFromSelector([anInvocation selector]);
if ([selString isEqualToString: @"validateMenuItem:"]) {
[anInvocation setTarget: [self delegate]];
[anInvocation invoke];
} else if ([selString isEqualToString: @"delete:"]) {
[anInvocation setTarget: [self dataSource]];
if ([self isKindOfClass: [NSOutlineView class]]) {
[anInvocation setSelector: @selector(deleteSelectedRowsInOutlineView:)];
} else {
[anInvocation setSelector: @selector(deleteSelectedRowsInTableView:)];
}
[anInvocation setArgument: &self atIndex: 2];
[anInvocation invoke];
} else if ([[self delegate] respondsToSelector: [anInvocation selector]]) {
[anInvocation setTarget: [self delegate]];
[anInvocation invoke];
} else
[super forwardInvocation: anInvocation];
}
- (BOOL)respondsToSelector: (SEL)aSelector
{
NSString *selString;
if ([super respondsToSelector: aSelector])
return YES;
selString = NSStringFromSelector(aSelector);
if ([selString isEqualToString: @"validateMenuItem:"]) {
return [[self delegate] respondsToSelector: aSelector];
} else if ([selString isEqualToString: @"delete:"]) {
if ([self isKindOfClass: [NSOutlineView class]]) {
return [[self dataSource] respondsToSelector:
@selector(deleteSelectedRowsInOutlineView:)];
} else {
return [[self dataSource] respondsToSelector: @selector(deleteSelectedRowsInTableView:)];
}
}
return [[self delegate] respondsToSelector: aSelector];
}
- (void)keyDown: (NSEvent *)theEvent
{
NSString *keyString;
unichar keyChar;
keyString = [theEvent charactersIgnoringModifiers];
keyChar = [keyString characterAtIndex: 0];
switch (keyChar) {
case 0177: // Delete Key
case NSDeleteFunctionKey:
case NSDeleteCharFunctionKey: {
SEL selector;
if ([self isKindOfClass: [NSOutlineView class]]) {
selector = @selector(deleteSelectedRowsInOutlineView:);
} else {
selector = @selector(deleteSelectedRowsInTableView:);
}
if ([self selectedRow] >= 0 &&
[[self dataSource] respondsToSelector: selector]) {
[[self dataSource] performSelector: selector
withObject: self];
}
break;
} default:
[super keyDown: theEvent];
}
}
- (BOOL)becomeFirstResponder
{
BOOL rc;
rc = [super becomeFirstResponder];
if (rc == YES) {
SEL selector;
if ([self isKindOfClass: [NSOutlineView class]])
selector = @selector(outlineViewDidBecomeFirstResponder:);
else
selector = @selector(tableViewDidBecomeFirstResponder:);
if ([[self delegate] respondsToSelector: selector])
[[self delegate] performSelector: selector
withObject: self];
}
return rc;
}
- (void)mouseDown: (NSEvent *)theEvent
{
if ([[self delegate] respondsToSelector: @selector(mouseDownEvent:)])
[[self delegate] performSelector: @selector(mouseDownEvent:)
withObject: theEvent];
[super mouseDown: theEvent];
}
- (unsigned int)draggingSourceOperationMaskForLocal: (BOOL)isLocal
{
if (isLocal)
return NSDragOperationPrivate;
else
return NSDragOperationCopy | NSDragOperationLink | NSDragOperationGeneric;
}
- (void)textDidEndEditing: (NSNotification *)aNotification
{
int keyPressed;
keyPressed = [[[aNotification userInfo] objectForKey: @"NSTextMovement"] intValue];
if (keyPressed == NSReturnTextMovement) {
NSMutableDictionary *newUserInfo;
NSNotification *newNotification;
newUserInfo = [NSMutableDictionary dictionaryWithDictionary:
[aNotification userInfo]];
[newUserInfo setObject: [NSNumber numberWithInt:0]
forKey: @"NSTextMovement"];
newNotification = [NSNotification notificationWithName: [aNotification name]
object: [aNotification object]
userInfo: newUserInfo];
[super textDidEndEditing: newNotification];
[[self window] makeFirstResponder: self];
} else
[super textDidEndEditing: aNotification];
}
@end
|