forked from Sappharad/MultiPatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MPFileTextField.m
56 lines (48 loc) · 1.28 KB
/
MPFileTextField.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// MPFileTextField.m
// MultiPatch
//
#import "MPFileTextField.h"
@implementation MPFileTextField
-(id)init{
if(self=[super init]){
[self registerForDraggedTypes:@[NSURLPboardType]];
}
return self;
}
-(id)initWithCoder:(NSCoder *)coder{
if(self=[super initWithCoder:coder]){
[self registerForDraggedTypes:@[NSURLPboardType]];
}
return self;
}
-(void)dealloc{
if(_acceptFileDrop != nil){
[_acceptFileDrop release];
_acceptFileDrop = nil;
}
[super dealloc];
}
-(NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender{
NSArray* fileList = [[sender draggingPasteboard] readObjectsForClasses:@[[NSURL class]] options:nil];
if(fileList.count == 1){
NSURL* url = [fileList objectAtIndex:0];
if(url.isFileURL){
return NSDragOperationCopy;
}
}
return NSDragOperationNone;
}
-(BOOL)performDragOperation:(id<NSDraggingInfo>)sender{
if(self.acceptFileDrop){
NSArray* fileList = [[sender draggingPasteboard] readObjectsForClasses:@[[NSURL class]] options:nil];
if(fileList.count == 1){
NSURL* url = [fileList objectAtIndex:0];
if(url.isFileURL){
return _acceptFileDrop(url);
}
}
}
return NO;
}
@end