This repository has been archived by the owner on Oct 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
DCFileDropCollectionViewController.j
68 lines (57 loc) · 2.27 KB
/
DCFileDropCollectionViewController.j
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
@import <AppKit/CPPanel.j>
@import "DCFileDropCollectionViewItemView.j"
@implementation DCFileDropCollectionViewController : CPPanel {
CPArray list;
CPCollectionView collectionView @accessors;
CPScrollView scrollView @accessors;
CPView view @accessors;
}
- (id)init {
self = [super init];
if (self) {
list = [[CPArray alloc] init];
[list addObject:@"Item\nOne"];
[list addObject:@"Item\nTwo"];
[list addObject:@"Item\nThree"];
[list addObject:@"Item\nFour"];
[list addObject:@"Item\nFive"];
// create the collection view
collectionView = [[CPCollectionView alloc] initWithFrame:CGRectMake(0, 0, 98, 98)];
[collectionView setMinItemSize:CGSizeMake(60, 60)];
[collectionView setMaxItemSize:CGSizeMake(60, 60)];
[collectionView setContent:list];
[collectionView setSelectable:YES];
[collectionView setAllowsMultipleSelection:NO];
[collectionView setDelegate:self];
[collectionView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
// create the item prototype
var itemPrototype = [[CPCollectionViewItem alloc] init];
var itemView = [[DCFileDropCollectionViewItemView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
[itemPrototype setView:itemView];
[collectionView setItemPrototype:itemPrototype];
var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(1, 1, 98, 98)];
[scrollView setBackgroundColor:[CPColor whiteColor]];
[scrollView setDocumentView:collectionView];
[scrollView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[scrollView setHasHorizontalScroller:NO];
var view = [[CPView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[view setBackgroundColor:[CPColor lightGrayColor]];
[view addSubview:scrollView];
var fileDropUploadController = [[DCFileDropController alloc]
initWithView:collectionView
dropDelegate:self
uploadURL:[CPURL URLWithString:@"upload.php"]
uploadManager:[DCFileUploadManager sharedManager]
insertAsFirstSubview:YES];
}
return self;
}
// ******************** DCFileDropControllerDropDelegate *********************
- (void)fileDropUploadController:(DCFileDropController)theController setState:(BOOL)visible {
if (visible) {
[collectionView setBackgroundColor:[CPColor orangeColor]];
} else {
[collectionView setBackgroundColor:[CPColor whiteColor]];
}
}
@end