-
Notifications
You must be signed in to change notification settings - Fork 0
/
NewFileDialog.j
151 lines (108 loc) · 3.53 KB
/
NewFileDialog.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
@import <AppKit/CPWindow.j>
@import <AppKit/CPButton.j>
@import <AppKit/CPCollectionView.j>
@implementation NewFileDialog : CPWindow
{
CPTextField _fileNameField;
CPCollectionView collectionView;
}
-(id) init
{
self = [super initWithContentRect:CGRectMake(0,0, 470,400) styleMask:CPClosableWindowMask];
if(self )
{
[self setTitle:@"New File"];
var cv = [self contentView];
var okButton = [[CPButton alloc] initWithFrame:CGRectMake(375, 360, 80, 25)];
[okButton setTitle:@"OK"];
[okButton setAutoresizingMask:CPViewMinXMargin|CPViewMinYMargin];
[okButton setTarget:self];
[okButton setAction:@selector(onConfirm:)];
[cv addSubview:okButton];
var cancelButton = [[CPButton alloc] initWithFrame:CGRectMake(290, 360, 80, 25)];
[cancelButton setTitle:@"Cancel"];
[cancelButton setAutoresizingMask:CPViewMinXMargin|CPViewMinYMargin];
[cancelButton setTarget:self];
[cancelButton setAction:@selector(orderOut:)];
[cv addSubview:cancelButton];
var fileTemplateLabel = [CPTextField labelWithString:@"File Template:"];
[fileTemplateLabel setFrameOrigin:CGPointMake(15, 15)];
[cv addSubview:fileTemplateLabel];
collectionView = [[CPCollectionView alloc] initWithFrame:CGRectMake(15,35, 440, 230)];
[collectionView setAutoresizingMask:CPViewWidthSizable];
[collectionView setBackgroundColor:[CPColor whiteColor]];
[collectionView setBorderWidth:1.0];
[collectionView setBorderColor:[CPColor colorWithHexString:@"9d9d9d"]];
[collectionView setHorizontalMargin:10];
[collectionView setVerticalMargin:10];
[collectionView setMinItemSize:CGSizeMake(96,96)];
[collectionView setMaxItemSize:CGSizeMake(96,96)];
var newItem = [[NewItem alloc] init];
[newItem setView:[[CPView alloc] initWithFrame:CGRectMake(0,0,96,96)]];
[collectionView setItemPrototype:newItem];
[collectionView setContent:[{
label : @"Window",
image : [CPImage imageNamed:@"window.png"]
},
{
label : @"View",
image : [CPImage imageNamed:@"view.png"]
}
]];
[cv addSubview:collectionView];
var newFileLabel = [CPTextField labelWithString:@"Filename:"];
[newFileLabel setFrameOrigin:CGPointMake(15, 275)];
[cv addSubview:newFileLabel];
_fileNameField = [[CPTextField alloc] initWithFrame:CGRectMake(15, 295, 440, 28)];
[_fileNameField setBezeled:YES];
[_fileNameField setAutoresizingMask:CPViewWidthSizable];
[cv addSubview:_fileNameField];
}
return self;
}
-(void) reset
{
[collectionView setSelectionIndexes:[CPIndexSet indexSetWithIndex:0]];
[_fileNameField setStringValue:@""];
[self makeFirstResponder:collectionView];
}
-(void) onConfirm:(id)sender
{
}
@end
@implementation NewItem : CPCollectionViewItem
{
CPTextField _label;
CPImageView _imageView;
}
-(void) setRepresentedObject:(JSObject)data
{
if(!_imageView)
{
_imageView = [[CPImageView alloc] initWithFrame:CGRectMake(16,5,64,64)];
[_imageView setImageScaling:CPScaleProportionally];
[_view addSubview:_imageView];
}
if(!_label)
{
_label = [CPTextField labelWithString:data.label];
[_label setTextShadowOffset:CGSizeMake(0,0)];
[_view addSubview:_label];
}
[_imageView setImage:data.image];
[_label setStringValue:data.label];
[_label sizeToFit];
[_label setFrameOrigin:CGPointMake((96-CGRectGetWidth([_label frame]))/2.0, 72)];
}
-(void) setSelected:(BOOL)aBOOL
{
[super setSelected:aBOOL];
if(aBOOL)
{
[_view setBackgroundColor:[CPColor colorWithHexString:@"99C2FF"]];
}else
{
[_view setBackgroundColor:[CPColor whiteColor]];
}
}
@end