Skip to content

Commit 1ea142a

Browse files
committed
• Greatly simplified SSYDragDestinationTextView, which was full of crap. I think that most of what I was doing when I wrote that code many years ago was built into NSTextView, but I didn't know how to use it.
• Removed patch for OS X 10.3.
1 parent ea2ee3b commit 1ea142a

File tree

2 files changed

+18
-246
lines changed

2 files changed

+18
-246
lines changed

Diff for: SSYDragDestinationTextView.h

+8-27
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,18 @@
11
#import <Cocoa/Cocoa.h>
22

3-
/*
4-
This class implements most of the NSDraggingDestination protocol,
5-
making it a little easier to make any NSTextView a dragging destination.
6-
7-
Things which must be done elsewhere:
8-
9-
- Somewhere,
10-
- send me -unregisterDraggedTypes, followed by
11-
-registerForDraggedTypes: to the dragging destination NSView.
12-
- If scrolling is desired, send configureScrollingHorzontal:vertical
13-
Suggestions: Do these in a window controller's -awakeFromNib
14-
15-
- Dragging destination NSView must have a delegate, or be in a window with a delegate,
16-
which implements the SSYDragDestinationTextViewDelegate protcol.
17-
18-
19-
*/
20-
213
@interface SSYDragDestinationTextView : NSTextView {
22-
BOOL _isInDrag ;
23-
// BOOL _tabToNextKeyView ; Depracated. See comments in .m
244
}
255

26-
/*!
27-
@brief Sets the ivar _tabToNextKeyView
6+
@property BOOL activateUponDrop ;
287

29-
@details Depracated. See comments in .m.
30-
By default, NSTextView accepts hitting the tab key as a text character.
31-
Setting this to YES tells it to tab to the next key view, like an NSTextField does.
32-
@param YES to tab to the next key view, NO for the default NSTextView behavior.
33-
- (void)setTabToNextKeyView:(BOOL)yn ;
8+
/*!
9+
@brief A wrapper around @property fieldEditor, which has a more meaningful
10+
name than fieldEditor
11+
12+
@details You can get the same result in Interface Builder, by switching on the
13+
receiver's *Field Editor* checkbox.
3414
*/
15+
@property BOOL ignoreTabsAndReturns ;
3516

3617
@end
3718

Diff for: SSYDragDestinationTextView.m

+10-219
Original file line numberDiff line numberDiff line change
@@ -1,233 +1,24 @@
11
#import "SSYDragDestinationTextView.h"
2-
#import "NSObject+SuperUtils.h"
3-
#import "NSView+FocusRing.h"
4-
#import "SSYDragDestinationTextViewDelegate.h"
5-
62

73
@implementation SSYDragDestinationTextView : NSTextView
84

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] ;
287
}
298

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] ;
5211
}
53-
*/
5412

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
10013
- (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] ;
11315

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+
}
12320

124-
- (void)setString:(NSString *)aString {
125-
[super setString:aString] ;
21+
return didDo ;
12622
}
12723

128-
12924
@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

Comments
 (0)