-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
ContextMenuManager.ts
1335 lines (1231 loc) · 35.8 KB
/
ContextMenuManager.ts
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
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import {
CanvasItem,ClassType,
minsky, DataOp, GodleyIcon, Group, IntOp, Lock, OperationBase, PlotWidget, PubTab,
Ravel, RenderNativeWindow, Sheet, SwitchIcon,VariableBase, VariableValue, Functions, events
} from '@minsky/shared';
import { BrowserWindow, Menu, MenuItem, IpcMainEvent } from 'electron';
import { BookmarkManager } from './BookmarkManager';
import { CommandsManager } from './CommandsManager';
import { WindowManager } from './WindowManager';
import log from 'electron-log';
import JSON5 from 'json5';
export class ContextMenuManager {
private static x: number = null;
private static y: number = null;
private static showAllPlotsOnTabChecked = false;
public static async initContextMenu(event: IpcMainEvent, x: number, y: number, type: string, command: string) {
switch (type)
{
case "canvas":
{
const mainWindow = WindowManager.getMainWindow();
this.x = x;
this.y = y;
const currentTab = WindowManager.currentTab;
if (currentTab.$equal(minsky.canvas))
this.initContextMenuForWiring(mainWindow);
else if (currentTab.$equal(minsky.phillipsDiagram))
this.initContextMenuForPhillipsDiagram(mainWindow);
else
this.initContextMenuForPublication(event, mainWindow,currentTab);
}
break;
case 'publication-button':
this.initContextMenuForPublicationTabButton(event,command);
break;
case "godley":
this.initContextMenuForGodleyPopup(command,x,y);
break;
case "html-godley":
this.initContextMenuForGodleyHTMLPopup(event, command,x,y);
break;
case "ravel":
this.initContextMenuForRavelPopup(command,x,y);
break;
case "csv-import":
this.initContextMenuForCSVImport(event, command,x,y);
break;
default:
log.warn("Unknown context menu for ",type);
break;
}
}
private static async initContextMenuForPublication(event: IpcMainEvent, mainWindow: BrowserWindow, currentTab: RenderNativeWindow) {
let pubTab=new PubTab(currentTab);
const menuItems = [
new MenuItem({
label: 'Add note: please just type note directly for now',
click: ()=>{
},
enabled: false,
}),
new MenuItem({
label: 'Rotate item',
click: () => {
pubTab.rotateItemAt(this.x,this.y);
},
enabled: await pubTab.getItemAt(this.x,this.y),
}),
new MenuItem({
label: 'Toggle editor mode',
click: () => {
pubTab.toggleEditorModeAt(this.x,this.y);
},
enabled: await pubTab.getItemAt(this.x,this.y),
}),
new MenuItem({
label: 'Remove item',
click: () => {
pubTab.removeItemAt(this.x,this.y);
},
enabled: await pubTab.getItemAt(this.x,this.y),
}),
];
ContextMenuManager.buildAndDisplayContextMenu(menuItems, mainWindow);
return;
}
private static async initContextMenuForPublicationTabButton(event: IpcMainEvent, command: string) {
let pubTab=new PubTab(command);
const menuItems = [
new MenuItem({
label: 'Rename publication tab',
click: async () => {
await CommandsManager.renamePubTab(command);
event.sender.send(events.PUB_TAB_REMOVED);
}
}),
new MenuItem({
label: 'Remove publication tab',
click: async () => {
event.sender.send(events.CHANGE_MAIN_TAB);
setTimeout(async ()=>{
await pubTab.removeSelf();
event.sender.send(events.PUB_TAB_REMOVED);
},100); // allow enough time for renderer to switch to canvas tabs before removing this tab
}
}),
];
ContextMenuManager.buildAndDisplayContextMenu(menuItems, WindowManager.getMainWindow());
return;
}
private static async initContextMenuForPhillipsDiagram(mainWindow: BrowserWindow) {
const menuItems = [
new MenuItem({
label: 'Rotate',
click: async () => {
minsky.phillipsDiagram.startRotatingItem(this.x,this.y);
},
}),
];
ContextMenuManager.buildAndDisplayContextMenu(menuItems, mainWindow);
}
private static async initContextMenuForWiring(mainWindow: BrowserWindow) {
try {
const isWirePresent = await minsky.canvas.getWireAt(this.x, this.y);
const isWireVisible = await minsky.canvas.wire.visible();
const itemInfo = await CommandsManager.getItemInfo(this.x, this.y);
if (isWirePresent && isWireVisible && (itemInfo?.classType != ClassType.Group || itemInfo?.displayContents)) {
ContextMenuManager.buildAndDisplayContextMenu(
ContextMenuManager.wireContextMenu(),
mainWindow
);
return;
}
if (itemInfo?.classType) {
switch (itemInfo?.classType) {
case ClassType.GodleyIcon:
ContextMenuManager.buildAndDisplayContextMenu(
await ContextMenuManager.rightMouseGodley(itemInfo),
mainWindow
);
break;
case ClassType.Group:
ContextMenuManager.buildAndDisplayContextMenu(
await ContextMenuManager.rightMouseGroup(itemInfo),
mainWindow
);
break;
default:
ContextMenuManager.buildAndDisplayContextMenu(
await ContextMenuManager.contextMenu(itemInfo),
mainWindow
);
break;
}
return;
}
ContextMenuManager.buildAndDisplayContextMenu(
await ContextMenuManager.canvasContext(),
mainWindow
);
return;
} catch (error) {
console.error(
'🚀 ~ file: contextMenuManager.ts ~ line 117 ~ ContextMenuManager ~ mainWindow.webContents.on ~ error',
error
);
}
}
private static async rightMouseGodley(
itemInfo: CanvasItem
): Promise<MenuItem[]> {
if (await CommandsManager.selectVar(this.x, this.y)) {
const menuItems: MenuItem[] = [
new MenuItem({
label: 'Copy',
click: () => {minsky.canvas.copyItem();}
}),
new MenuItem({
label: 'Rename all instances',
click: async () => {
await CommandsManager.renameAllInstances(itemInfo);
},
}),
];
return menuItems;
} else {
return await ContextMenuManager.contextMenu(itemInfo);
}
}
private static async rightMouseGroup(
itemInfo: CanvasItem
): Promise<MenuItem[]> {
if (await CommandsManager.selectVar(this.x, this.y)) {
const menuItems = [
new MenuItem({
label: 'Edit',
click: async () => {
await CommandsManager.editVar();
},
}),
new MenuItem({
label: 'Copy',
click: () => {minsky.canvas.copyItem();}
}),
new MenuItem({
label: 'Remove',
click: () => {minsky.canvas.removeItemFromItsGroup();}
}),
];
return menuItems;
} else {
return await ContextMenuManager.contextMenu(itemInfo);
}
}
private static wireContextMenu(): MenuItem[] {
const menuItems = [
new MenuItem({
label: 'Description',
click: () => {CommandsManager.postNote('wire');}
}),
new MenuItem({
label: 'Straighten',
click: () => {minsky.canvas.wire.straighten();}
}),
new MenuItem({
label: 'Delete wire',
click: () => {minsky.canvas.deleteWire();}
}),
];
return menuItems;
}
private static async canvasContext(): Promise<MenuItem[]> {
const selectedItems = minsky.canvas.selection.items;
const selectionSize = await selectedItems.size();
const ravelsSelected = await minsky.canvas.ravelsSelected();
const menuItems = [
new MenuItem({
label: 'Cut',
click: () => {minsky.cut();},
enabled: selectionSize > 0
}),
new MenuItem({
label: 'Copy selection',
click: () => {minsky.copy();},
enabled: selectionSize > 0
}),
new MenuItem({
label: 'Save selection as',
click: async () => {
await CommandsManager.saveSelectionAsFile();
},
enabled: selectionSize > 0
}),
new MenuItem({
label: 'Paste selection',
click: () => {
CommandsManager.pasteAt(this.x, this.y);
},
}),
new MenuItem({
label: 'Bookmark here',
click: async () => {
await CommandsManager.bookmarkAt(this.x, this.y);
},
}),
new MenuItem({
label: 'Group',
click: () => {minsky.canvas.groupSelection();}
}),
new MenuItem({
label: 'Link selected Ravels',
click: async () => {minsky.canvas.lockRavelsInSelection();},
enabled: ravelsSelected > 1
}),
new MenuItem({
label: 'Unlink selected Ravels',
click: async () => {minsky.canvas.unlockRavelsInSelection();},
enabled: ravelsSelected > 0
}),
new MenuItem({
label: 'Open master group',
click: () => {
minsky.openModelInCanvas();
BookmarkManager.updateBookmarkList();
}
}),
];
return menuItems;
}
private static buildAndDisplayContextMenu(
menuItems: MenuItem[],
mainWindow: Electron.BrowserWindow
) {
if (menuItems.length) {
const menu = Menu.buildFromTemplate([
new MenuItem({
label: 'Help',
visible:
WindowManager.currentTab.$equal(minsky.canvas),
click: async () => {
await CommandsManager.help(this.x, this.y);
},
}),
...menuItems,
]);
menu.popup({
window: mainWindow,
x: this.x,
y: this.y + WindowManager.electronTopOffset,
});
}
}
private static async contextMenu(itemInfo: CanvasItem) {
let menuItems: MenuItem[] = [
new MenuItem({
label: 'Description',
click: () => {
CommandsManager.postNote('item');
},
}),
];
switch (itemInfo?.classType) {
case ClassType.Variable:
case ClassType.VarConstant:
menuItems = [
...menuItems,
...(await ContextMenuManager.buildContextMenuForVariables(itemInfo)),
];
break;
case ClassType.Operation:
case ClassType.IntOp:
case ClassType.DataOp:
case ClassType.UserFunction:
menuItems = [
...menuItems,
...(await ContextMenuManager.buildContextMenuForOperations(itemInfo)),
];
break;
case ClassType.PlotWidget:
menuItems = [
...menuItems,
...(await ContextMenuManager.buildContextMenuForPlotWidget(itemInfo)),
];
break;
case ClassType.GodleyIcon:
menuItems = [
...menuItems,
...(await ContextMenuManager.buildContextMenuForGodleyIcon(itemInfo)),
];
break;
case ClassType.Group:
menuItems = [
...menuItems,
...(await ContextMenuManager.buildContextMenuForGroup()),
];
break;
case ClassType.Item:
menuItems = [
...menuItems,
new MenuItem({
label: 'Copy item',
click: async () => {minsky.canvas.copyItem();}
}),
];
break;
case ClassType.SwitchIcon:
menuItems = [
...menuItems,
...(await ContextMenuManager.buildContextMenuForSwitchIcon()),
];
break;
case ClassType.Ravel:
menuItems = [
...menuItems,
...(await ContextMenuManager.buildContextMenuForRavel(new Ravel(minsky.canvas.item))),
];
break;
case ClassType.Lock:
menuItems = [
...menuItems,
...(await ContextMenuManager.buildContextMenuForLock()),
];
break;
case ClassType.Sheet:
let sheet=new Sheet(minsky.canvas.item);
menuItems = [
...menuItems,
new MenuItem({
label: 'Row Slices',
submenu: [
{
label: 'Head',
click: () => {sheet.showRowSlice("head");}
},
{
label: 'Tail',
click: () => {sheet.showRowSlice("tail");}
},
{
label: 'Head & Tail',
click: () => {sheet.showRowSlice("headAndTail");}
},
]
}),
new MenuItem({
label: 'Column Slices',
submenu: [
{
label: 'Head',
click: () => {sheet.showColSlice("head");}
},
{
label: 'Tail',
click: () => {sheet.showColSlice("tail");}
},
{
label: 'Head & Tail',
click: () => {sheet.showColSlice("headAndTail");}
},
]
}),
];
break;
default:
break;
}
menuItems = [
...menuItems,
new MenuItem({
label: `Rotate ${itemInfo.classType}`,
click: () => {
minsky.canvas.rotateItem(this.x, this.y);
}
}),
new MenuItem({
label: 'Add item to a publication tab',
submenu: await ContextMenuManager.pubTabMenu(),
}),
new MenuItem({
label: `Delete ${itemInfo.classType}`,
click: () => {
CommandsManager.deleteCurrentItemHavingId(itemInfo.id);
},
}),
];
return menuItems;
}
private static async pubTabMenu() {
let pubTabs=await minsky.publicationTabs.$properties();
let menu=[];
for (let i=0; i<pubTabs.length; ++i) {
let j=i;
menu.push({
label: pubTabs[i].name,
click: ()=>{minsky.addCanvasItemToPublicationTab(j);}
});
}
return menu;
}
private static async buildContextMenuForPlotWidget(
itemInfo: CanvasItem
): Promise<MenuItem[]> {
const plot=new PlotWidget(minsky.canvas.item);
const menuItems = [
new MenuItem({
label: 'Expand',
click: async () => {
await CommandsManager.expandPlot(itemInfo);
},
}),
new MenuItem({
label: 'Make Group Plot',
click: async () => {plot.makeDisplayPlot();}
}),
new MenuItem({
label: 'Options',
click: async () => {
await CommandsManager.openPlotWindowOptions(itemInfo);
},
}),
new MenuItem({
label: 'Set options as default',
click: async () => {
minsky.canvas.setDefaultPlotOptions();
},
}),
new MenuItem({
label: 'Apply default options',
click: async () => {
minsky.canvas.applyDefaultPlotOptions();
},
}),
new MenuItem({
label: 'Pen Styles',
click: () => {
WindowManager.createPopupWindowWithRouting({
title: `Pen Styles`,
url: `#/headless/menu/context-menu/pen-styles`,
height: 700,
width: 350,
});
},
}),
new MenuItem({
label: 'Export as CSV',
click: async () => {
await CommandsManager.exportItemAsCSV(plot);
},
}),
new MenuItem({
label: 'Export Image As',
submenu: [
{
label: 'SVG',
click: async () => {
CommandsManager.exportItemAsImageDialog(plot, 'svg', 'SVG');
},
},
{
label: 'PDF',
click: async () => {
CommandsManager.exportItemAsImageDialog(plot, 'pdf', 'PDF');
},
},
{
label: 'PostScript',
click: async () => {
CommandsManager.exportItemAsImageDialog(plot, 'ps', 'PostScript');
},
},
{
label: 'EMF',
visible: Functions.isWindows(),
click: async () => {
CommandsManager.exportItemAsImageDialog(plot, 'emf', 'EMF');
},
},
{
label: 'Portale Network Graphics',
click: async () => {
CommandsManager.exportItemAsImageDialog(plot, 'png', 'Portale Network Graphics');
},
},
],
}),
];
return menuItems;
}
private static async buildContextMenuForGodleyIcon(
itemInfo: CanvasItem
): Promise<MenuItem[]> {
let godley=new GodleyIcon(minsky.canvas.item);
const displayVariableChecked = await godley.variableDisplay();
const rowColButtonsChecked = await godley.buttonDisplay();
const editorModeChecked = await godley.editorMode();
const menuItems = [
new MenuItem({
label: 'Open Godley Table',
click: async () => {
await CommandsManager.openGodleyTable(itemInfo);
},
}),
new MenuItem({
label: 'Title',
click: () => {
CommandsManager.editGodleyTitle(godley);
},
}),
new MenuItem({
label: 'Set currency',
click: () => {
CommandsManager.setGodleyCurrency();
},
}),
new MenuItem({
label: 'Editor mode',
checked: editorModeChecked,
type: 'checkbox',
click: async () => {godley.toggleEditorMode();}
}),
new MenuItem({
label: 'Row/Col buttons',
checked: rowColButtonsChecked,
type: 'checkbox',
click: async () => {godley.toggleButtons();}
}),
new MenuItem({
label: 'Display variables',
type: 'checkbox',
checked: displayVariableChecked,
click: async () => {godley.toggleVariableDisplay();}
}),
new MenuItem({
label: 'Copy flow variables',
click: async () => {minsky.canvas.copyAllFlowVars();}
}),
new MenuItem({
label: 'Copy stock variables',
click: async () => {minsky.canvas.copyAllStockVars();}
}),
new MenuItem({
label: 'Export as',
submenu: [
{
label: 'CSV',
click: async () => {
await CommandsManager.exportGodleyAs('csv');
},
},
{
label: 'LaTeX',
click: async () => {
await CommandsManager.exportGodleyAs('tex');
},
},
],
}),
];
return menuItems;
}
private static async buildContextMenuForOperations(
itemInfo: CanvasItem
): Promise<MenuItem[]> {
let op=new OperationBase(minsky.canvas.item);
let portValues;
await op.portValues().
then((x)=>{portValues=x;}).
catch((x)=>{portValues = 'unknown';});
let menuItems = [
new MenuItem({ label: `Port values ${portValues}` }),
new MenuItem({
label: 'Edit',
click: async () => {
await CommandsManager.editItem(itemInfo.classType);
},
}),
];
// TODO data is obsolete
if (await op.type() === 'data') {
menuItems.push(
new MenuItem({
label: 'Import Data',
click: async () => {
const filePath = await CommandsManager.getFilePathUsingSaveDialog();
if (filePath) {(new DataOp(op)).readData(filePath);}
}
})
);
}
menuItems = [
...menuItems,
new MenuItem({
label: 'Copy item',
click: async () => {minsky.canvas.copyItem();}
}),
new MenuItem({
label: 'Flip',
click: async () => {
await CommandsManager.flip();
},
}),
];
if (await op.type() === 'integrate') {
menuItems.push(
new MenuItem({
label: 'Toggle var binding',
click: async () => {
(new IntOp(op)).toggleCoupled();
CommandsManager.requestRedraw();
},
})
);
menuItems.push(
new MenuItem({
label: 'Select all instances',
click: () => {minsky.canvas.selectAllVariables();}
})
);
menuItems.push(
new MenuItem({
label: 'Rename all instances',
click: async () => {
await CommandsManager.renameAllInstances(itemInfo);
},
})
);
}
return menuItems;
}
private static async buildContextMenuForGroup(): Promise<MenuItem[]> {
let group=new Group(minsky.canvas.item);
const menuItems = [
new MenuItem({
label: 'Edit',
click: async () => {
await CommandsManager.editItem(ClassType.Group);
},
}),
new MenuItem({
label: 'Open in canvas',
click: async () => {
minsky.openGroupInCanvas();
BookmarkManager.updateBookmarkList();
}
}),
new MenuItem({
label: 'Zoom to display',
click: async () => {
minsky.canvas.zoomToDisplay();
await CommandsManager.requestRedraw();
},
}),
new MenuItem({
label: 'Remove plot icon',
click: async () => {
group.removeDisplayPlot();
await CommandsManager.requestRedraw();
},
}),
new MenuItem({
label: 'Copy',
click: () => {minsky.canvas.copyItem();}
}),
new MenuItem({
label: 'Make subroutine',
click: () => {group.makeSubroutine();}
}),
new MenuItem({
label: 'Save group as',
click: async () => {
await CommandsManager.saveGroupAsFile();
},
}),
new MenuItem({
label: 'Flip',
click: async () => {
await CommandsManager.flip();
},
}),
new MenuItem({
label: 'Flip Contents',
click: async () => {
group.flipContents();
CommandsManager.requestRedraw();
},
}),
new MenuItem({
label: 'Ungroup',
click: async () => {
minsky.canvas.ungroupItem();
CommandsManager.requestRedraw();
},
}),
];
return menuItems;
}
private static async buildContextMenuForRavel(ravel: Ravel): Promise<MenuItem[]> {
const aggregations = [{label: 'Σ', value: 'sum'},{label: 'Π', value: 'prod'},{label:'av',value:'av'},{label: 'σ', value: 'stddev'},{label: 'min', value: 'min'},{label: 'max', value: 'max'}];
const handleIndex = await ravel.selectedHandle();
const sortOrder = await ravel.sortOrder();
const editorMode = await ravel.editorMode();
const ravelsSelected = await minsky.canvas.ravelsSelected();
// may be null if ravel.lockGroup is null, ie ravel is not part of a "RavelLockGroup"
const allLockHandles = await ravel.lockGroup.allLockHandles();
const linkHandlesAvailable = ravelsSelected > 1 || allLockHandles!==null && allLockHandles.length>0;
const unlinkAvailable = allLockHandles!==null;
const handleAvailable = handleIndex !== -1;
let menuItems = [
new MenuItem({
label: 'Editor mode',
type: 'checkbox',
checked: editorMode,
click: () => {ravel.toggleEditorMode();}
}),
new MenuItem({
label: 'Export as CSV',
click: async () => {
await CommandsManager.exportItemAsCSV(ravel);
},
}),
new MenuItem({
label: 'Set next aggregation',
submenu: aggregations.map(agg => ({
label: agg.label,
click: async () => {ravel.nextReduction(agg.value);}
}))
}),
new MenuItem({
label: 'Collapse all handles',
click: async () => {ravel.collapseAllHandles(true);}
}),
new MenuItem({
label: 'Expand all handles',
click: async () => {ravel.collapseAllHandles(false);}
}),
new MenuItem({
label: 'Flip',
click: async () => {ravel.flipped(!await ravel.flipped());}
}),
new MenuItem({
label: 'Link specific handles',
click: async () => {
CommandsManager.lockSpecificHandles(ravel);
},
enabled: linkHandlesAvailable
}),
new MenuItem({
label: 'Unlink',
enabled: unlinkAvailable,
click: async () => {
ravel.leaveLockGroup();
CommandsManager.requestRedraw();
},
})
];
let valueSort=(type: string,dir: string)=>{
return type+dir[0].toUpperCase()+dir.slice(1);
};
menuItems.push(...[new MenuItem(
{
label: 'Toggle axis calipers',
enabled: handleAvailable,
click: async () => {
ravel.toggleDisplayFilterCaliper();
ravel.broadcastStateToLockGroup();
}
}),
new MenuItem(
{
label: 'Sort axis',
enabled: handleAvailable,
submenu: ['none','forward','reverse'].map(so =>(<any>{
label: so,
type: 'radio',
checked: sortOrder == valueSort('static',so),
click: () => {
ravel.setSortOrder(valueSort('static',so));
ravel.broadcastStateToLockGroup();
minsky.reset();
}
})).concat(
['forward','reverse'].map(vso =>(<any>{
label: `${vso} dynamically`,
type: 'radio',
checked: sortOrder == valueSort('dynamic',vso),
click: async () => {
ravel.sortByValue(vso);
ravel.setSortOrder(valueSort('dynamic',vso));
ravel.broadcastStateToLockGroup();
minsky.reset();
}
})))
}),
new MenuItem({
label: 'Pick axis slices',
enabled: handleAvailable,
click: () => {
CommandsManager.pickSlices(ravel,handleIndex);
}
}),
new MenuItem({
label: 'Axis properties',
enabled: handleAvailable,
submenu: [
{
label: 'Description',
click: async () => {
await CommandsManager.editHandleDescription(ravel,handleIndex);
}
},
{
label: 'Dimension',
click: async () => {
await CommandsManager.editHandleDimension(ravel,handleIndex);
}
},
{
label: 'Set aggregation',
submenu: aggregations.map(agg => ({
label: agg.label,
click: () => {
ravel.handleSetReduction(handleIndex, agg.value);
}
}))
}
]
})]);
return menuItems;
}
private static async buildContextMenuForSwitchIcon(): Promise<MenuItem[]> {
let switchIcon=new SwitchIcon(minsky.canvas.item);
const menuItems = [
new MenuItem({
label: 'Add case',
click: async () => {switchIcon.setNumCases(await switchIcon.numCases()+1);},
}),
new MenuItem({
label: 'Delete case',
click: async () => {switchIcon.setNumCases(await switchIcon.numCases()-1);},
}),
new MenuItem({
label: 'Flip',
click: async () => {
await CommandsManager.flipSwitch();
},
}),
];
return menuItems;
}
private static async buildContextMenuForLock(): Promise<MenuItem[]> {
let ravel=new Lock(minsky.canvas.item);
return [
new MenuItem({
label: (await ravel.locked())? 'Unlock': 'Lock',
click: () => {ravel.toggleLocked();}
}),
new MenuItem({
label: 'Apply state to Ravel',
click: () => {ravel.applyLockedStateToRavel();}
}),
];
}