1
1
#import " SSYDragDestinationTextView.h"
2
- #import " NSObject+SuperUtils.h"
3
- #import " NSView+FocusRing.h"
4
- #import " SSYDragDestinationTextViewDelegate.h"
5
-
6
2
7
3
@implementation SSYDragDestinationTextView : NSTextView
8
4
9
- - (void )awakeFromNib {
10
- [self patchPreLeopardFocusRingDrawingForScrolling ] ;
11
-
12
- // Safely invoke super
13
- [self safelySendSuperSelector: _cmd
14
- prettyFunction: __PRETTY_FUNCTION__
15
- arguments: nil ] ;
16
- }
17
-
18
-
19
- /*
20
-
21
- // At one time, I used the following two methods to make the 'tab' and 'shift-tab'
22
- // keystrokes tab to the next and prior fields instead of being treated as text
23
- // But then I found a better way: -[NSTextView setFieldEditor:YES].
24
- // So this code is out.
25
-
26
- - (void)setTabToNextKeyView:(BOOL)yn {
27
- _tabToNextKeyView = yn ;
5
+ - (void )setIgnoreTabsAndReturns : (BOOL )ignoreTabsAndReturns {
6
+ [self setFieldEditor: ignoreTabsAndReturns] ;
28
7
}
29
8
30
- - (void)keyDown:(NSEvent*)event {
31
- NSString *s = [event charactersIgnoringModifiers] ;
32
- unichar keyChar = 0 ;
33
- if ([s length] == 1) {
34
- keyChar = [s characterAtIndex:0] ;
35
-
36
- // Our superclass NSTextView accepts tabs and backtabs as text.
37
- // If we want _tabToNextKeyView, we re-implement the NSView behavior
38
- // of selecting the next or previous key view
39
- if ((keyChar == NSTabCharacter)&& _tabToNextKeyView) {
40
- [[self window] selectNextKeyView:self] ;
41
- }
42
- else if ((keyChar == NSBackTabCharacter) && _tabToNextKeyView) {
43
- [[self window] selectPreviousKeyView:self] ;
44
- }
45
- else {
46
- // Handle using super's (i.e. NSTextView) -interpretKeyEvents:,
47
- // which will typewrite the key-downed character
48
- NSArray* events = [NSArray arrayWithObject:event] ;
49
- [self interpretKeyEvents:events] ;
50
- }
51
- }
9
+ - (BOOL )ignoreTabsAndReturns {
10
+ return [self isFieldEditor ] ;
52
11
}
53
- */
54
12
55
- - (NSDragOperation )draggingEntered : (id <NSDraggingInfo >)sender {
56
- NSDragOperation answer = NSDragOperationNone ;
57
- NSPasteboard * pasteboard = [sender draggingPasteboard ] ;
58
- NSString *anAcceptableType = [pasteboard availableTypeFromArray: [self registeredDraggedTypes ]];
59
-
60
- if (anAcceptableType != nil ) {
61
- // Don't be hidden!!!...
62
- [NSApp activateIgnoringOtherApps: YES ] ;
63
- [[self window ] makeKeyAndOrderFront: self ] ;
64
-
65
- answer = NSDragOperationCopy ; // Accept data as a copy operation
66
-
67
- _isInDrag = YES ;
68
- [self selectAll: self ] ;
69
- [self setNeedsDisplay: YES ] ;
70
- }
71
-
72
- return answer ;
73
- }
74
-
75
- // Called whenever a drag exits our drop zone
76
- - (void )draggingExited : (id <NSDraggingInfo >)sender {
77
- _isInDrag = NO ;
78
- [self setSelectedRange: NSMakeRange (0 ,0 )] ;
79
- [self setNeedsDisplay: YES ] ;
80
- }
81
-
82
- // Method to determine if we can accept the drop
83
- - (BOOL )prepareForDragOperation : (id <NSDraggingInfo >)sender {
84
- BOOL answer = NO ;
85
-
86
- NSPasteboard * pasteboard = [sender draggingPasteboard ] ;
87
- NSArray * registeredTypes = [self registeredDraggedTypes ] ;
88
- NSString * anAcceptableType = [pasteboard availableTypeFromArray: registeredTypes] ;
89
- if (anAcceptableType != nil ) {
90
- _isInDrag = NO ;
91
- [self setSelectedRange: NSMakeRange (0 ,0 )] ;
92
- [self setNeedsDisplay: YES ] ;
93
- answer = YES ;
94
- }
95
-
96
- return answer ;
97
- }
98
-
99
- // Forward the drop to the delegate, or else, its window's delegate
100
13
- (BOOL )performDragOperation : (id <NSDraggingInfo >)sender {
101
- BOOL answer = NO ;
102
- if ([self respondsToSelector: @selector (delegate )]) {
103
- answer = [(id <SSYDragDestinationTextViewDelegate>)[self delegate ] performDragOperation: sender
104
- destination: self ] ;
105
- }
106
- else if ([[[self window ] delegate ] respondsToSelector: @selector (performDragOperation:destination: )]) {
107
- answer = [(id <SSYDragDestinationTextViewDelegate>)[[self window ] delegate ] performDragOperation: sender
108
- destination: self ] ;
109
- }
110
-
111
- return answer ;
112
- }
14
+ BOOL didDo = [super performDragOperation: sender] ;
113
15
114
- - (void )concludeDragOperation : (id <NSDraggingInfo >)sender {
115
- }
116
-
117
- - (void )drawRect : (NSRect )rect {
118
- [super drawRect: rect] ;
119
- if (_isInDrag) {
120
- [self drawFocusRing ] ;
121
- }
122
- }
16
+ if (self.activateUponDrop ) {
17
+ [NSApp activateIgnoringOtherApps: YES ] ;
18
+ [[self window ] makeKeyAndOrderFront: self ] ;
19
+ }
123
20
124
- - (void )setString : (NSString *)aString {
125
- [super setString: aString] ;
21
+ return didDo ;
126
22
}
127
23
128
-
129
24
@end
130
-
131
- /*
132
-
133
-
134
- NSPasteboard *pb = [sender draggingPasteboard];
135
- NSString *value;
136
- NSString *type;
137
- type = [pb availableTypeFromArray:[NSArray arrayWithObject:NSStringPboardType]];
138
- if (type) {
139
- value = [pb stringForType:NSStringPboardType];
140
- id target = [self myDropTarget];
141
- SEL action = [self myDropAction];
142
- [target performSelector:action withObject:value];
143
- return YES;
144
- }
145
- return NO;
146
- }
147
-
148
-
149
- - (BOOL)performDragOperation:(id <NSDraggingInfo>)info {
150
- NSPasteboard* pasteboard = [info draggingPasteboard] ;
151
-
152
- NSArray* acceptableTypes ;
153
- if ([self respondsToSelector:@selector(orderedRegisteredDraggedTypes)]) {
154
- acceptableTypes = [self orderedRegisteredDraggedTypes] ;
155
- }
156
- else {
157
- acceptableTypes = [self registeredDraggedTypes] ;
158
- }
159
- NSString *bestType = [pasteboard availableTypeFromArray:acceptableTypes] ;
160
-
161
- id object = nil ;
162
-
163
- if ([bestType isEqualToString:@"MV Super-secret message transfer pasteboard type"]) {
164
- NSLog(@"Tried drag of Apple Mail message: not supported yet.") ;
165
- // // Three reasons why this code is commented out:
166
- // // 1. Import takes 30 seconds or more.
167
- // // 2. Import comes in html, as shown below. Must filter to plain text somehow:
168
- // // this:</DIV><DIV><BR></DIV><DIV>Licensee Name:</DIV><DIV>bH New Sale =
169
- // // 150953</DIV><DIV><BR></DIV><DIV>Serial =
170
- // // Number:</DIV><DIV>CbN34wJoOVX7Jgva</DIV><DIV><BR></DIV><DIV>Bookmarksman =
171
- // // Neither of problems 1 or 2 are fixed by uncommenting "theLock" in
172
- // // CIPAppleScriptHelper.m
173
- // // 3. According to Apple Documentation, should not use [self class] in the
174
- // // next line but should use [MyApp class] instead. But MyApp is not
175
- // // declared anywhere. Maybe this could be fixed by using -classNamed:@"MyApp".
176
- // // But who do you send that instance message to?
177
- // NSBundle *bundle = [NSBundle bundleForClass:[self class]];
178
- // NSLog(@"Hullo! bundlePath = %@", [bundle bundlePath]) ;
179
- // NSString *resourcePath = [bundle pathForResource: @"MailHelper"
180
- // ofType: @"applescript"];
181
- //
182
- // NSLog(@"Hullo! resourcePath = %@", resourcePath) ;
183
- // NSLog(@"Hullo! 1 Getting result from helper") ;
184
- // NSAppleEventDescriptor *result =
185
- // [[CIPAppleScriptHelper sharedHelper] callInResource: resourcePath
186
- // script: @"getSelectedMailCount"] ;
187
- //
188
- // NSLog(@"Hullo! 1 result = %@", result) ;
189
- // NSMutableString* textFromMessages = [[NSMutableString alloc] init] ;
190
- //
191
- // if(result) {
192
- // int k;
193
- // NSString *mailMessage;
194
- //
195
- // NSLog(@"Hullo! 2 Getting result from helper") ;
196
- // result = [[CIPAppleScriptHelper sharedHelper] callInResource: resourcePath
197
- // script: @"getSelectedMailBodies"];
198
- // NSLog(@"Hullo! 2 result = %@", result) ;
199
- // int numberOfItems = [result numberOfItems];
200
- // NSLog(@"Hullo! numberOfItems = %i", numberOfItems) ;
201
- // for(k=1; k <= numberOfItems; k++) {
202
- // mailMessage = [[result descriptorAtIndex: k] stringValue] ;
203
- // NSLog(@"Hullo! mailMessage = %@", mailMessage) ;
204
- // [textFromMessages appendString:mailMessage] ;
205
- // }
206
- // }
207
- //
208
- // if ([textFromMessages length] > 0) {
209
- // object = [textFromMessages copy] ;
210
- // }
211
- //
212
- // [textFromMessages release] ;
213
-
214
- }
215
-
216
- if (!object) {
217
- object = [pasteboard propertyListForType:bestType] ;
218
- if (!object) {
219
- object = [pasteboard stringForType:bestType] ;
220
- if (!object) {
221
- object = [pasteboard dataForType:bestType] ;
222
- }
223
- }
224
- }
225
-
226
- if (object) {
227
- [[self target] performSelector:@selector(swallowDraggedObject:) withObject:object] ;
228
- return YES ;
229
- }
230
-
231
- return NO ;
232
- }
233
- */
0 commit comments