This repository has been archived by the owner on Sep 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
TableListCon.m
89 lines (79 loc) · 2.63 KB
/
TableListCon.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
#import "TableListCon.h"
@implementation TableListCon
- (void)awakeFromNib
{
[tableView setDraggingSourceOperationMask:NSDragOperationLink forLocal:NO];
[tableView setDraggingSourceOperationMask:(NSDragOperationCopy | NSDragOperationMove) forLocal:YES];
[tableView registerForDraggedTypes:[NSArray arrayWithObjects:
NSFilenamesPboardType, nil]];
[tableView setAllowsMultipleSelection:YES];
}
- (BOOL)tableView:(NSTableView *)aTableView
writeRowsWithIndexes:(NSIndexSet *)rowIndexes
toPasteboard:(NSPasteboard *)pboard
{
return YES;
}
- (NSDragOperation)tableView:(NSTableView*)tv
validateDrop:(id <NSDraggingInfo>)info
proposedRow:(int)row
proposedDropOperation:(NSTableViewDropOperation)op
{
NSDragOperation dragOp = NSDragOperationCopy;
return dragOp;
}
-(void)addFileToList:(NSString*)path
{
NSArray *components = [path pathComponents];
NSString *filename = [components lastObject];
// Generate dict of new file
NSMutableDictionary *cfile = [NSMutableDictionary dictionaryWithObjectsAndKeys:
filename, @"filename",
[NSNumber numberWithBool:YES], @"rename",
path, @"path",
nil];
// Add it to the tableView's array controller
[ArrayCon addObject:cfile];
}
-(void)addDirectoryToList:(NSString*)path
{
NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager]
enumeratorAtPath:path];
NSString *pname;
while (pname = [direnum nextObject])
{
if ([[[pname pathComponents] lastObject] hasPrefix:@"."])
{
// hidden dot-file/folder, skip this and sub-dirs
[direnum skipDescendents];
}
else
{
[self addFileToList:pname];
}
}
}
- (BOOL)tableView:(NSTableView*)tv
acceptDrop:(id<NSDraggingInfo>)info
row:(int)row
dropOperation:(NSTableViewDropOperation)op
{
NSPasteboard *pboard = [info draggingPasteboard];
if([[pboard types] containsObject:NSFilenamesPboardType])
{
NSArray *files = [pboard propertyListForType:NSFilenamesPboardType];
for(id file in files)
{
BOOL isDir;
if([[NSFileManager defaultManager]
fileExistsAtPath:file isDirectory:&isDir] && isDir)
[self addDirectoryToList:file];
else
[self addFileToList:file];
}
// Done all files
return YES;
}
return NO;
}
@end