-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSKDragView.m
99 lines (84 loc) · 2.73 KB
/
SKDragView.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
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
//
// SKDragView.m
// Skreenics
//
// Created by naixn on 12/09/09.
// Copyright 2009 Thibault Martin-Lagardette. All rights reserved.
//
#import <QTKit/QTKit.h>
#import "SKDragView.h"
@implementation SKDragView
- (id)initWithCoder:(NSCoder *)coder
{
if (self = [super initWithCoder:coder])
{
[self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
acceptableMovieTypes = [[QTMovie movieTypesWithOptions:QTIncludeCommonTypes] retain];
}
return self;
}
- (void)dealloc
{
[acceptableMovieTypes release];
[super dealloc];
}
- (void)setDragDelegate:(id <SKDragDelegateProtocol>)delegate
{
dragDelegate = delegate;
}
#pragma mark Drag and Drop Operations
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
NSWorkspace* workspace;
NSFileManager* filemanager;
NSPasteboard* pboard;
NSDragOperation sourceDragMask;
BOOL canQTKitInitDraggedFiles;
BOOL pathIsDirectory;
// Init some variables
workspace = [NSWorkspace sharedWorkspace];
filemanager = [NSFileManager defaultManager];
pboard = [sender draggingPasteboard];
sourceDragMask = [sender draggingSourceOperationMask];
canQTKitInitDraggedFiles = NO;
pathIsDirectory = NO;
// We accept data from pasteboard only if it contains filenames
if ([[pboard types] containsObject:NSFilenamesPboardType])
{
// Look if we have at least one type of file we can deal with (movie / folder)
for (NSString* filePath in [pboard propertyListForType:NSFilenamesPboardType])
{
[filemanager fileExistsAtPath:filePath isDirectory:&pathIsDirectory];
if (pathIsDirectory)
{
break;
}
if ([acceptableMovieTypes containsObject:[workspace typeOfFile:filePath error:nil]])
{
canQTKitInitDraggedFiles = YES;
break;
}
}
// If a folder is dragged, of the filename list contains a movie, return "NSDragOperationCopy" to get the (+) icon
if ((pathIsDirectory || canQTKitInitDraggedFiles) && (sourceDragMask & NSDragOperationCopy))
{
return NSDragOperationCopy;
}
}
// If all of the above failed, then we can't handle anything that was dragged
return NSDragOperationNone;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPasteboard* pboard = [sender draggingPasteboard];
if ([[pboard types] containsObject:NSFilenamesPboardType] )
{
for (NSString* filePath in [pboard propertyListForType:NSFilenamesPboardType])
{
[dragDelegate addDragPathElement:filePath];
}
return YES;
}
return NO;
}
@end