-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAppController.j
More file actions
694 lines (624 loc) · 27.7 KB
/
AppController.j
File metadata and controls
694 lines (624 loc) · 27.7 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
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
// (c) 2010-2011 by Anton Korenyushkin
@import "Multiview.j"
@import "Data.j"
@import "Proxy.j"
@import "Confirm.j"
@import "SidebarController.j"
@import "AboutPanelController.j"
@import "KeyPanelController.j"
@import "SignupPanelController.j"
@import "LoginPanelController.j"
@import "ChangePasswordPanelController.j"
@import "ResetPasswordPanelController.j"
@import "NewAppPanelController.j"
@import "ManageDomainsPanelController.j"
@import "ContactPanelController.j"
@import "CodeFileController.j"
@import "LibFileController.j"
@import "EvalController.j"
@import "GitController.j"
@import "CommitController.j"
@implementation FileBuffer (AppController)
- (CPString)modeIndex // public
{
return 0;
}
@end
@implementation CodeFileBuffer (AppController)
- (Class)presentationControllerClass // public
{
return CodeFileController;
}
@end
@implementation LibFileBuffer (AppController)
- (Class)presentationControllerClass // public
{
return LibFileController;
}
@end
@implementation EvalBuffer (AppController)
- (CPString)modeIndex // public
{
return 1;
}
- (Class)presentationControllerClass // public
{
return EvalController;
}
@end
@implementation CommitBuffer (AppController)
- (CPString)modeIndex // public
{
return 2;
}
- (Class)presentationControllerClass // public
{
return CommitController;
}
@end
@implementation GitBuffer (AppController)
- (CPString)modeIndex // public
{
return 3;
}
- (Class)presentationControllerClass // public
{
return GitController;
}
@end
var ModeNames = ["Edit", "Eval", "Commit", "Git"];
BoundKeys = ["[", "]", "f", "g", "n", "s", "w", "l"];
var DocsURL = "/docs/0.3/";
function setMenuItemsEnabled(menuItems, flag) {
menuItems.forEach(function (menuItem) { [menuItem doSetEnabled:flag]; });
}
@implementation AppController : CPObject
{
@outlet CPWindow mainWindow;
@outlet CPView sidebarView;
@outlet Multiview presentationMultiview;
Proxy navigatorControllerProxy;
Proxy workspaceControllerProxy;
Proxy presentationControllerProxy;
AboutPanelController aboutPanelController;
KeyPanelController keyPanelController;
ChangePasswordPanelController changePasswordPanelController;
ResetPasswordPanelController resetPasswordPanelController;
SignupPanelController signupPanelController @accessors(readonly);
LoginPanelController loginPanelController;
NewAppPanelController newAppPanelController;
ContactPanelController contactPanelController;
TabOpener helpTabOpener;
CPMenuItem passwordMenuItem;
CPMenu fileMenu;
CPMenu appsMenu;
CPMenuItem newFileMenuItem;
CPMenuItem newFolderMenuItem;
CPMenuItem openAppMenuItem;
CPMenuItem uploadFileMenuItem;
CPMenuItem closeMenuItem;
CPMenuItem saveMenuItem;
CPMenuItem saveAllMenuItem;
CPMenuItem actionsMenuItem;
CPMenuItem findMenuItem;
CPMenuItem findNextMenuItem;
CPMenuItem findPreviousMenuItem;
CPMenuItem goToLineMenuItem;
CPMenuItem modeMenuItem;
CPMenuItem editMenuItem;
CPMenuItem evalMenuItem;
CPMenuItem commitMenuItem;
CPMenuItem gitMenuItem;
CPMenuItem selectNextModeMenuItem;
CPMenuItem selectPreviousModeMenuItem;
CPMenuItem selectNextTabMenuItem;
CPMenuItem selectPreviousTabMenuItem;
CPMenuItem switchToPreviewMenuItem;
CPMenuItem openEvalMenuItem;
CPMenuItem openPreviewMenuItem;
CPMenuItem newEnvMenuItem;
CPMenuItem useLibMenuItem;
CPMenuItem manageDomainsMenuItem;
CPMenuItem publishAppMenuItem;
CPMenuItem deleteAppMenuItem;
CPMenuItem logoutMenuItem;
CPPopUpButton appPopUpButton;
JSObject toolbarItems;
CPToolbar toolbar;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification // private
{
[mainWindow setAcceptsMouseMovedEvents:YES];
[CPPlatformWindow preventCharacterKeysFromPropagating:BoundKeys];
navigatorControllerProxy = [[Proxy alloc] initWithObject:DATA keyPath:"app.navigatorController"];
workspaceControllerProxy = [[Proxy alloc] initWithObject:DATA keyPath:"app.workspaceController"];
presentationControllerProxy = [[Proxy alloc] initWithObject:DATA keyPath:"app.buffer.presentationController"];
aboutPanelController = [AboutPanelController new];
keyPanelController = [KeyPanelController new];
changePasswordPanelController = [ChangePasswordPanelController new];
resetPasswordPanelController = [ResetPasswordPanelController new];
signupPanelController = [SignupPanelController new];
loginPanelController = [[LoginPanelController alloc] initWithResetPasswordPanelController:resetPasswordPanelController];
newAppPanelController = [[NewAppPanelController alloc] initWithTarget:self action:@selector(didCreateAppWithName:)];
contactPanelController = [ContactPanelController new];
helpTabOpener = [TabOpener new];
var mainMenu = [CPApp mainMenu];
[mainMenu removeAllItems];
var akshellMenu = [CPMenu new];
[akshellMenu addItemWithTitle:"About Akshell" target:aboutPanelController action:@selector(showWindow:)];
[akshellMenu addItem:[CPMenuItem separatorItem]];
[akshellMenu addItemWithTitle:"SSH Public Key" target:keyPanelController action:@selector(showWindow:)];
passwordMenuItem = [akshellMenu addItemWithTitle:"" target:nil action:@selector(showWindow:)];
[[mainMenu addItemWithTitle:"Akshell"] setSubmenu:akshellMenu];
fileMenu = [CPMenu new];
[[fileMenu addItemWithTitle:"New App…" target:newAppPanelController action:@selector(showWindow:) keyEquivalent:"n"]
setKeyEquivalentModifierMask:CPAlternateKeyMask | CPPlatformActionKeyMask];
newFileMenuItem = [fileMenu addItemWithTitle:"New File" target:navigatorControllerProxy action:@selector(showNewFile)];
newFolderMenuItem = [fileMenu addItemWithTitle:"New Folder" target:navigatorControllerProxy action:@selector(showNewFolder)];
appsMenu = [CPMenu new];
openAppMenuItem = [fileMenu addItemWithTitle:"Open App"];
[openAppMenuItem setSubmenu:appsMenu];
[fileMenu addItem:[CPMenuItem separatorItem]];
uploadFileMenuItem = [fileMenu addItemWithTitle:"Upload File…"];
[uploadFileMenuItem setUploadTarget:navigatorControllerProxy action:@selector(uploadDOMFile:)];
[fileMenu addItem:[CPMenuItem separatorItem]];
closeMenuItem = [fileMenu addItemWithTitle:"Close"
target:workspaceControllerProxy
action:@selector(closeCurrentBuffer)
keyEquivalent:"w"];
saveMenuItem = [fileMenu addItemWithTitle:"Save" target:presentationControllerProxy action:@selector(save) keyEquivalent:"s"];
saveAllMenuItem = [fileMenu addItemWithTitle:"Save All" target:self action:@selector(saveAll) keyEquivalent:"s"];
[saveAllMenuItem setKeyEquivalentModifierMask:CPAlternateKeyMask | CPPlatformActionKeyMask];
[fileMenu addItem:[CPMenuItem separatorItem]];
actionsMenuItem = [fileMenu addItemWithTitle:"Actions"];
[actionsMenuItem setSubmenu:[CPMenu new]];
[[mainMenu addItemWithTitle:"File"] setSubmenu:fileMenu];
if (navigator.userAgent.indexOf("Chrome") == -1) {
[newFileMenuItem setKeyEquivalent:"n"];
[newFolderMenuItem setKeyEquivalent:"N"];
} else {
[closeMenuItem setKeyEquivalentModifierMask:CPAlternateKeyMask | CPPlatformActionKeyMask];
}
var editMenu = [CPMenu new];
findMenuItem = [editMenu addItemWithTitle:"Find…"
target:presentationControllerProxy
action:@selector(showFind)
keyEquivalent:"f"];
findNextMenuItem = [editMenu addItemWithTitle:"Find Next"
target:presentationControllerProxy
action:@selector(findNext)
keyEquivalent:"g"];
findPreviousMenuItem = [editMenu addItemWithTitle:"Find Previous"
target:presentationControllerProxy
action:@selector(findPrevious)
keyEquivalent:"G"];
[editMenu addItem:[CPMenuItem separatorItem]];
goToLineMenuItem = [editMenu addItemWithTitle:"Go to Line…"
target:presentationControllerProxy
action:@selector(showGoToLine)
keyEquivalent:"l"];
[[mainMenu addItemWithTitle:"Edit"] setSubmenu:editMenu];
var goMenu = [CPMenu new];
var modeMenu = [CPMenu new];
editMenuItem = [modeMenu addItemWithTitle:"Edit" target:workspaceControllerProxy action:@selector(switchToEdit)];
evalMenuItem = [modeMenu addItemWithTitle:"Eval" target:navigatorControllerProxy action:@selector(switchToEval)];
commitMenuItem = [modeMenu addItemWithTitle:"Commit" target:workspaceControllerProxy action:@selector(switchToCommit)];
gitMenuItem = [modeMenu addItemWithTitle:"Git" target:workspaceControllerProxy action:@selector(switchToGit)];
modeMenuItem = [goMenu addItemWithTitle:"Mode"];
[modeMenuItem setSubmenu:modeMenu];
selectNextModeMenuItem = [goMenu addItemWithTitle:"Select Next Mode"
target:self
action:@selector(switchToNextMode)
keyEquivalent:"]"];
[selectNextModeMenuItem setKeyEquivalentModifierMask:CPAlternateKeyMask | CPPlatformActionKeyMask];
selectPreviousModeMenuItem = [goMenu addItemWithTitle:"Select Previous Mode"
target:self
action:@selector(switchToPreviousMode)
keyEquivalent:"["];
[selectPreviousModeMenuItem setKeyEquivalentModifierMask:CPAlternateKeyMask | CPPlatformActionKeyMask];
[goMenu addItem:[CPMenuItem separatorItem]];
selectNextTabMenuItem = [goMenu addItemWithTitle:"Select Next Tab"
target:workspaceControllerProxy
action:@selector(switchToNextBuffer)
keyEquivalent:"/"];
[selectNextTabMenuItem setKeyEquivalentModifierMask:CPAlternateKeyMask | CPPlatformActionKeyMask];
selectPreviousTabMenuItem = [goMenu addItemWithTitle:"Select Previous Tab"
target:workspaceControllerProxy
action:@selector(switchToPreviousBuffer)
keyEquivalent:"'"];
[selectPreviousTabMenuItem setKeyEquivalentModifierMask:CPAlternateKeyMask | CPPlatformActionKeyMask];
[goMenu addItem:[CPMenuItem separatorItem]];
switchToPreviewMenuItem = [goMenu addItemWithTitle:"Switch to Preview"
target:navigatorControllerProxy
action:@selector(switchToPreview)];
[goMenu addItemWithTitle:"Switch to Help" target:self action:@selector(switchToHelp)];
[goMenu addItem:[CPMenuItem separatorItem]];
openEvalMenuItem = [goMenu addItemWithTitle:"Open Eval"];
[openEvalMenuItem setSubmenu:[CPMenu new]];
openPreviewMenuItem = [goMenu addItemWithTitle:"Open Preview"];
[openPreviewMenuItem setSubmenu:[CPMenu new]];
[[mainMenu addItemWithTitle:"Go"] setSubmenu:goMenu];
var appMenu = [CPMenu new];
newEnvMenuItem = [appMenu addItemWithTitle:"New Environment" target:navigatorControllerProxy action:@selector(showNewEnv)];
useLibMenuItem = [appMenu addItemWithTitle:"Use Library…" target:navigatorControllerProxy action:@selector(showUseLib)];
[appMenu addItem:[CPMenuItem separatorItem]];
manageDomainsMenuItem = [appMenu addItemWithTitle:"Manage Domains…" target:self action:@selector(showManageDomains)];
publishAppMenuItem = [appMenu addItemWithTitle:"" target:self action:nil];
deleteAppMenuItem = [appMenu addItemWithTitle:"Delete App…" target:self action:@selector(showDeleteApp)];
[[mainMenu addItemWithTitle:"App"] setSubmenu:appMenu];
var helpMenu = [CPMenu new];
[helpMenu addItemWithTitle:"Getting Started" target:self action:@selector(openGettingStarted)];
[helpMenu addItemWithTitle:"User Guide" target:self action:@selector(openUserGuide)];
[helpMenu addItemWithTitle:"Reference" target:self action:@selector(openReference)];
[helpMenu addItem:[CPMenuItem separatorItem]];
[helpMenu addItemWithTitle:"Blog" target:self action:@selector(openBlog)];
[helpMenu addItemWithTitle:"Twitter" target:self action:@selector(openTwitter)];
[helpMenu addItem:[CPMenuItem separatorItem]];
[helpMenu addItemWithTitle:"Contact…" target:contactPanelController action:@selector(showWindow:)];
[[mainMenu addItemWithTitle:"Help"] setSubmenu:helpMenu];
[akshellMenu, fileMenu, editMenu, goMenu, appMenu, helpMenu].forEach(
function (menu) { [menu setAutoenablesItems:NO]; });
[mainMenu addItem:[CPMenuItem separatorItem]];
toolbarItems = {};
toolbar = [CPToolbar new];
[toolbar setDelegate:self];
[mainWindow setToolbar:toolbar];
[
"username", "apps", "app",
"app.isPublic", "app.code", "app.envs", "app.libs", "app.buffers", "app.bufferIndex", "app.buffer",
"app.buffer.name", "app.buffer.isModified", "app.buffer.isEditable",
"app.numberOfModifiedBuffers"
].forEach(
function (keyPath) {
[DATA addObserver:self forKeyPath:keyPath options:CPKeyValueObservingOptionInitial context:keyPath];
});
}
- (void)observeValueForKeyPath:(CPString)keyPath ofObject:(id)object change:(CPDictionary)change context:(id)context // private
{
switch (context) {
case "username":
var mainMenu = [CPApp mainMenu];
for (var index = [mainMenu numberOfItems]; ![[mainMenu itemAtIndex:--index] isSeparatorItem];)
[mainMenu removeItemAtIndex:index];
if (DATA.username) {
[passwordMenuItem setTitle:"Change Password…"];
[passwordMenuItem setTarget:changePasswordPanelController];
logoutMenuItem = [mainMenu addItemWithTitle:"Log Out (" + DATA.username + ")" target:self action:@selector(logOut)];
} else {
[passwordMenuItem setTitle:"Reset Password…"];
[passwordMenuItem setTarget:resetPasswordPanelController];
[mainMenu addItemWithTitle:"Sign Up" target:signupPanelController action:@selector(showWindow:)];
[mainMenu addItemWithTitle:"Log In" target:loginPanelController action:@selector(showWindow:)];
}
break;
case "apps":
[appsMenu removeAllItems];
[appPopUpButton removeAllItems];
[appsMenu, [appPopUpButton menu]].forEach(
function (menu) {
DATA.apps.forEach(function (app) { [menu addItemWithTitle:app.name target:self action:@selector(switchApp:)]; });
});
if (DATA.apps.length) {
[[appsMenu itemAtIndex:DATA.appIndex] setState:CPOnState];
if (DATA.appIndex)
[appPopUpButton selectItemAtIndex:DATA.appIndex];
else
[[appPopUpButton itemAtIndex:0] setState:CPOnState];
}
break;
case "app":
[sidebarView setSubviews:[]];
if (DATA.app) {
if (!DATA.app.sidebarController)
DATA.app.sidebarController = [[SidebarController alloc] initWithApp:DATA.app view:sidebarView];
[DATA.app.sidebarController show];
[
[actionsMenuItem, @selector(actionsMenu)],
[openEvalMenuItem, @selector(evalMenu)],
[openPreviewMenuItem, @selector(previewMenu)]
].forEach(
function (pair) {
[[pair[0] submenu] setSupermenu:nil];
[pair[0] setSubmenu:objj_msgSend(navigatorControllerProxy, pair[1])];
});
}
setMenuItemsEnabled(
[openAppMenuItem, actionsMenuItem, modeMenuItem, manageDomainsMenuItem, deleteAppMenuItem, publishAppMenuItem],
DATA.app);
[toolbarItems["App"] setEnabled:DATA.app]
break;
case "app.isPublic":
if (DATA.app && DATA.app.isPublic) {
[publishAppMenuItem setTitle:"Unpublish App…"];
[publishAppMenuItem setAction:@selector(showUnpublishApp)];
} else {
[publishAppMenuItem setTitle:"Publish App…"];
[publishAppMenuItem setAction:@selector(showPublishApp)];
}
break;
case "app.code":
var code = DATA.app && DATA.app.code
setMenuItemsEnabled([newFileMenuItem, newFolderMenuItem, uploadFileMenuItem], code);
[toolbarItems["New"] setEnabled:code];
break;
case "app.envs":
var envs = DATA.app && DATA.app.envs;
setMenuItemsEnabled([switchToPreviewMenuItem, openPreviewMenuItem, newEnvMenuItem], envs);
[toolbarItems["Preview"] setEnabled:envs];
break;
case "app.libs":
[useLibMenuItem doSetEnabled:DATA.app && DATA.app.libs];
break;
case "app.buffers":
var buffers = DATA.app && DATA.app.buffers;
["Edit", "Eval", "Commit", "Git"].forEach(function (name) { [toolbarItems[name] setEnabled:buffers]; });
setMenuItemsEnabled([editMenuItem, evalMenuItem, commitMenuItem, gitMenuItem, openEvalMenuItem], buffers);
[selectNextModeMenuItem doSetEnabled:buffers && buffers.length];
[selectPreviousModeMenuItem doSetEnabled:buffers && buffers.length];
[selectNextTabMenuItem doSetEnabled:buffers && buffers.length > 1];
[selectPreviousTabMenuItem doSetEnabled:buffers && buffers.length > 1];
break;
case "app.buffer":
[toolbar reloadChangedToolbarItems];
var buffer = DATA.app && DATA.app.buffer;
var modeName = ModeNames[[buffer modeIndex]];
[toolbar setSelectedItemIdentifier:modeName];
[editMenuItem, evalMenuItem, commitMenuItem, gitMenuItem].forEach(
function (menuItem) { [menuItem setState:[menuItem title] == modeName ? CPOnState : CPOffState]; });
[closeMenuItem doSetEnabled:buffer];
if (buffer) {
if (!buffer.presentationController)
buffer.presentationController = [[[buffer presentationControllerClass] alloc] initWithApp:DATA.app buffer:buffer];
[presentationMultiview showView:[buffer.presentationController view]];
[buffer.presentationController focus];
[toolbarItems["Save All"] setEnabled:DATA.app.numberOfModifiedBuffers];
} else {
[presentationMultiview showView:nil];
window.focus();
}
// FALL THROUGH
case "app.buffer.name":
var image;
var title;
if (DATA.app && DATA.app.buffer) {
image = [CPImage imageFromPath:[DATA.app.buffer imageName] + "16.png"];
title = /* HAIR SPACE */ " " + [DATA.app.buffer name];
} else {
image = nil;
title = "";
}
[CPMenu setMenuBarIconImage:image];
[CPMenu setMenuBarTitle:title];
document.title = "Akshell";
break;
case "app.buffer.isModified":
var isModified = DATA.app && DATA.app.buffer && DATA.app.buffer.isModified;
[toolbarItems["Save"] setEnabled:isModified];
[saveMenuItem doSetEnabled:isModified];
break;
case "app.buffer.isEditable":
setMenuItemsEnabled([findMenuItem, findNextMenuItem, findPreviousMenuItem, goToLineMenuItem],
DATA.app && DATA.app.buffer && DATA.app.buffer.isEditable);
break;
case "app.numberOfModifiedBuffers":
var numberOfModifiedBuffers = DATA.app && DATA.app.numberOfModifiedBuffers;
[toolbarItems["Save All"] setEnabled:numberOfModifiedBuffers];
[saveAllMenuItem doSetEnabled:numberOfModifiedBuffers];
break;
}
}
- (CPArray)toolbarDefaultItemIdentifiers:(CPToolbar)aToolbar // private
{
return [
"App", CPToolbarSpaceItemIdentifier,
"New", "Save", "Save All", CPToolbarSpaceItemIdentifier,
"Edit", "Eval", "Commit", "Git", CPToolbarSpaceItemIdentifier,
"Preview", "Help"
];
}
- (CPToolbarItem)toolbar:(CPToolbar)aToolbar
itemForItemIdentifier:(CPString)itemIdentifier
willBeInsertedIntoToolbar:(BOOL)flag // private
{
var item = toolbarItems[itemIdentifier] = [[CPToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
[item setLabel:itemIdentifier];
if (itemIdentifier == "App") {
appPopUpButton = [[CPPopUpButton alloc] initWithFrame:CGRectMake(4, 8, 202, 24)];
[appPopUpButton setAutoresizingMask:CPViewWidthSizable];
if (DATA.apps.length)
[appPopUpButton selectItemAtIndex:DATA.appIndex];
var itemView = [[CPView alloc] initWithFrame:CGRectMake(0, 0, 206, 32)];
[itemView addSubview:appPopUpButton];
[item setView:itemView];
var size = [itemView frameSize];
[item setMinSize:size];
[item setMaxSize:size];
} else {
var image = [CPImage imageFromPath:itemIdentifier.replace(" ", "") + "32.png"];
[item setImage:image];
[item setMinSize:CGSizeMake(32, 32)];
var pair = {
"New": [navigatorControllerProxy, @selector(showNewFile)],
"Save": [presentationControllerProxy, @selector(save)],
"Save All": [self, @selector(saveAll)],
"Edit": [workspaceControllerProxy, @selector(switchToEdit)],
"Eval": [navigatorControllerProxy, @selector(switchToEval)],
"Commit": [workspaceControllerProxy, @selector(switchToCommit)],
"Git": [workspaceControllerProxy, @selector(switchToGit)],
"Preview": [navigatorControllerProxy, @selector(switchToPreview)],
"Help": [self, @selector(switchToHelp)],
}[itemIdentifier];
[item setTarget:pair[0]];
[item setAction:pair[1]];
}
return item;
}
- (unsigned)splitView:(CPSplitView)splitView constrainSplitPosition:(unsigned)position ofSubviewAt:(unsigned)index // private
{
position = MIN(MAX(position, 150), [splitView frameSize].width - 600);
var size = CGSizeMake(position - 35, 32);
[toolbarItems["App"] setMinSize:size];
[toolbarItems["App"] setMaxSize:size];
return position;
}
- (void)logOut // private
{
var image = [CPImage imageFromPath:"GraySpinner16.gif"];
[image setSize:CGSizeMake(16, 16)];
[logoutMenuItem setImage:image];
[[[HTTPRequest alloc] initWithMethod:"PUT" URL:"/config" target:self action:@selector(doLogOut)] send:[DATA archive]];
}
- (void)doLogOut // private
{
[[[HTTPRequest alloc] initWithMethod:"POST" URL:"/logout" target:self action:@selector(didLogOut)] send];
}
- (void)didLogOut // private
{
[DATA loadFromBasis:{username: "", email: "", appNames: ["hello-world"], libNames: [], config: {}}];
}
- (void)switchApp:(CPMenuItem)sender // private
{
var index = [[sender menu] indexOfItem:sender];
if (index == DATA.appIndex)
return;
[[appsMenu itemAtIndex:DATA.appIndex] setState:CPOffState];
[[appsMenu itemAtIndex:index] setState:CPOnState];
[appPopUpButton selectItemAtIndex:index];
[DATA setAppIndex:index];
}
- (void)didCreateAppWithName:(CPString)appName // private
{
var appNameLower = appName.toLowerCase();
for (var index = 0; index < DATA.apps.length; ++index)
if (DATA.apps[index].name.toLowerCase() > appNameLower)
break;
var item = [[CPMenuItem alloc] initWithTitle:appName action:@selector(switchApp:) keyEquivalent:nil];
[item setState:CPOnState];
[[appPopUpButton menu] insertItem:item atIndex:index];
if (DATA.apps.length) {
if (index == DATA.appIndex)
[[appPopUpButton itemAtIndex:index + 1] setState:CPOffState];
else
[appPopUpButton selectItemAtIndex:index];
[[appsMenu itemAtIndex:DATA.appIndex] setState:CPOffState];
}
[appsMenu insertItem:[item copy] atIndex:index];
DATA.apps.splice(index, 0, [[App alloc] initWithName:appName]);
[DATA setAppIndex:index];
}
- (void)switchToNextMode // private
{
[self switchToModeWithIndex:([DATA.app.buffer modeIndex] + 1) % ModeNames.length];
}
- (void)switchToPreviousMode // private
{
[self switchToModeWithIndex:([DATA.app.buffer modeIndex] || ModeNames.length) - 1];
}
- (void)switchToModeWithIndex:(unsigned)modeIndex // private
{
switch (modeIndex) {
case 0: [workspaceControllerProxy switchToEdit]; break;
case 1: [navigatorControllerProxy switchToEval]; break;
case 2: [workspaceControllerProxy switchToCommit]; break;
case 3: [workspaceControllerProxy switchToGit]; break;
}
}
- (void)showDeleteApp // private
{
[[[Confirm alloc] initWithMessage:"Are you sure you want to delete the app \"" + DATA.app.name + "\"?"
comment:"You cannot undo this action."
target:self
action:@selector(deleteApp)]
showPanel];
}
- (void)deleteApp // private
{
[[[HTTPRequest alloc] initWithMethod:"DELETE" URL:[DATA.app URL]] send];
[appsMenu removeItemAtIndex:DATA.appIndex];
[appPopUpButton removeItemAtIndex:DATA.appIndex];
DATA.apps.splice(DATA.appIndex, 1);
if (DATA.apps.length) {
[[appsMenu itemAtIndex:0] setState:CPOnState];
if (DATA.appIndex)
[appPopUpButton selectItemAtIndex:0];
else
[[appPopUpButton itemAtIndex:0] setState:CPOnState];
}
[DATA setAppIndex:0];
}
- (void)saveAll // private
{
DATA.app.buffers.forEach(function (buffer) { [buffer.presentationController save]; });
}
- (void)showPublishApp // private
{
if (DATA.username) {
[self doShowPublishApp];
} else {
[signupPanelController setTarget:self];
[signupPanelController setAction:@selector(doShowPublishApp)];
[signupPanelController showWindow:nil];
}
}
- (void)doShowPublishApp // private
{
[[[Confirm alloc] initWithMessage:"Are you sure you want to publish the app \"" + DATA.app.name + "\"?"
comment:"Its code will be available to all Akshell developers."
target:self
action:@selector(publishApp)]
showPanel];
}
- (void)publishApp // private
{
[self makeAppPublic:YES];
}
- (void)showUnpublishApp // private
{
[[[Confirm alloc] initWithMessage:"Are you sure you want to unpublish the app \"" + DATA.app.name + "\"?"
comment:"Other developers will no longer be able to use is as a library."
target:self
action:@selector(unpublishApp)]
showPanel];
}
- (void)unpublishApp // private
{
[self makeAppPublic:NO];
}
- (void)makeAppPublic:(BOOL)flag // private
{
[DATA.app setPublic:flag];
[[[HTTPRequest alloc] initWithMethod:"PUT" URL:[DATA.app URL] + "public"] send:flag];
}
- (void)showManageDomains // private
{
if (!DATA.app.manageDomainsPanelController)
DATA.app.manageDomainsPanelController = [[ManageDomainsPanelController alloc] initWithApp:DATA.app
signupPanelController:signupPanelController];
return [DATA.app.manageDomainsPanelController showWindow:nil];
}
- (void)openGettingStarted // private
{
[helpTabOpener openURL:DocsURL + "intro/"];
}
- (void)openUserGuide // private
{
[helpTabOpener openURL:DocsURL + "guide/"];
}
- (void)openReference // private
{
[helpTabOpener openURL:DocsURL + "ref/"];
}
- (void)switchToHelp // private
{
if (![helpTabOpener switchToLastTab])
[self openGettingStarted];
}
- (void)openBlog // private
{
window.open("http://blog.akshell.com/");
}
- (void)openTwitter // private
{
window.open("http://twitter.com/akshell_com/");
}
@end