forked from maciekish/iReSign
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIRTextFieldDrag.m
58 lines (43 loc) · 1.39 KB
/
IRTextFieldDrag.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
57
58
//
// IRTextFieldDrag.m
// iReSign
//
// Created by Esteban Bouza on 01/12/12.
//
#import "IRTextFieldDrag.h"
@implementation IRTextFieldDrag
- (void)awakeFromNib {
[self registerForDraggedTypes:@[NSFilenamesPboardType]];
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPasteboard *pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSURLPboardType] ) {
NSArray *files = [pboard propertyListForType:NSFilenamesPboardType];
if (files.count <= 0) {
return NO;
}
self.stringValue = [files objectAtIndex:0];
}
return YES;
}
// Source: http://www.cocoabuilder.com/archive/cocoa/11014-dnd-for-nstextfields-drag-drop.html
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
if (!self.isEnabled) return NSDragOperationNone;
NSPasteboard *pboard;
NSDragOperation sourceDragMask;
sourceDragMask = [sender draggingSourceOperationMask];
pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSColorPboardType] ) {
if (sourceDragMask & NSDragOperationCopy) {
return NSDragOperationCopy;
}
}
if ( [[pboard types] containsObject:NSFilenamesPboardType] ) {
if (sourceDragMask & NSDragOperationCopy) {
return NSDragOperationCopy;
}
}
return NSDragOperationNone;
}
@end