-
Notifications
You must be signed in to change notification settings - Fork 3
/
MediaView.j
288 lines (229 loc) · 9.74 KB
/
MediaView.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
@implementation MediaView : CPView
{
CPView frontView;
CPView backView;
ItemAttachment attachment;
Item itemUsed;
CPView pdfView;
CPImageView imageView;
BOOL isFullScreen;
CPButton fullScreenButton;
CPButton infoButton;
CPButton deleteButton;
CPScrollView scrollView;
}
- (id)initWithFrame:(CGRect)aRect
{
self = [super initWithFrame:aRect];
if (self)
{
frontView = [[CPView alloc] initWithFrame:CGRectMake(0,0,aRect.size.width,aRect.size.height)];
[self addSubview:frontView];
[frontView setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable];
//console.log(aRect.size.height);
scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0,0,aRect.size.width, aRect.size.height - 50)];
[scrollView setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable/*|CPViewMaxXMargin|CPViewMinXMargin|CPViewMinYMargin|CPViewMaxYMargin*/];
[scrollView setHorizontalLineScroll:.5];
[scrollView setVerticalLineScroll:.5];
[frontView addSubview:scrollView];
var hud = [CPTheme themeNamed:@"Aristo-HUD"];
[[scrollView verticalScroller] setTheme:hud];
[[scrollView horizontalScroller] setTheme:hud];
fullScreenButton = [[CPButton alloc] initWithFrame:CGRectMake(aRect.size.width / 2 - 202, aRect.size.height - 35, 125, 24)];
[fullScreenButton setTitle:@"Full Screen"];
[fullScreenButton setTheme:hud];
[fullScreenButton setTarget:self];
[fullScreenButton setAction:@selector(fullScreen:)];
[fullScreenButton setKeyEquivalent:"f"];
[fullScreenButton setKeyEquivalentModifierMask:CPCommandKeyMask];
[fullScreenButton setAutoresizingMask:CPViewMinYMargin|CPViewMinXMargin|CPViewMaxXMargin];
[frontView addSubview:fullScreenButton];
infoButton = [[CPButton alloc] initWithFrame:CGRectMake(aRect.size.width / 2 - 62, aRect.size.height - 35, 125, 24)];
[infoButton setTitle:@"Info"];
[infoButton setTheme:hud];
[infoButton setTarget:self];
[infoButton setAction:@selector(info:)];
[infoButton setKeyEquivalent:"i"];
[infoButton setKeyEquivalentModifierMask:CPCommandKeyMask];
[infoButton setAutoresizingMask:CPViewMinYMargin|CPViewMinXMargin|CPViewMaxXMargin];
[frontView addSubview:infoButton];
deleteButton = [[CPButton alloc] initWithFrame:CGRectMake(aRect.size.width / 2 + 77, aRect.size.height - 35, 125, 24)];
[deleteButton setTitle:@"Delete"];
[deleteButton setTheme:hud];
[deleteButton setTarget:self];
[deleteButton setAction:@selector(confirmDelete:)];
[deleteButton setAutoresizingMask:CPViewMinYMargin|CPViewMinXMargin|CPViewMaxXMargin];
[frontView addSubview:deleteButton];
}
return self;
}
- (void)fullScreen:(id)sender
{
if ([self isInFullScreenMode])
{
// exit full screen
[self exitFullScreenModeWithOptions:nil];
[fullScreenButton setTitle:"Full Screen"];
}
else
{
// enter full screen
[self enterFullScreenMode:nil withOptions:nil];
[fullScreenButton setTitle:"Exit Full Screen"];
}
}
- (void)info:(id)sender
{
var frame = [frontView frame],
startPoint = CGPointMake(0, frame.size.height),
endPoint = CGPointMake(0,0);
backView = [[MediaInfoView alloc] initWithFrame:CGRectMake(startPoint.x, startPoint.y, frame.size.width, frame.size.height)];
//[backView setBackgroundColor:[CPColor redColor]];
[backView setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable];
[self addSubview:backView];
var cardFlipController = [LPCardFlipController sharedController],
centerPoint = [[self window] convertBaseToGlobal:[frontView convertPoint:[frontView center] toView:nil]];
[cardFlipController setDelegate:self];
[cardFlipController setStartCenter:centerPoint endCenter:centerPoint];
[cardFlipController flipWithView:frontView backView:backView reverse:NO];
//window.setTimeout(function(){[self flipBackToMedia:nil];},1000);
/*var animation = [[LPViewAnimation alloc] initWithViewAnimations:[
{
@"target": backView,
@"animations": [
[LPOriginAnimationKey, startPoint, endPoint] // Can also have multiple animations on a single view
]
}
]];
[animation setAnimationCurve:CPAnimationEaseInOut];
[animation setDuration:0.5];
[animation setShouldUseCSSAnimations:YES];
[animation startAnimation];*/
}
- (void)flipBackToMedia:(id)sender
{
var cardFlipController = [LPCardFlipController sharedController],
centerPoint = [[self window] convertBaseToGlobal:[backView convertPoint:[backView center] toView:nil]];
[cardFlipController setDelegate:self];
[cardFlipController setStartCenter:centerPoint endCenter:centerPoint];
[cardFlipController flipWithView:backView backView:frontView reverse:NO];
}
- (void)confirmDelete:(id)sender
{
/*var removeAttachmentSheet = [[CPWindow alloc] initWithContentRect:CGRectMake(0,0,400,120) styleMask:CPDocModalWindowMask],
contentView = [removeAttachmentSheet contentView],
header = [CPTextField labelWithTitle:@"Delete Attachment"];
[header setFrame:CGRectMake(100,10, 415, 25)];
[header setFont:[CPFont boldSystemFontOfSize:15]];
[contentView addSubview:header];
var headerImage = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"logoPlain.png"] size:CGSizeMake(68,68)];
var headerImageView = [[CPImageView alloc] initWithFrame:CGRectMake(20, 10, 68, 68)];
[headerImageView setImage:headerImage];
[contentView addSubview:headerImageView];
var warningMessage = [[CPTextField alloc] initWithFrame:CGRectMake(100, 35, 325, 60)];
[warningMessage setStringValue:@"Are you sure you want to this attachment? This action cannot be undone."];
[warningMessage setLineBreakMode:CPLineBreakByWordWrapping];
[contentView addSubview:warningMessage];
var removeButton = [[CPButton alloc] initWithFrame:CGRectMake(285, 85, 100, 24)];
[removeButton setTitle:@"Remove"];
[removeButton setTag:0];
[removeButton setTarget:self];
[removeButton setAction:@selector(closeSheet:)];
[contentView addSubview:removeButton];
var cancelButton = [[CPButton alloc] initWithFrame:CGRectMake(175, 85, 100, 24)];
[cancelButton setTag:-1];
[cancelButton setTitle:@"Cancel"];
[cancelButton setTarget:self];
[cancelButton setAction:@selector(closeSheet:)];
[contentView addSubview:cancelButton];
[removeAttachmentSheet setDefaultButton:cancelButton];
[CPApp beginSheet:removeAttachmentSheet modalForWindow:[self window] modalDelegate:self didEndSelector:@selector(didEndSheet:returnCode:contextInfo:) contextInfo:self];
*/
var alert = [[CPAlert alloc] init];
// [alert setWindowStyle:CPHUDBackgroundWindowMask];
[alert setTitle:"Delete Attachment"];
[alert setDelegate:self];
[alert setAlertStyle:CPWarningAlertStyle];
[alert setMessageText:"Delete Attachment"];
[alert setInformativeText:"Are you sure you want to delete "+ [attachment name] +"? This action cannot be undone."];
[alert addButtonWithTitle:"Delete"];
[alert addButtonWithTitle:"Cancel"];
[alert runModal];
}
-(void)alertDidEnd:(CPAlert)theAlert returnCode:(int)returnCode
{
if (returnCode)
return;
[itemUsed removeAttachment:attachment];
[[self window] orderOut:self];
}
- (void)setMedia:(ItemAttachment)anAttachment forItem:(Item)anItem
{
attachment = anAttachment;
itemUsed = anItem;
var type = [attachment type];
switch (type)
{
case "image":
var imageView = [[CPImageView alloc] initWithFrame:CGRectMake(0,0,1000,1000)],
image = [[CPImage alloc] initWithContentsOfFile:[anAttachment data] size:CGSizeMake(1000,1000)];
[imageView setImage:image];
[scrollView setDocumentView:imageView];
break;
case "pdf":
var webview = [[CPWebView alloc] initWithFrame:[scrollView frame]]//CGRectMake(0,0,)];
[webview setMainFrameURL:"mysamplepdf.pdf"];//[anAttachment data]];
[webview setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable];
[scrollView removeFromSuperview];
[frontView addSubview:webview];
break;
case "video":
break;
case "audio":
break;
case "document":
break;
case "other":
break;
}
}
- (void)keyDown:(CPEvent)anEvent
{
if ([anEvent keyCode] === CPEscapeKeyCode && [self isInFullScreenMode])
[self fullScreen:nil];
}
- (BOOL)acceptsFirstResponder
{
return YES;
}
- (void)cardFlipDidFinish:(id)sender
{
[[sender frontView] removeFromSuperview];
[self addSubview:[sender backView]];
[[sender backView] setFrameOrigin:CGPointMakeZero()];
}
@end
@implementation MediaInfoView : CPView
{
CPTextField nameField;
}
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
if (self)
{
var nameLabel = [[CPTextField alloc] initWithFrame:CGRectMake(30,30,30,30)];
[nameLabel setStringValue:"File Name:"];
[nameLabel sizeToFit];
[nameLabel setAlignment:CPRightTextAlignment];
[nameLabel setTextColor:[CPColor whiteColor]];
[self addSubview:nameLabel];
nameField = [LocationEditView customTextField];
[nameField setFrame:CGRectMake(CGRectGetMaxX([nameLabel frame]) + 5, 25, 165, 30)];
[nameField setFont:[CPFont systemFontOfSize:12]];
[nameField setTextColor:[CPColor whiteColor]];
[self addSubview:nameField];
}
return self;
}
@end