This repository was 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
Expand file tree
/
Copy pathTableListCon.m
More file actions
96 lines (85 loc) · 2.81 KB
/
TableListCon.m
File metadata and controls
96 lines (85 loc) · 2.81 KB
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
#import "TableListCon.h"
#import "tvdb_api_wrapper.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*)old_filepath
{
NSString *old_filename = [[old_filepath pathComponents] lastObject];
// Generate dict of new file
NSDictionary *cfile = [NSMutableDictionary dictionaryWithObjectsAndKeys:
old_filename, @"old_filename",
old_filepath, @"old_filepath",
[NSNumber numberWithBool:YES], @"rename",
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
{
[busy setHidden:NO];
[busy startAnimation:self];
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
[busy setHidden:YES];
[busy stopAnimation:self];
return YES;
}
[busy setHidden:YES];
[busy stopAnimation:self];
return NO;
}
@end