@lvce-editor/title-bar-worker 1.10.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/titleBarWorkerMain.js +1590 -1504
- package/package.json +1 -1
|
@@ -815,6 +815,9 @@ const createRpc = ipc => {
|
|
|
815
815
|
},
|
|
816
816
|
invokeAndTransfer(method, ...params) {
|
|
817
817
|
return invokeAndTransfer(ipc, method, ...params);
|
|
818
|
+
},
|
|
819
|
+
async dispose() {
|
|
820
|
+
await ipc?.dispose();
|
|
818
821
|
}
|
|
819
822
|
};
|
|
820
823
|
return rpc;
|
|
@@ -873,41 +876,25 @@ const isEqual$2 = (oldState, newState) => {
|
|
|
873
876
|
return oldState.titleBarEntries === newState.titleBarEntries && oldState.width === newState.width && oldState.focusedIndex === newState.focusedIndex && oldState.isMenuOpen === newState.isMenuOpen;
|
|
874
877
|
};
|
|
875
878
|
|
|
876
|
-
const DiffEntries = {
|
|
877
|
-
__proto__: null,
|
|
878
|
-
diffType: diffType$2,
|
|
879
|
-
isEqual: isEqual$2
|
|
880
|
-
};
|
|
881
|
-
|
|
882
879
|
const diffType$1 = RenderFocusedIndex;
|
|
883
880
|
const isEqual$1 = (oldState, newState) => {
|
|
884
881
|
return oldState.focusedIndex === newState.focusedIndex && oldState.isMenuOpen === newState.isMenuOpen;
|
|
885
882
|
};
|
|
886
883
|
|
|
887
|
-
const DiffFocusedIndex = {
|
|
888
|
-
__proto__: null,
|
|
889
|
-
diffType: diffType$1,
|
|
890
|
-
isEqual: isEqual$1
|
|
891
|
-
};
|
|
892
|
-
|
|
893
884
|
const diffType = RenderMenus;
|
|
894
885
|
const isEqual = (oldState, newState) => {
|
|
895
886
|
return oldState.menus === newState.menus;
|
|
896
887
|
};
|
|
897
888
|
|
|
898
|
-
const
|
|
899
|
-
|
|
900
|
-
diffType,
|
|
901
|
-
isEqual
|
|
902
|
-
};
|
|
903
|
-
|
|
904
|
-
const modules = [DiffEntries, DiffFocusedIndex, DiffMenus];
|
|
889
|
+
const modules = [isEqual$2, isEqual$1, isEqual];
|
|
890
|
+
const numbers = [diffType$2, diffType$1, diffType];
|
|
905
891
|
|
|
906
892
|
const diff = (oldState, newState) => {
|
|
907
893
|
const diffResult = [];
|
|
908
|
-
for (
|
|
909
|
-
|
|
910
|
-
|
|
894
|
+
for (let i = 0; i < modules.length; i++) {
|
|
895
|
+
const fn = modules[i];
|
|
896
|
+
if (!fn(oldState, newState)) {
|
|
897
|
+
diffResult.push(numbers[i]);
|
|
911
898
|
}
|
|
912
899
|
}
|
|
913
900
|
return diffResult;
|
|
@@ -941,215 +928,12 @@ const diff2 = uid => {
|
|
|
941
928
|
return diff(oldState, newState);
|
|
942
929
|
};
|
|
943
930
|
|
|
944
|
-
const
|
|
945
|
-
const MenuBar = 'menubar';
|
|
946
|
-
const MenuItem$1 = 'menuitem';
|
|
947
|
-
const MenuItemCheckBox = 'menuitemcheckbox';
|
|
948
|
-
const None$1 = 'none';
|
|
949
|
-
const Separator$1 = 'separator';
|
|
950
|
-
|
|
951
|
-
const HandleClick = 'handleClick';
|
|
952
|
-
const HandleClickMinimize = 'handleClickMinimize';
|
|
953
|
-
const HandleClickToggleClose = 'handleClickToggleClose';
|
|
954
|
-
const HandleClickToggleMaximize = 'handleClickToggleMaximize';
|
|
955
|
-
const HandleFocusIn = 'handleFocusIn';
|
|
956
|
-
const HandleFocusOut = 'handleFocusOut';
|
|
957
|
-
const HandlePointerOut = 'handlePointerOut';
|
|
958
|
-
const HandlePointerOver = 'handlePointerOver';
|
|
959
|
-
const HandleMenuClick = 'handleMenuClick';
|
|
960
|
-
const HandleMenuMouseOver = 'handleMenuMouseOver';
|
|
961
|
-
|
|
962
|
-
const Menu = 'Menu';
|
|
963
|
-
const MenuItem = 'MenuItem';
|
|
964
|
-
const MenuItemFocused = 'MenuItemFocused';
|
|
965
|
-
const MenuItemSeparator = 'MenuItemSeparator';
|
|
966
|
-
const MenuItemSeparatorLine = 'MenuItemSeparatorLine';
|
|
967
|
-
const MenuItemSubMenu = 'MenuItemSubMenu';
|
|
968
|
-
const MenuItemSubMenuArrowRight = 'MenuItemSubMenuArrowRight';
|
|
969
|
-
const TitleBarEntryActive = 'TitleBarEntryActive';
|
|
970
|
-
const TitleBarTopLevelEntry = 'TitleBarTopLevelEntry';
|
|
971
|
-
const TitleBarTopLevelEntryLabel = 'TitleBarTopLevelEntryLabel';
|
|
972
|
-
|
|
973
|
-
const Button = 1;
|
|
974
|
-
const Div = 4;
|
|
975
|
-
const Text = 12;
|
|
976
|
-
const I = 16;
|
|
977
|
-
const Img = 17;
|
|
978
|
-
const Span = 8;
|
|
979
|
-
|
|
980
|
-
const text = data => {
|
|
981
|
-
return {
|
|
982
|
-
type: Text,
|
|
983
|
-
text: data,
|
|
984
|
-
childCount: 0
|
|
985
|
-
};
|
|
986
|
-
};
|
|
987
|
-
|
|
988
|
-
const getItemVirtualDom = item => {
|
|
989
|
-
// @ts-ignore
|
|
990
|
-
const {
|
|
991
|
-
keyboardShortCut,
|
|
992
|
-
label,
|
|
993
|
-
isOpen,
|
|
994
|
-
isFocused
|
|
995
|
-
} = item;
|
|
996
|
-
const dom = [];
|
|
997
|
-
dom.push({
|
|
998
|
-
type: Div,
|
|
999
|
-
className: TitleBarTopLevelEntry,
|
|
1000
|
-
ariaHasPopup: true,
|
|
1001
|
-
ariaExpanded: isOpen,
|
|
1002
|
-
role: MenuItem$1,
|
|
1003
|
-
childCount: 1,
|
|
1004
|
-
ariaKeyShortcuts: keyboardShortCut
|
|
1005
|
-
});
|
|
1006
|
-
if (isOpen) {
|
|
1007
|
-
// @ts-ignore
|
|
1008
|
-
dom[0].ariaOwns = 'Menu-0';
|
|
1009
|
-
}
|
|
1010
|
-
if (isFocused) {
|
|
1011
|
-
dom[0].className += ' ' + TitleBarEntryActive;
|
|
1012
|
-
// @ts-ignore
|
|
1013
|
-
dom[0].id = 'TitleBarEntryActive';
|
|
1014
|
-
dom.push({
|
|
1015
|
-
type: Div,
|
|
1016
|
-
className: TitleBarTopLevelEntryLabel,
|
|
1017
|
-
childCount: 1
|
|
1018
|
-
});
|
|
1019
|
-
}
|
|
1020
|
-
dom.push(text(label));
|
|
1021
|
-
return dom;
|
|
1022
|
-
};
|
|
1023
|
-
const getTitleBarMenuBarItemsVirtualDom = visibleItems => {
|
|
1024
|
-
const dom = visibleItems.flatMap(getItemVirtualDom);
|
|
1025
|
-
return dom;
|
|
1026
|
-
};
|
|
1027
|
-
|
|
1028
|
-
const activeId = 'TitleBarEntryActive';
|
|
1029
|
-
const getTitleBarMenuBarVirtualDom = (visibleItems, focusedIndex) => {
|
|
1030
|
-
return [{
|
|
1031
|
-
type: Div,
|
|
1032
|
-
className: 'Viewlet TitleBarMenuBar',
|
|
1033
|
-
role: MenuBar,
|
|
1034
|
-
tabIndex: 0,
|
|
1035
|
-
childCount: visibleItems.length,
|
|
1036
|
-
onMouseDown: HandleClick,
|
|
1037
|
-
onFocusOut: HandleFocusOut,
|
|
1038
|
-
onFocusIn: HandleFocusIn,
|
|
1039
|
-
onPointerOver: HandlePointerOver,
|
|
1040
|
-
onPointerOut: HandlePointerOut,
|
|
1041
|
-
ariaActivedescendant: focusedIndex === -1 ? '' : activeId
|
|
1042
|
-
}, ...getTitleBarMenuBarItemsVirtualDom(visibleItems)];
|
|
1043
|
-
};
|
|
1044
|
-
|
|
1045
|
-
const Ellipsis = 'Ellipsis';
|
|
1046
|
-
|
|
1047
|
-
const emptyObject = {};
|
|
1048
|
-
const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
|
|
1049
|
-
const i18nString = (key, placeholders = emptyObject) => {
|
|
1050
|
-
if (placeholders === emptyObject) {
|
|
1051
|
-
return key;
|
|
1052
|
-
}
|
|
1053
|
-
const replacer = (match, rest) => {
|
|
1054
|
-
return placeholders[rest];
|
|
1055
|
-
};
|
|
1056
|
-
return key.replaceAll(RE_PLACEHOLDER, replacer);
|
|
1057
|
-
};
|
|
1058
|
-
|
|
1059
|
-
const About = 'About';
|
|
1060
|
-
const CheckForUpdates = 'Check For Updates';
|
|
1061
|
-
const ClearRecentlyOpened = 'Clear Recently Opened';
|
|
1062
|
-
const Edit$1 = 'Edit';
|
|
1063
|
-
const File$1 = 'File';
|
|
1064
|
-
const Go$1 = 'Go';
|
|
1065
|
-
const Help$1 = 'Help';
|
|
1066
|
-
const MoreDot = 'More ...';
|
|
1067
|
-
const OpenProcessExplorer = 'Open Process Explorer';
|
|
1068
|
-
const Run$1 = 'Run';
|
|
1069
|
-
const Selection$1 = 'Selection';
|
|
1070
|
-
const Terminal$1 = 'Terminal';
|
|
1071
|
-
const ToggleDeveloperTools = 'Toggle Developer Tools';
|
|
1072
|
-
const View$1 = 'View';
|
|
1073
|
-
|
|
1074
|
-
const moreDot = () => {
|
|
1075
|
-
return i18nString(MoreDot);
|
|
1076
|
-
};
|
|
1077
|
-
const clearRecentlyOpened = () => {
|
|
1078
|
-
return i18nString(ClearRecentlyOpened);
|
|
1079
|
-
};
|
|
1080
|
-
|
|
1081
|
-
const getVisibleTitleBarEntries = (entries, width, focusedIndex, isMenuOpen) => {
|
|
1082
|
-
array(entries);
|
|
1083
|
-
number(width);
|
|
1084
|
-
let total = 0;
|
|
1085
|
-
const visible = [];
|
|
1086
|
-
for (let i = 0; i < entries.length; i++) {
|
|
1087
|
-
const entry = entries[i];
|
|
1088
|
-
total += entry.width;
|
|
1089
|
-
if (total >= width) {
|
|
1090
|
-
break;
|
|
1091
|
-
}
|
|
1092
|
-
const isOpen = i === focusedIndex && isMenuOpen;
|
|
1093
|
-
const isFocused = i === focusedIndex;
|
|
1094
|
-
visible.push({
|
|
1095
|
-
...entry,
|
|
1096
|
-
isOpen,
|
|
1097
|
-
isFocused
|
|
1098
|
-
});
|
|
1099
|
-
}
|
|
1100
|
-
const hasOverflow = visible.length < entries.length;
|
|
1101
|
-
if (hasOverflow) {
|
|
1102
|
-
const padding = 8;
|
|
1103
|
-
const moreIconWidth = 22;
|
|
1104
|
-
const totalPadding = padding * 2;
|
|
1105
|
-
const hasStillOverflow = total + moreIconWidth + totalPadding > width;
|
|
1106
|
-
if (hasStillOverflow) {
|
|
1107
|
-
visible.pop();
|
|
1108
|
-
}
|
|
1109
|
-
visible.push({
|
|
1110
|
-
ariaLabel: moreDot(),
|
|
1111
|
-
icon: Ellipsis,
|
|
1112
|
-
label: '',
|
|
1113
|
-
width: moreIconWidth + totalPadding
|
|
1114
|
-
});
|
|
1115
|
-
}
|
|
1116
|
-
return visible;
|
|
1117
|
-
};
|
|
1118
|
-
|
|
1119
|
-
const renderEntries = (oldState, newState) => {
|
|
1120
|
-
const visibleEntries = getVisibleTitleBarEntries(newState.titleBarEntries, newState.width, newState.focusedIndex, newState.isMenuOpen);
|
|
1121
|
-
const dom = getTitleBarMenuBarVirtualDom(visibleEntries, newState.focusedIndex);
|
|
1122
|
-
return ['Viewlet.setDom2', newState.uid, dom];
|
|
1123
|
-
};
|
|
1124
|
-
|
|
1125
|
-
const SetFocusedIndex = 'setFocusedIndex';
|
|
1126
|
-
const SetMenus = 'setMenus';
|
|
1127
|
-
|
|
1128
|
-
const renderFocusedIndex = (oldState, newState) => {
|
|
1129
|
-
return ['Viewlet.send', newState.uid, /* method */SetFocusedIndex, /* oldFocusedIndex */oldState.focusedIndex, /* newfocusedIndex */newState.focusedIndex, /* oldIsMenuOpen */oldState.isMenuOpen, /* newIsMenuOpen */newState.isMenuOpen];
|
|
1130
|
-
};
|
|
931
|
+
const commandsIds = ['closeMenu', 'handleClickAt', 'focus', 'focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusPrevious', 'handleClick', 'handleFocus', 'handleFocusOut', 'handleKeyArrowDown', 'handleKeyArrowLeft', 'handleKeyArrowRight', 'handleKeyArrowUp', 'handleKeyEnd', 'handleKeyEnter', 'handleKeyEscape', 'handleKeyHome', 'handleKeySpace', 'handleMenuClick', 'handleMenuMouseOver', 'handleMouseOut', 'handleMouseOver', 'handlePointerOver', 'handlePointerOut', 'toggleIndex', 'toggleMenu'];
|
|
1131
932
|
|
|
1132
|
-
const
|
|
1133
|
-
|
|
1134
|
-
if (ctrlKey) {
|
|
1135
|
-
string += 'Ctrl+';
|
|
1136
|
-
}
|
|
1137
|
-
if (shiftKey) {
|
|
1138
|
-
string += 'Shift+';
|
|
1139
|
-
}
|
|
1140
|
-
string += key.toUpperCase();
|
|
1141
|
-
return string;
|
|
933
|
+
const getCommandIds = () => {
|
|
934
|
+
return commandsIds;
|
|
1142
935
|
};
|
|
1143
936
|
|
|
1144
|
-
const Separator = 1;
|
|
1145
|
-
const None = 0;
|
|
1146
|
-
const SubMenu = 4;
|
|
1147
|
-
const Checked = 2;
|
|
1148
|
-
const Unchecked = 3;
|
|
1149
|
-
const Disabled = 5;
|
|
1150
|
-
const RestoreFocus = 6;
|
|
1151
|
-
const Ignore = 7;
|
|
1152
|
-
|
|
1153
937
|
const Backspace$1 = 1;
|
|
1154
938
|
const Tab$1 = 2;
|
|
1155
939
|
const Enter$1 = 3;
|
|
@@ -1215,1480 +999,1770 @@ const Backslash$1 = 91;
|
|
|
1215
999
|
const Star$1 = 131;
|
|
1216
1000
|
const Plus$1 = 132;
|
|
1217
1001
|
|
|
1218
|
-
const
|
|
1219
|
-
const Backspace = 'Backspace';
|
|
1220
|
-
const Tab = 'Tab';
|
|
1221
|
-
const Enter = 'Enter';
|
|
1222
|
-
const Escape = 'Escape';
|
|
1223
|
-
const Space = 'Space';
|
|
1224
|
-
const PageUp = 'PageUp';
|
|
1225
|
-
const PageDown = 'PageDown';
|
|
1226
|
-
const End = 'End';
|
|
1227
|
-
const Home = 'Home';
|
|
1228
|
-
const LeftArrow = 'LeftArrow';
|
|
1229
|
-
const UpArrow = 'UpArrow';
|
|
1230
|
-
const RightArrow = 'RightArrow';
|
|
1231
|
-
const DownArrow = 'DownArrow';
|
|
1232
|
-
const Insert = 'Insert';
|
|
1233
|
-
const Delete = 'Delete';
|
|
1234
|
-
const Digit0 = '0';
|
|
1235
|
-
const Digit1 = '1';
|
|
1236
|
-
const Digit2 = '2';
|
|
1237
|
-
const Digit3 = '3';
|
|
1238
|
-
const Digit4 = '4';
|
|
1239
|
-
const Digit5 = '5';
|
|
1240
|
-
const Digit6 = '6';
|
|
1241
|
-
const Digit7 = '7';
|
|
1242
|
-
const Digit8 = '8';
|
|
1243
|
-
const Digit9 = '9';
|
|
1244
|
-
const KeyA = 'a';
|
|
1245
|
-
const KeyB = 'b';
|
|
1246
|
-
const KeyC = 'c';
|
|
1247
|
-
const KeyD = 'd';
|
|
1248
|
-
const KeyE = 'e';
|
|
1249
|
-
const KeyF = 'f';
|
|
1250
|
-
const KeyG = 'g';
|
|
1251
|
-
const KeyH = 'h';
|
|
1252
|
-
const KeyI = 'i';
|
|
1253
|
-
const KeyJ = 'j';
|
|
1254
|
-
const KeyK = 'k';
|
|
1255
|
-
const KeyL = 'l';
|
|
1256
|
-
const KeyM = 'm';
|
|
1257
|
-
const KeyN = 'n';
|
|
1258
|
-
const KeyO = 'o';
|
|
1259
|
-
const KeyP = 'p';
|
|
1260
|
-
const KeyQ = 'q';
|
|
1261
|
-
const KeyR = 'r';
|
|
1262
|
-
const KeyS = 's';
|
|
1263
|
-
const KeyT = 't';
|
|
1264
|
-
const KeyU = 'u';
|
|
1265
|
-
const KeyV = 'v';
|
|
1266
|
-
const KeyW = 'w';
|
|
1267
|
-
const KeyX = 'x';
|
|
1268
|
-
const KeyY = 'y';
|
|
1269
|
-
const KeyZ = 'z';
|
|
1270
|
-
const F1 = 'F1';
|
|
1271
|
-
const F2 = 'F2';
|
|
1272
|
-
const F3 = 'F3';
|
|
1273
|
-
const F4 = 'F4';
|
|
1274
|
-
const F5 = 'F5';
|
|
1275
|
-
const F6 = 'F6';
|
|
1276
|
-
const Equal = '=';
|
|
1277
|
-
const Comma = ',';
|
|
1278
|
-
const Minus = 'Minus';
|
|
1279
|
-
const Backquote = 'Backquote';
|
|
1280
|
-
const Backslash = 'Backslash';
|
|
1281
|
-
const Star = '*';
|
|
1282
|
-
const Plus = '+';
|
|
1002
|
+
const FocusTitleBarMenuBar = 26;
|
|
1283
1003
|
|
|
1284
|
-
const
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1004
|
+
const getKeyBindings = () => {
|
|
1005
|
+
return [{
|
|
1006
|
+
key: DownArrow$1,
|
|
1007
|
+
command: 'TitleBarMenuBar.handleKeyArrowDown',
|
|
1008
|
+
when: FocusTitleBarMenuBar
|
|
1009
|
+
}, {
|
|
1010
|
+
key: UpArrow$1,
|
|
1011
|
+
command: 'TitleBarMenuBar.handleKeyArrowUp',
|
|
1012
|
+
when: FocusTitleBarMenuBar
|
|
1013
|
+
}, {
|
|
1014
|
+
key: RightArrow$1,
|
|
1015
|
+
command: 'TitleBarMenuBar.handleKeyArrowRight',
|
|
1016
|
+
when: FocusTitleBarMenuBar
|
|
1017
|
+
}, {
|
|
1018
|
+
key: LeftArrow$1,
|
|
1019
|
+
command: 'TitleBarMenuBar.handleKeyArrowLeft',
|
|
1020
|
+
when: FocusTitleBarMenuBar
|
|
1021
|
+
}, {
|
|
1022
|
+
key: Space$1,
|
|
1023
|
+
command: 'TitleBarMenuBar.handleKeySpace',
|
|
1024
|
+
when: FocusTitleBarMenuBar
|
|
1025
|
+
}, {
|
|
1026
|
+
key: Home$1,
|
|
1027
|
+
command: 'TitleBarMenuBar.handleKeyHome',
|
|
1028
|
+
when: FocusTitleBarMenuBar
|
|
1029
|
+
}, {
|
|
1030
|
+
key: End$1,
|
|
1031
|
+
command: 'TitleBarMenuBar.handleKeyEnd',
|
|
1032
|
+
when: FocusTitleBarMenuBar
|
|
1033
|
+
}, {
|
|
1034
|
+
key: Escape$1,
|
|
1035
|
+
command: 'TitleBarMenuBar.handleKeyEscape',
|
|
1036
|
+
when: FocusTitleBarMenuBar
|
|
1037
|
+
}];
|
|
1038
|
+
};
|
|
1039
|
+
|
|
1040
|
+
const emptyObject = {};
|
|
1041
|
+
const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
|
|
1042
|
+
const i18nString = (key, placeholders = emptyObject) => {
|
|
1043
|
+
if (placeholders === emptyObject) {
|
|
1044
|
+
return key;
|
|
1045
|
+
}
|
|
1046
|
+
const replacer = (match, rest) => {
|
|
1047
|
+
return placeholders[rest];
|
|
1048
|
+
};
|
|
1049
|
+
return key.replaceAll(RE_PLACEHOLDER, replacer);
|
|
1050
|
+
};
|
|
1051
|
+
|
|
1052
|
+
/**
|
|
1053
|
+
* @enum {string}
|
|
1054
|
+
*/
|
|
1055
|
+
const UiStrings$2 = {
|
|
1056
|
+
Copy: 'Copy',
|
|
1057
|
+
CopyLineDown: 'Copy Line Down',
|
|
1058
|
+
CopyLineUp: 'Copy Line Up',
|
|
1059
|
+
Cut: 'Cut',
|
|
1060
|
+
MoveLineDown: 'Move Line Down',
|
|
1061
|
+
MoveLineUp: 'Move Line Up',
|
|
1062
|
+
Paste: 'Paste',
|
|
1063
|
+
Redo: 'Redo',
|
|
1064
|
+
SelectAll: 'Select All',
|
|
1065
|
+
ToggleBlockComment: 'Toggle Block Comment',
|
|
1066
|
+
ToggleLineComment: 'Toggle Line Comment',
|
|
1067
|
+
Undo: 'Undo'};
|
|
1068
|
+
const cut = () => {
|
|
1069
|
+
return i18nString(UiStrings$2.Cut);
|
|
1070
|
+
};
|
|
1071
|
+
const copy = () => {
|
|
1072
|
+
return i18nString(UiStrings$2.Copy);
|
|
1073
|
+
};
|
|
1074
|
+
const paste = () => {
|
|
1075
|
+
return i18nString(UiStrings$2.Paste);
|
|
1076
|
+
};
|
|
1077
|
+
const undo = () => {
|
|
1078
|
+
return i18nString(UiStrings$2.Undo);
|
|
1079
|
+
};
|
|
1080
|
+
const redo = () => {
|
|
1081
|
+
return i18nString(UiStrings$2.Redo);
|
|
1082
|
+
};
|
|
1083
|
+
const toggleLineComment = () => {
|
|
1084
|
+
return i18nString(UiStrings$2.ToggleLineComment);
|
|
1085
|
+
};
|
|
1086
|
+
const toggleBlockComment = () => {
|
|
1087
|
+
return i18nString(UiStrings$2.ToggleBlockComment);
|
|
1088
|
+
};
|
|
1089
|
+
const selectAll = () => {
|
|
1090
|
+
return i18nString(UiStrings$2.SelectAll);
|
|
1091
|
+
};
|
|
1092
|
+
const copyLineUp = () => {
|
|
1093
|
+
return i18nString(UiStrings$2.CopyLineUp);
|
|
1094
|
+
};
|
|
1095
|
+
const copyLineDown = () => {
|
|
1096
|
+
return i18nString(UiStrings$2.CopyLineDown);
|
|
1097
|
+
};
|
|
1098
|
+
const moveLineUp = () => {
|
|
1099
|
+
return i18nString(UiStrings$2.MoveLineUp);
|
|
1100
|
+
};
|
|
1101
|
+
const moveLineDown = () => {
|
|
1102
|
+
return i18nString(UiStrings$2.MoveLineDown);
|
|
1103
|
+
};
|
|
1104
|
+
|
|
1105
|
+
const Edit$1 = 2;
|
|
1106
|
+
const File$1 = 5;
|
|
1107
|
+
const Go$1 = 6;
|
|
1108
|
+
const Help$1 = 7;
|
|
1109
|
+
const OpenRecent = 9;
|
|
1110
|
+
const Run$1 = 10;
|
|
1111
|
+
const Selection$1 = 11;
|
|
1112
|
+
const Terminal$1 = 14;
|
|
1113
|
+
const TitleBar = 15;
|
|
1114
|
+
const View$1 = 16;
|
|
1115
|
+
|
|
1116
|
+
const Separator$1 = 1;
|
|
1117
|
+
const None$1 = 0;
|
|
1118
|
+
const SubMenu = 4;
|
|
1119
|
+
const Checked = 2;
|
|
1120
|
+
const Unchecked = 3;
|
|
1121
|
+
const Disabled = 5;
|
|
1122
|
+
const RestoreFocus = 6;
|
|
1123
|
+
const Ignore = 7;
|
|
1124
|
+
|
|
1125
|
+
const menuEntrySeparator = {
|
|
1126
|
+
id: 'separator',
|
|
1127
|
+
label: '',
|
|
1128
|
+
flags: Separator$1,
|
|
1129
|
+
command: ''
|
|
1130
|
+
};
|
|
1131
|
+
|
|
1132
|
+
const id$9 = Edit$1;
|
|
1133
|
+
const getMenuEntries$d = () => {
|
|
1134
|
+
return [{
|
|
1135
|
+
id: 'undo',
|
|
1136
|
+
label: undo(),
|
|
1137
|
+
flags: Disabled,
|
|
1138
|
+
command: /* TODO */'-1'
|
|
1139
|
+
}, {
|
|
1140
|
+
id: 'redo',
|
|
1141
|
+
label: redo(),
|
|
1142
|
+
flags: Disabled,
|
|
1143
|
+
command: /* TODO */'-1'
|
|
1144
|
+
}, menuEntrySeparator, {
|
|
1145
|
+
id: 'cut',
|
|
1146
|
+
label: cut(),
|
|
1147
|
+
flags: None$1,
|
|
1148
|
+
command: /* Editor.cut */'Editor.cut'
|
|
1149
|
+
}, {
|
|
1150
|
+
id: 'copy',
|
|
1151
|
+
label: copy(),
|
|
1152
|
+
flags: None$1,
|
|
1153
|
+
command: /* Editor.copy */'Editor.copy'
|
|
1154
|
+
}, {
|
|
1155
|
+
id: 'paste',
|
|
1156
|
+
label: paste(),
|
|
1157
|
+
flags: None$1,
|
|
1158
|
+
command: /* Editor.paste */'Editor.paste'
|
|
1159
|
+
}, menuEntrySeparator, {
|
|
1160
|
+
id: 'toggle-line-comment',
|
|
1161
|
+
label: toggleLineComment(),
|
|
1162
|
+
flags: None$1,
|
|
1163
|
+
command: /* Editor.toggleLineComment */'Editor.toggleLineComment'
|
|
1164
|
+
}, {
|
|
1165
|
+
id: 'toggle-block-comment',
|
|
1166
|
+
label: toggleBlockComment(),
|
|
1167
|
+
flags: None$1,
|
|
1168
|
+
command: /* Editor.toggleBlockComment */'Editor.toggleBlockComment'
|
|
1169
|
+
}];
|
|
1170
|
+
};
|
|
1171
|
+
|
|
1172
|
+
const MenuEntriesEdit = {
|
|
1173
|
+
__proto__: null,
|
|
1174
|
+
getMenuEntries: getMenuEntries$d,
|
|
1175
|
+
id: id$9
|
|
1176
|
+
};
|
|
1177
|
+
|
|
1178
|
+
/**
|
|
1179
|
+
* @enum {string}
|
|
1180
|
+
*/
|
|
1181
|
+
const UiStrings$1 = {
|
|
1182
|
+
NewFile: 'New File',
|
|
1183
|
+
NewWindow: 'New Window',
|
|
1184
|
+
OpenFile: 'Open File',
|
|
1185
|
+
OpenFolder: 'Open Folder',
|
|
1186
|
+
OpenRecent: 'Open Recent',
|
|
1187
|
+
Exit: 'Exit',
|
|
1188
|
+
Save: 'Save',
|
|
1189
|
+
SaveAll: 'Save All'
|
|
1190
|
+
};
|
|
1191
|
+
const newFile = () => {
|
|
1192
|
+
return i18nString(UiStrings$1.NewFile);
|
|
1193
|
+
};
|
|
1194
|
+
const newWindow = () => {
|
|
1195
|
+
return i18nString(UiStrings$1.NewWindow);
|
|
1196
|
+
};
|
|
1197
|
+
const openFile = () => {
|
|
1198
|
+
return i18nString(UiStrings$1.OpenFile);
|
|
1199
|
+
};
|
|
1200
|
+
const openFolder = () => {
|
|
1201
|
+
return i18nString(UiStrings$1.OpenFolder);
|
|
1202
|
+
};
|
|
1203
|
+
const openRecent = () => {
|
|
1204
|
+
return i18nString(UiStrings$1.OpenRecent);
|
|
1205
|
+
};
|
|
1206
|
+
const save = () => {
|
|
1207
|
+
return i18nString(UiStrings$1.Save);
|
|
1208
|
+
};
|
|
1209
|
+
const saveAll = () => {
|
|
1210
|
+
return i18nString(UiStrings$1.SaveAll);
|
|
1211
|
+
};
|
|
1212
|
+
const exit = () => {
|
|
1213
|
+
return i18nString(UiStrings$1.Exit);
|
|
1214
|
+
};
|
|
1215
|
+
|
|
1216
|
+
const Web = 1;
|
|
1217
|
+
const Electron = 2;
|
|
1218
|
+
const Remote = 3;
|
|
1219
|
+
|
|
1220
|
+
const id$8 = File$1;
|
|
1221
|
+
const getMenuEntries$c = platform => {
|
|
1222
|
+
const entries = [{
|
|
1223
|
+
id: 'newFile',
|
|
1224
|
+
label: newFile(),
|
|
1225
|
+
flags: None$1,
|
|
1226
|
+
command: '-1'
|
|
1227
|
+
}, {
|
|
1228
|
+
id: 'newWindow',
|
|
1229
|
+
label: newWindow(),
|
|
1230
|
+
flags: None$1,
|
|
1231
|
+
command: /* Window.openNew */'Window.openNew'
|
|
1232
|
+
}, menuEntrySeparator, {
|
|
1233
|
+
id: 'openFile',
|
|
1234
|
+
label: openFile(),
|
|
1235
|
+
flags: None$1,
|
|
1236
|
+
command: 'Dialog.openFile'
|
|
1237
|
+
}, {
|
|
1238
|
+
id: 'openFolder',
|
|
1239
|
+
label: openFolder(),
|
|
1240
|
+
flags: RestoreFocus,
|
|
1241
|
+
command: 'Dialog.openFolder'
|
|
1242
|
+
}, {
|
|
1243
|
+
id: OpenRecent,
|
|
1244
|
+
label: openRecent(),
|
|
1245
|
+
flags: SubMenu,
|
|
1246
|
+
command: ''
|
|
1247
|
+
}, menuEntrySeparator, {
|
|
1248
|
+
id: 'save',
|
|
1249
|
+
label: save(),
|
|
1250
|
+
flags: None$1,
|
|
1251
|
+
command: 'Main.save'
|
|
1252
|
+
}, {
|
|
1253
|
+
id: 'saveAll',
|
|
1254
|
+
label: saveAll(),
|
|
1255
|
+
flags: None$1,
|
|
1256
|
+
command: 'Main.saveAll'
|
|
1257
|
+
}];
|
|
1258
|
+
if (platform === Electron) {
|
|
1259
|
+
entries.push(menuEntrySeparator, {
|
|
1260
|
+
id: 'exit',
|
|
1261
|
+
label: exit(),
|
|
1262
|
+
flags: Ignore,
|
|
1263
|
+
command: 'Chrome.exit'
|
|
1264
|
+
});
|
|
1265
|
+
}
|
|
1266
|
+
return entries;
|
|
1267
|
+
};
|
|
1268
|
+
|
|
1269
|
+
const MenuEntriesFile = {
|
|
1270
|
+
__proto__: null,
|
|
1271
|
+
getMenuEntries: getMenuEntries$c,
|
|
1272
|
+
id: id$8
|
|
1273
|
+
};
|
|
1274
|
+
|
|
1275
|
+
const id$7 = Go$1;
|
|
1276
|
+
const getMenuEntries$b = () => {
|
|
1277
|
+
return [];
|
|
1278
|
+
};
|
|
1279
|
+
|
|
1280
|
+
const MenuEntriesGo = {
|
|
1281
|
+
__proto__: null,
|
|
1282
|
+
getMenuEntries: getMenuEntries$b,
|
|
1283
|
+
id: id$7
|
|
1284
|
+
};
|
|
1285
|
+
|
|
1286
|
+
const About = 'About';
|
|
1287
|
+
const CheckForUpdates = 'Check For Updates';
|
|
1288
|
+
const ClearRecentlyOpened = 'Clear Recently Opened';
|
|
1289
|
+
const Close = 'Close';
|
|
1290
|
+
const Edit = 'Edit';
|
|
1291
|
+
const File = 'File';
|
|
1292
|
+
const Go = 'Go';
|
|
1293
|
+
const Help = 'Help';
|
|
1294
|
+
const Maximize = 'Maximize';
|
|
1295
|
+
const Minimize = 'Minimize';
|
|
1296
|
+
const MoreDot = 'More ...';
|
|
1297
|
+
const OpenProcessExplorer = 'Open Process Explorer';
|
|
1298
|
+
const Run = 'Run';
|
|
1299
|
+
const Selection = 'Selection';
|
|
1300
|
+
const Terminal = 'Terminal';
|
|
1301
|
+
const ToggleDeveloperTools = 'Toggle Developer Tools';
|
|
1302
|
+
const View = 'View';
|
|
1303
|
+
|
|
1304
|
+
const toggleDeveloperTools = () => {
|
|
1305
|
+
return i18nString(ToggleDeveloperTools);
|
|
1306
|
+
};
|
|
1307
|
+
const openProcessExplorer = () => {
|
|
1308
|
+
return i18nString(OpenProcessExplorer);
|
|
1309
|
+
};
|
|
1310
|
+
const checkForUpdates = () => {
|
|
1311
|
+
return i18nString(CheckForUpdates);
|
|
1312
|
+
};
|
|
1313
|
+
const about = () => {
|
|
1314
|
+
return i18nString(About);
|
|
1315
|
+
};
|
|
1316
|
+
|
|
1317
|
+
const isAutoUpdateSupported = platform => {
|
|
1318
|
+
if (platform !== Electron) {
|
|
1319
|
+
return false;
|
|
1320
|
+
}
|
|
1321
|
+
return false;
|
|
1322
|
+
};
|
|
1323
|
+
|
|
1324
|
+
const id$6 = Help$1;
|
|
1325
|
+
const getMenuEntries$a = async platform => {
|
|
1326
|
+
const autoUpdateSupported = isAutoUpdateSupported(platform);
|
|
1327
|
+
const entries = [];
|
|
1328
|
+
if (platform !== Web) {
|
|
1329
|
+
entries.push({
|
|
1330
|
+
id: 'toggleDeveloperTools',
|
|
1331
|
+
label: toggleDeveloperTools(),
|
|
1332
|
+
flags: None$1,
|
|
1333
|
+
command: 'Developer.toggleDeveloperTools'
|
|
1334
|
+
}, {
|
|
1335
|
+
id: 'openProcessExplorer',
|
|
1336
|
+
label: openProcessExplorer(),
|
|
1337
|
+
flags: RestoreFocus,
|
|
1338
|
+
command: 'Developer.openProcessExplorer'
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
if (autoUpdateSupported) {
|
|
1342
|
+
entries.push(menuEntrySeparator, {
|
|
1343
|
+
id: 'checkForUpdates',
|
|
1344
|
+
label: checkForUpdates(),
|
|
1345
|
+
flags: RestoreFocus,
|
|
1346
|
+
command: 'AutoUpdater.checkForUpdates'
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
if (entries.length > 0) {
|
|
1350
|
+
entries.push(menuEntrySeparator);
|
|
1416
1351
|
}
|
|
1352
|
+
entries.push({
|
|
1353
|
+
id: 'about',
|
|
1354
|
+
label: about(),
|
|
1355
|
+
flags: RestoreFocus,
|
|
1356
|
+
command: 'About.showAbout'
|
|
1357
|
+
});
|
|
1358
|
+
return entries;
|
|
1417
1359
|
};
|
|
1418
1360
|
|
|
1419
|
-
const
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
number(rawKey);
|
|
1424
|
-
const isCtrl = Boolean(rawKey & CtrlCmd);
|
|
1425
|
-
const isShift = Boolean(rawKey & Shift);
|
|
1426
|
-
const keyCode = rawKey & 0x00_00_00_ff;
|
|
1427
|
-
const key = getKeyCodeString(keyCode);
|
|
1428
|
-
return {
|
|
1429
|
-
key,
|
|
1430
|
-
isCtrl,
|
|
1431
|
-
isShift
|
|
1432
|
-
};
|
|
1361
|
+
const MenuEntriesHelp = {
|
|
1362
|
+
__proto__: null,
|
|
1363
|
+
getMenuEntries: getMenuEntries$a,
|
|
1364
|
+
id: id$6
|
|
1433
1365
|
};
|
|
1434
1366
|
|
|
1435
|
-
const
|
|
1436
|
-
|
|
1437
|
-
className: MenuItemSeparator,
|
|
1438
|
-
role: Separator$1,
|
|
1439
|
-
childCount: 1
|
|
1440
|
-
};
|
|
1441
|
-
const separatorLine = {
|
|
1442
|
-
type: Div,
|
|
1443
|
-
className: MenuItemSeparatorLine,
|
|
1444
|
-
childCount: 0
|
|
1445
|
-
};
|
|
1446
|
-
const checkboxUnchecked = {
|
|
1447
|
-
type: Div,
|
|
1448
|
-
className: MenuItem,
|
|
1449
|
-
role: MenuItemCheckBox,
|
|
1450
|
-
ariaChecked: false,
|
|
1451
|
-
tabIndex: -1,
|
|
1452
|
-
childCount: 1
|
|
1453
|
-
};
|
|
1454
|
-
const checkboxChecked = {
|
|
1455
|
-
type: Div,
|
|
1456
|
-
className: `${MenuItem} MenuItemCheckMark`,
|
|
1457
|
-
role: MenuItemCheckBox,
|
|
1458
|
-
ariaChecked: true,
|
|
1459
|
-
tabIndex: -1,
|
|
1460
|
-
childCount: 2
|
|
1367
|
+
const state$1 = {
|
|
1368
|
+
rpc: undefined
|
|
1461
1369
|
};
|
|
1462
|
-
const
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
childCount: 1
|
|
1370
|
+
const invoke = (method, ...params) => {
|
|
1371
|
+
const {
|
|
1372
|
+
rpc
|
|
1373
|
+
} = state$1;
|
|
1374
|
+
// @ts-ignore
|
|
1375
|
+
return rpc.invoke(method, ...params);
|
|
1469
1376
|
};
|
|
1470
|
-
const
|
|
1471
|
-
|
|
1472
|
-
className: MenuItemSubMenuArrowRight,
|
|
1473
|
-
childCount: 0
|
|
1377
|
+
const setRpc = rpc => {
|
|
1378
|
+
state$1.rpc = rpc;
|
|
1474
1379
|
};
|
|
1475
|
-
|
|
1476
|
-
|
|
1380
|
+
|
|
1381
|
+
const getRecentlyOpened = () => {
|
|
1382
|
+
return invoke(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
|
|
1477
1383
|
};
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
className: 'MenuItemCheckmarkIcon MaskIconCheck'
|
|
1485
|
-
}, text(label)];
|
|
1384
|
+
|
|
1385
|
+
const getTitle = uri => {
|
|
1386
|
+
if (!uri) {
|
|
1387
|
+
return '';
|
|
1388
|
+
}
|
|
1389
|
+
return uri;
|
|
1486
1390
|
};
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
} = menuItem;
|
|
1491
|
-
return [checkboxUnchecked, text(label)];
|
|
1391
|
+
|
|
1392
|
+
const moreDot = () => {
|
|
1393
|
+
return i18nString(MoreDot);
|
|
1492
1394
|
};
|
|
1493
|
-
const
|
|
1494
|
-
|
|
1495
|
-
label
|
|
1496
|
-
} = menuItem;
|
|
1497
|
-
return [disabled, text(label)];
|
|
1395
|
+
const clearRecentlyOpened = () => {
|
|
1396
|
+
return i18nString(ClearRecentlyOpened);
|
|
1498
1397
|
};
|
|
1499
|
-
|
|
1500
|
-
|
|
1398
|
+
|
|
1399
|
+
const MAX_MENU_RECENT_ENTRIES = 10;
|
|
1400
|
+
const toMenuItem = folder => {
|
|
1401
|
+
const label = getTitle(folder);
|
|
1402
|
+
return {
|
|
1501
1403
|
label,
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
if (isFocused) {
|
|
1507
|
-
className += ' ' + MenuItemFocused;
|
|
1508
|
-
}
|
|
1509
|
-
const dom = [];
|
|
1510
|
-
dom.push({
|
|
1511
|
-
type: Div,
|
|
1512
|
-
className,
|
|
1513
|
-
role: MenuItem$1,
|
|
1514
|
-
tabIndex: -1,
|
|
1515
|
-
childCount: 1
|
|
1516
|
-
}, text(label));
|
|
1517
|
-
if (key) {
|
|
1518
|
-
dom[0].childCount++;
|
|
1519
|
-
const parsedKey = parseKey(key);
|
|
1520
|
-
const keyBindingsString = getKeyBindingString(parsedKey.key, false, parsedKey.isCtrl, parsedKey.isShift);
|
|
1521
|
-
dom.push({
|
|
1522
|
-
type: Span,
|
|
1523
|
-
className: 'MenuItemKeyBinding',
|
|
1524
|
-
childCount: 1
|
|
1525
|
-
}, text(keyBindingsString));
|
|
1526
|
-
}
|
|
1527
|
-
return dom;
|
|
1404
|
+
flags: None$1,
|
|
1405
|
+
command: 'Workspace.setPath',
|
|
1406
|
+
args: [folder]
|
|
1407
|
+
};
|
|
1528
1408
|
};
|
|
1529
|
-
const
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
let className = MenuItem;
|
|
1537
|
-
className += ' ' + MenuItemSubMenu;
|
|
1538
|
-
if (isFocused) {
|
|
1539
|
-
className += ' ' + MenuItemFocused;
|
|
1409
|
+
const id$5 = OpenRecent;
|
|
1410
|
+
const getMenuEntries$9 = async () => {
|
|
1411
|
+
const allItems = await getRecentlyOpened();
|
|
1412
|
+
const itemsToShow = allItems.slice(0, MAX_MENU_RECENT_ENTRIES);
|
|
1413
|
+
const items = [];
|
|
1414
|
+
if (itemsToShow.length > 0) {
|
|
1415
|
+
items.push(...itemsToShow.map(toMenuItem), menuEntrySeparator);
|
|
1540
1416
|
}
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1417
|
+
items.push({
|
|
1418
|
+
id: 'more',
|
|
1419
|
+
label: moreDot(),
|
|
1420
|
+
flags: None$1,
|
|
1421
|
+
command: 'QuickPick.showRecent'
|
|
1422
|
+
}, menuEntrySeparator, {
|
|
1423
|
+
id: 'clearRecentlyOpened',
|
|
1424
|
+
label: clearRecentlyOpened(),
|
|
1425
|
+
flags: None$1,
|
|
1426
|
+
command: 'RecentlyOpened.clearRecentlyOpened'
|
|
1427
|
+
});
|
|
1428
|
+
return items;
|
|
1551
1429
|
};
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
case None:
|
|
1558
|
-
case RestoreFocus:
|
|
1559
|
-
case Ignore:
|
|
1560
|
-
return getMenuItemDefaultDom(menuItem);
|
|
1561
|
-
case Separator:
|
|
1562
|
-
return getMenuItemSeparatorDom();
|
|
1563
|
-
case Checked:
|
|
1564
|
-
return getMenuItemCheckedDom(menuItem);
|
|
1565
|
-
case Unchecked:
|
|
1566
|
-
return getMenuItemUncheckedDom(menuItem);
|
|
1567
|
-
case Disabled:
|
|
1568
|
-
return getMenuItemDisabledDom(menuItem);
|
|
1569
|
-
case SubMenu:
|
|
1570
|
-
return getMenuItemSubMenuDom(menuItem);
|
|
1571
|
-
default:
|
|
1572
|
-
return [];
|
|
1573
|
-
}
|
|
1430
|
+
|
|
1431
|
+
const MenuEntriesOpenRecent = {
|
|
1432
|
+
__proto__: null,
|
|
1433
|
+
getMenuEntries: getMenuEntries$9,
|
|
1434
|
+
id: id$5
|
|
1574
1435
|
};
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
className: Menu,
|
|
1580
|
-
role: Menu$1,
|
|
1581
|
-
tabIndex: -1,
|
|
1582
|
-
childCount: menuItems.length
|
|
1583
|
-
});
|
|
1584
|
-
dom.push(...menuItems.flatMap(getMenuItemVirtualDom));
|
|
1585
|
-
return dom;
|
|
1436
|
+
|
|
1437
|
+
const id$4 = Run$1;
|
|
1438
|
+
const getMenuEntries$8 = () => {
|
|
1439
|
+
return [];
|
|
1586
1440
|
};
|
|
1587
1441
|
|
|
1588
|
-
const
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
} = items;
|
|
1593
|
-
for (let i = 0; i < length; i++) {
|
|
1594
|
-
const item = items[i];
|
|
1595
|
-
const {
|
|
1596
|
-
flags,
|
|
1597
|
-
label
|
|
1598
|
-
} = item;
|
|
1599
|
-
visibleItems.push({
|
|
1600
|
-
label,
|
|
1601
|
-
flags,
|
|
1602
|
-
isFocused: i === focusedIndex,
|
|
1603
|
-
isExpanded: i === focusedIndex && expanded,
|
|
1604
|
-
level,
|
|
1605
|
-
key: item.key
|
|
1606
|
-
});
|
|
1607
|
-
}
|
|
1608
|
-
return visibleItems;
|
|
1442
|
+
const MenuEntriesRun = {
|
|
1443
|
+
__proto__: null,
|
|
1444
|
+
getMenuEntries: getMenuEntries$8,
|
|
1445
|
+
id: id$4
|
|
1609
1446
|
};
|
|
1610
1447
|
|
|
1611
|
-
const
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
}
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1448
|
+
const id$3 = Selection$1;
|
|
1449
|
+
const getMenuEntries$7 = () => {
|
|
1450
|
+
return [{
|
|
1451
|
+
id: 'selectAll',
|
|
1452
|
+
label: selectAll(),
|
|
1453
|
+
flags: None$1,
|
|
1454
|
+
command: 'Editor.selectAll'
|
|
1455
|
+
}, {
|
|
1456
|
+
id: 'copyLineUp',
|
|
1457
|
+
label: copyLineUp(),
|
|
1458
|
+
flags: None$1,
|
|
1459
|
+
command: 'Editor.copyLineUp'
|
|
1460
|
+
}, {
|
|
1461
|
+
id: 'copyLineDown',
|
|
1462
|
+
label: copyLineDown(),
|
|
1463
|
+
flags: None$1,
|
|
1464
|
+
command: 'Editor.copyLineDown'
|
|
1465
|
+
}, {
|
|
1466
|
+
id: 'moveLineUp',
|
|
1467
|
+
label: moveLineUp(),
|
|
1468
|
+
flags: Disabled,
|
|
1469
|
+
command: 'Editor.moveLineUp'
|
|
1470
|
+
}, {
|
|
1471
|
+
id: 'moveLineDown',
|
|
1472
|
+
label: moveLineDown(),
|
|
1473
|
+
flags: Disabled,
|
|
1474
|
+
command: 'Editor.moveLineDown'
|
|
1475
|
+
}];
|
|
1637
1476
|
};
|
|
1638
1477
|
|
|
1639
|
-
const
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
case RenderFocusedIndex:
|
|
1644
|
-
return renderFocusedIndex;
|
|
1645
|
-
case RenderMenus:
|
|
1646
|
-
return renderMEnus;
|
|
1647
|
-
default:
|
|
1648
|
-
throw new Error('unknown renderer');
|
|
1649
|
-
}
|
|
1478
|
+
const MenuEntriesSelection = {
|
|
1479
|
+
__proto__: null,
|
|
1480
|
+
getMenuEntries: getMenuEntries$7,
|
|
1481
|
+
id: id$3
|
|
1650
1482
|
};
|
|
1651
1483
|
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
}
|
|
1658
|
-
return commands;
|
|
1484
|
+
/**
|
|
1485
|
+
* @enum {string}
|
|
1486
|
+
*/
|
|
1487
|
+
const UiStrings = {
|
|
1488
|
+
NewTerminal: 'New Terminal'
|
|
1659
1489
|
};
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
const {
|
|
1663
|
-
oldState,
|
|
1664
|
-
newState
|
|
1665
|
-
} = get(uid);
|
|
1666
|
-
const diffResult = diff(oldState, newState);
|
|
1667
|
-
const commands = applyRender(oldState, newState, diffResult);
|
|
1668
|
-
return commands;
|
|
1490
|
+
const newTerminal = () => {
|
|
1491
|
+
return i18nString(UiStrings.NewTerminal);
|
|
1669
1492
|
};
|
|
1670
1493
|
|
|
1671
|
-
const
|
|
1494
|
+
const id$2 = Terminal$1;
|
|
1495
|
+
const getMenuEntries$6 = () => {
|
|
1496
|
+
return [{
|
|
1497
|
+
id: 'newTerminal',
|
|
1498
|
+
label: newTerminal(),
|
|
1499
|
+
flags: None$1,
|
|
1500
|
+
command: 'Layout.togglePanel',
|
|
1501
|
+
args: ['Terminal']
|
|
1502
|
+
}];
|
|
1503
|
+
};
|
|
1672
1504
|
|
|
1673
|
-
const
|
|
1674
|
-
|
|
1505
|
+
const MenuEntriesTerminal = {
|
|
1506
|
+
__proto__: null,
|
|
1507
|
+
getMenuEntries: getMenuEntries$6,
|
|
1508
|
+
id: id$2
|
|
1675
1509
|
};
|
|
1676
1510
|
|
|
1677
|
-
const
|
|
1511
|
+
const file = () => {
|
|
1512
|
+
return i18nString(File);
|
|
1513
|
+
};
|
|
1514
|
+
const edit = () => {
|
|
1515
|
+
return i18nString(Edit);
|
|
1516
|
+
};
|
|
1517
|
+
const selection = () => {
|
|
1518
|
+
return i18nString(Selection);
|
|
1519
|
+
};
|
|
1520
|
+
const view = () => {
|
|
1521
|
+
return i18nString(View);
|
|
1522
|
+
};
|
|
1523
|
+
const go = () => {
|
|
1524
|
+
return i18nString(Go);
|
|
1525
|
+
};
|
|
1526
|
+
const run = () => {
|
|
1527
|
+
return i18nString(Run);
|
|
1528
|
+
};
|
|
1529
|
+
const terminal = () => {
|
|
1530
|
+
return i18nString(Terminal);
|
|
1531
|
+
};
|
|
1532
|
+
const help = () => {
|
|
1533
|
+
return i18nString(Help);
|
|
1534
|
+
};
|
|
1535
|
+
const minimize$1 = () => {
|
|
1536
|
+
return i18nString(Minimize);
|
|
1537
|
+
};
|
|
1538
|
+
const maximize$1 = () => {
|
|
1539
|
+
return i18nString(Maximize);
|
|
1540
|
+
};
|
|
1541
|
+
const close$1 = () => {
|
|
1542
|
+
return i18nString(Close);
|
|
1543
|
+
};
|
|
1678
1544
|
|
|
1679
|
-
const
|
|
1545
|
+
const getMenuEntries$5 = () => {
|
|
1680
1546
|
return [{
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1547
|
+
id: File$1,
|
|
1548
|
+
label: file(),
|
|
1549
|
+
flags: SubMenu
|
|
1684
1550
|
}, {
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1551
|
+
id: Edit$1,
|
|
1552
|
+
label: edit(),
|
|
1553
|
+
flags: SubMenu
|
|
1688
1554
|
}, {
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1555
|
+
id: Selection$1,
|
|
1556
|
+
label: selection(),
|
|
1557
|
+
flags: SubMenu
|
|
1692
1558
|
}, {
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1559
|
+
id: View$1,
|
|
1560
|
+
label: view(),
|
|
1561
|
+
flags: SubMenu
|
|
1696
1562
|
}, {
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1563
|
+
id: Go$1,
|
|
1564
|
+
label: go(),
|
|
1565
|
+
flags: SubMenu
|
|
1700
1566
|
}, {
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1567
|
+
id: Run$1,
|
|
1568
|
+
label: run(),
|
|
1569
|
+
keyboardShortCut: 'Alt+r',
|
|
1570
|
+
flags: SubMenu
|
|
1704
1571
|
}, {
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1572
|
+
id: Terminal$1,
|
|
1573
|
+
label: terminal(),
|
|
1574
|
+
keyboardShortCut: 'Alt+t',
|
|
1575
|
+
flags: SubMenu
|
|
1708
1576
|
}, {
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1577
|
+
id: Help$1,
|
|
1578
|
+
label: help(),
|
|
1579
|
+
keyboardShortCut: 'Alt+h',
|
|
1580
|
+
flags: SubMenu
|
|
1712
1581
|
}];
|
|
1713
1582
|
};
|
|
1714
1583
|
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1584
|
+
const getMenuEntries$4 = () => {
|
|
1585
|
+
return [{
|
|
1586
|
+
id: File$1,
|
|
1587
|
+
label: file(),
|
|
1588
|
+
flags: None$1
|
|
1589
|
+
}, {
|
|
1590
|
+
id: Edit$1,
|
|
1591
|
+
label: edit(),
|
|
1592
|
+
flags: None$1
|
|
1593
|
+
}, {
|
|
1594
|
+
id: Selection$1,
|
|
1595
|
+
label: selection(),
|
|
1596
|
+
flags: None$1
|
|
1597
|
+
}, {
|
|
1598
|
+
id: View$1,
|
|
1599
|
+
label: view(),
|
|
1600
|
+
flags: None$1
|
|
1601
|
+
}, {
|
|
1602
|
+
id: Go$1,
|
|
1603
|
+
label: go(),
|
|
1604
|
+
flags: None$1
|
|
1605
|
+
}, {
|
|
1606
|
+
id: Help$1,
|
|
1607
|
+
label: help(),
|
|
1608
|
+
flags: None$1
|
|
1609
|
+
}];
|
|
1733
1610
|
};
|
|
1734
|
-
|
|
1735
|
-
|
|
1611
|
+
|
|
1612
|
+
const getFn = platform => {
|
|
1613
|
+
switch (platform) {
|
|
1614
|
+
case Web:
|
|
1615
|
+
return getMenuEntries$4;
|
|
1616
|
+
default:
|
|
1617
|
+
return getMenuEntries$5;
|
|
1618
|
+
}
|
|
1736
1619
|
};
|
|
1737
|
-
const
|
|
1738
|
-
|
|
1620
|
+
const id$1 = TitleBar;
|
|
1621
|
+
const getMenuEntries$3 = async platform => {
|
|
1622
|
+
const fn = getFn(platform);
|
|
1623
|
+
return fn();
|
|
1739
1624
|
};
|
|
1740
|
-
|
|
1741
|
-
|
|
1625
|
+
|
|
1626
|
+
const MenuEntriesTitleBar = {
|
|
1627
|
+
__proto__: null,
|
|
1628
|
+
getMenuEntries: getMenuEntries$3,
|
|
1629
|
+
id: id$1
|
|
1742
1630
|
};
|
|
1743
|
-
|
|
1744
|
-
|
|
1631
|
+
|
|
1632
|
+
const id = View$1;
|
|
1633
|
+
const getMenuEntries$2 = () => {
|
|
1634
|
+
return [];
|
|
1745
1635
|
};
|
|
1746
|
-
|
|
1747
|
-
|
|
1636
|
+
|
|
1637
|
+
const MenuEntriesView = {
|
|
1638
|
+
__proto__: null,
|
|
1639
|
+
getMenuEntries: getMenuEntries$2,
|
|
1640
|
+
id
|
|
1748
1641
|
};
|
|
1749
|
-
|
|
1750
|
-
|
|
1642
|
+
|
|
1643
|
+
const menus$1 = [MenuEntriesEdit, MenuEntriesFile, MenuEntriesGo, MenuEntriesHelp, MenuEntriesRun, MenuEntriesSelection, MenuEntriesTerminal, MenuEntriesTitleBar, MenuEntriesView, MenuEntriesOpenRecent];
|
|
1644
|
+
|
|
1645
|
+
const getMenuIds = () => {
|
|
1646
|
+
return menus$1.map(menu => menu.id);
|
|
1751
1647
|
};
|
|
1752
|
-
const
|
|
1753
|
-
|
|
1648
|
+
const getMenuEntries$1 = (id, platform) => {
|
|
1649
|
+
const menu = menus$1.find(item => item.id === id);
|
|
1650
|
+
if (!menu) {
|
|
1651
|
+
return [];
|
|
1652
|
+
}
|
|
1653
|
+
return menu.getMenuEntries(platform);
|
|
1754
1654
|
};
|
|
1755
|
-
|
|
1756
|
-
|
|
1655
|
+
|
|
1656
|
+
const getTitleBarButtonsWeb = () => {
|
|
1657
|
+
return [];
|
|
1658
|
+
};
|
|
1659
|
+
const getTitleBarButtonsRemote = () => {
|
|
1660
|
+
return [];
|
|
1661
|
+
};
|
|
1662
|
+
const getTitleBarButtonsElectron = (controlsOverlayEnabled, titleBarStyleCustom) => {
|
|
1663
|
+
if (controlsOverlayEnabled) {
|
|
1664
|
+
return [];
|
|
1665
|
+
}
|
|
1666
|
+
if (titleBarStyleCustom) {
|
|
1667
|
+
// TODO don't render title bar buttons on windows when electron window controls overlay is enabled
|
|
1668
|
+
return [{
|
|
1669
|
+
label: minimize$1(),
|
|
1670
|
+
icon: 'Minimize',
|
|
1671
|
+
id: 'Minimize',
|
|
1672
|
+
onClick: 'handleClickMinimize'
|
|
1673
|
+
}, {
|
|
1674
|
+
label: maximize$1(),
|
|
1675
|
+
icon: 'Maximize',
|
|
1676
|
+
id: 'ToggleMaximize',
|
|
1677
|
+
onClick: 'handleClickToggleMaximize'
|
|
1678
|
+
}, {
|
|
1679
|
+
label: close$1(),
|
|
1680
|
+
icon: 'ChromeClose',
|
|
1681
|
+
id: 'Close',
|
|
1682
|
+
onClick: 'handleClickClose'
|
|
1683
|
+
}];
|
|
1684
|
+
}
|
|
1685
|
+
return [];
|
|
1686
|
+
};
|
|
1687
|
+
const getTitleBarButtons = (platform, controlsOverlayEnabled, titleBarStyleCustom) => {
|
|
1688
|
+
switch (platform) {
|
|
1689
|
+
case Electron:
|
|
1690
|
+
return getTitleBarButtonsElectron(controlsOverlayEnabled, titleBarStyleCustom);
|
|
1691
|
+
case Web:
|
|
1692
|
+
return getTitleBarButtonsWeb();
|
|
1693
|
+
case Remote:
|
|
1694
|
+
return getTitleBarButtonsRemote();
|
|
1695
|
+
default:
|
|
1696
|
+
return [];
|
|
1697
|
+
}
|
|
1698
|
+
};
|
|
1699
|
+
|
|
1700
|
+
const MaskIconCheck = 'MaskIconCheck';
|
|
1701
|
+
const Menu$1 = 'Menu';
|
|
1702
|
+
const MenuItem$1 = 'MenuItem';
|
|
1703
|
+
const MenuItemCheckMark = 'MenuItemCheckMark';
|
|
1704
|
+
const MenuItemCheckmarkIcon = 'MenuItemCheckmarkIcon';
|
|
1705
|
+
const MenuItemFocused = 'MenuItemFocused';
|
|
1706
|
+
const MenuItemKeyBinding = 'MenuItemKeyBinding';
|
|
1707
|
+
const MenuItemSeparator = 'MenuItemSeparator';
|
|
1708
|
+
const MenuItemSeparatorLine = 'MenuItemSeparatorLine';
|
|
1709
|
+
const MenuItemSubMenu = 'MenuItemSubMenu';
|
|
1710
|
+
const MenuItemSubMenuArrowRight = 'MenuItemSubMenuArrowRight';
|
|
1711
|
+
const TitleBarButtons = 'TitleBarButtons';
|
|
1712
|
+
const TitleBarEntryActive = 'TitleBarEntryActive';
|
|
1713
|
+
const TitleBarIcon = 'TitleBarIcon';
|
|
1714
|
+
const TitleBarIconIcon = 'TitleBarIconIcon';
|
|
1715
|
+
const TitleBarMenuBar$1 = 'TitleBarMenuBar';
|
|
1716
|
+
const TitleBarTopLevelEntry = 'TitleBarTopLevelEntry';
|
|
1717
|
+
const TitleBarTopLevelEntryLabel = 'TitleBarTopLevelEntryLabel';
|
|
1718
|
+
const Viewlet = 'Viewlet';
|
|
1719
|
+
|
|
1720
|
+
const Menu = 'menu';
|
|
1721
|
+
const MenuBar = 'menubar';
|
|
1722
|
+
const MenuItem = 'menuitem';
|
|
1723
|
+
const MenuItemCheckBox = 'menuitemcheckbox';
|
|
1724
|
+
const None = 'none';
|
|
1725
|
+
const Separator = 'separator';
|
|
1726
|
+
|
|
1727
|
+
const Button = 1;
|
|
1728
|
+
const Div = 4;
|
|
1729
|
+
const I = 16;
|
|
1730
|
+
const Img = 17;
|
|
1731
|
+
const Span = 8;
|
|
1732
|
+
|
|
1733
|
+
const getIconVirtualDom = (icon, type = Div) => {
|
|
1734
|
+
return {
|
|
1735
|
+
type,
|
|
1736
|
+
className: `MaskIcon MaskIcon${icon}`,
|
|
1737
|
+
role: None,
|
|
1738
|
+
childCount: 0
|
|
1739
|
+
};
|
|
1757
1740
|
};
|
|
1758
|
-
|
|
1759
|
-
|
|
1741
|
+
|
|
1742
|
+
const createTitleBarButton = button => {
|
|
1743
|
+
const {
|
|
1744
|
+
id,
|
|
1745
|
+
icon,
|
|
1746
|
+
label,
|
|
1747
|
+
onClick
|
|
1748
|
+
} = button;
|
|
1749
|
+
const dom = [{
|
|
1750
|
+
type: Button,
|
|
1751
|
+
className: `TitleBarButton TitleBarButton${id}`,
|
|
1752
|
+
ariaLabel: label,
|
|
1753
|
+
childCount: 1,
|
|
1754
|
+
onClick
|
|
1755
|
+
}, getIconVirtualDom(icon, I)];
|
|
1756
|
+
return dom;
|
|
1760
1757
|
};
|
|
1761
|
-
|
|
1762
|
-
|
|
1758
|
+
|
|
1759
|
+
const mergeClassNames = (...classNames) => {
|
|
1760
|
+
return classNames.filter(Boolean).join(' ');
|
|
1763
1761
|
};
|
|
1764
|
-
const
|
|
1765
|
-
|
|
1762
|
+
const Text = 12;
|
|
1763
|
+
const text = data => {
|
|
1764
|
+
return {
|
|
1765
|
+
type: Text,
|
|
1766
|
+
text: data,
|
|
1767
|
+
childCount: 0
|
|
1768
|
+
};
|
|
1766
1769
|
};
|
|
1767
1770
|
|
|
1768
|
-
const
|
|
1769
|
-
const
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
const Terminal = 14;
|
|
1776
|
-
const TitleBar = 15;
|
|
1777
|
-
const View = 16;
|
|
1778
|
-
|
|
1779
|
-
const menuEntrySeparator = {
|
|
1780
|
-
id: 'separator',
|
|
1781
|
-
label: '',
|
|
1782
|
-
flags: Separator,
|
|
1783
|
-
command: ''
|
|
1771
|
+
const getTitleBarButtonsVirtualDom = buttons => {
|
|
1772
|
+
const dom = [{
|
|
1773
|
+
type: Div,
|
|
1774
|
+
className: mergeClassNames(Viewlet, TitleBarButtons),
|
|
1775
|
+
childCount: buttons.length
|
|
1776
|
+
}, ...buttons.flatMap(createTitleBarButton)];
|
|
1777
|
+
return dom;
|
|
1784
1778
|
};
|
|
1785
1779
|
|
|
1786
|
-
const
|
|
1787
|
-
const getMenuEntries$d = () => {
|
|
1780
|
+
const getTitleBarIconVirtualDom = iconSrc => {
|
|
1788
1781
|
return [{
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
command: /* TODO */-1
|
|
1793
|
-
}, {
|
|
1794
|
-
id: 'redo',
|
|
1795
|
-
label: redo(),
|
|
1796
|
-
flags: Disabled,
|
|
1797
|
-
command: /* TODO */-1
|
|
1798
|
-
}, menuEntrySeparator, {
|
|
1799
|
-
id: 'cut',
|
|
1800
|
-
label: cut(),
|
|
1801
|
-
flags: None,
|
|
1802
|
-
command: /* Editor.cut */'Editor.cut'
|
|
1803
|
-
}, {
|
|
1804
|
-
id: 'copy',
|
|
1805
|
-
label: copy(),
|
|
1806
|
-
flags: None,
|
|
1807
|
-
command: /* Editor.copy */'Editor.copy'
|
|
1808
|
-
}, {
|
|
1809
|
-
id: 'paste',
|
|
1810
|
-
label: paste(),
|
|
1811
|
-
flags: None,
|
|
1812
|
-
command: /* Editor.paste */'Editor.paste'
|
|
1813
|
-
}, menuEntrySeparator, {
|
|
1814
|
-
id: 'toggle-line-comment',
|
|
1815
|
-
label: toggleLineComment(),
|
|
1816
|
-
flags: None,
|
|
1817
|
-
command: /* Editor.toggleLineComment */'Editor.toggleLineComment'
|
|
1782
|
+
type: Div,
|
|
1783
|
+
className: mergeClassNames(Viewlet, TitleBarIcon),
|
|
1784
|
+
childCount: 1
|
|
1818
1785
|
}, {
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1786
|
+
type: Img,
|
|
1787
|
+
className: TitleBarIconIcon,
|
|
1788
|
+
src: iconSrc,
|
|
1789
|
+
alt: '',
|
|
1790
|
+
childCount: 0
|
|
1823
1791
|
}];
|
|
1824
1792
|
};
|
|
1825
1793
|
|
|
1826
|
-
const
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1794
|
+
const HandleClick = 'handleClick';
|
|
1795
|
+
const HandleClickMinimize = 'handleClickMinimize';
|
|
1796
|
+
const HandleClickToggleClose = 'handleClickToggleClose';
|
|
1797
|
+
const HandleClickToggleMaximize = 'handleClickToggleMaximize';
|
|
1798
|
+
const HandleFocusIn = 'handleFocusIn';
|
|
1799
|
+
const HandleFocusOut = 'handleFocusOut';
|
|
1800
|
+
const HandlePointerOut = 'handlePointerOut';
|
|
1801
|
+
const HandlePointerOver = 'handlePointerOver';
|
|
1802
|
+
const HandleMenuClick = 'handleMenuClick';
|
|
1803
|
+
const HandleMenuMouseOver = 'handleMenuMouseOver';
|
|
1831
1804
|
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1805
|
+
const getItemVirtualDom = item => {
|
|
1806
|
+
// @ts-ignore
|
|
1807
|
+
const {
|
|
1808
|
+
keyboardShortCut,
|
|
1809
|
+
label,
|
|
1810
|
+
isOpen,
|
|
1811
|
+
isFocused
|
|
1812
|
+
} = item;
|
|
1813
|
+
const dom = [];
|
|
1814
|
+
dom.push({
|
|
1815
|
+
type: Div,
|
|
1816
|
+
className: TitleBarTopLevelEntry,
|
|
1817
|
+
ariaHasPopup: true,
|
|
1818
|
+
ariaExpanded: isOpen,
|
|
1819
|
+
role: MenuItem,
|
|
1820
|
+
childCount: 1,
|
|
1821
|
+
ariaKeyShortcuts: keyboardShortCut
|
|
1822
|
+
});
|
|
1823
|
+
if (isOpen) {
|
|
1824
|
+
// @ts-ignore
|
|
1825
|
+
dom[0].ariaOwns = 'Menu-0';
|
|
1826
|
+
}
|
|
1827
|
+
if (isFocused) {
|
|
1828
|
+
dom[0].className += ' ' + TitleBarEntryActive;
|
|
1829
|
+
// @ts-ignore
|
|
1830
|
+
dom[0].id = 'TitleBarEntryActive';
|
|
1831
|
+
dom.push({
|
|
1832
|
+
type: Div,
|
|
1833
|
+
className: TitleBarTopLevelEntryLabel,
|
|
1834
|
+
childCount: 1
|
|
1835
|
+
});
|
|
1836
|
+
}
|
|
1837
|
+
dom.push(text(label));
|
|
1838
|
+
return dom;
|
|
1850
1839
|
};
|
|
1851
|
-
const
|
|
1852
|
-
|
|
1840
|
+
const getTitleBarMenuBarItemsVirtualDom = visibleItems => {
|
|
1841
|
+
const dom = visibleItems.flatMap(getItemVirtualDom);
|
|
1842
|
+
return dom;
|
|
1853
1843
|
};
|
|
1854
|
-
|
|
1855
|
-
|
|
1844
|
+
|
|
1845
|
+
const activeId = 'TitleBarEntryActive';
|
|
1846
|
+
const getTitleBarMenuBarVirtualDom = (visibleItems, focusedIndex) => {
|
|
1847
|
+
return [{
|
|
1848
|
+
type: Div,
|
|
1849
|
+
className: mergeClassNames(Viewlet, TitleBarMenuBar$1),
|
|
1850
|
+
role: MenuBar,
|
|
1851
|
+
tabIndex: 0,
|
|
1852
|
+
childCount: visibleItems.length,
|
|
1853
|
+
onMouseDown: HandleClick,
|
|
1854
|
+
onFocusOut: HandleFocusOut,
|
|
1855
|
+
onFocusIn: HandleFocusIn,
|
|
1856
|
+
onPointerOver: HandlePointerOver,
|
|
1857
|
+
onPointerOut: HandlePointerOut,
|
|
1858
|
+
ariaActivedescendant: focusedIndex === -1 ? '' : activeId
|
|
1859
|
+
}, ...getTitleBarMenuBarItemsVirtualDom(visibleItems)];
|
|
1856
1860
|
};
|
|
1857
|
-
|
|
1858
|
-
|
|
1861
|
+
|
|
1862
|
+
const getTitleVirtualDom = title => {
|
|
1863
|
+
return [text(title)];
|
|
1859
1864
|
};
|
|
1860
|
-
|
|
1861
|
-
|
|
1865
|
+
|
|
1866
|
+
const maximize = async () => {
|
|
1867
|
+
await invoke('ElectronWindow.unmaximize');
|
|
1862
1868
|
};
|
|
1863
|
-
const
|
|
1864
|
-
|
|
1869
|
+
const minimize = async () => {
|
|
1870
|
+
await invoke('ElectronWindow.minimize');
|
|
1865
1871
|
};
|
|
1866
|
-
const
|
|
1867
|
-
|
|
1872
|
+
const close = async () => {
|
|
1873
|
+
await invoke('ElectronWindow.close');
|
|
1868
1874
|
};
|
|
1869
1875
|
|
|
1870
|
-
const
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
const id$8 = File;
|
|
1874
|
-
const getMenuEntries$c = platform => {
|
|
1875
|
-
const entries = [{
|
|
1876
|
-
id: 'newFile',
|
|
1877
|
-
label: newFile(),
|
|
1878
|
-
flags: None,
|
|
1879
|
-
command: -1
|
|
1880
|
-
}, {
|
|
1881
|
-
id: 'newWindow',
|
|
1882
|
-
label: newWindow(),
|
|
1883
|
-
flags: None,
|
|
1884
|
-
command: /* Window.openNew */'Window.openNew'
|
|
1885
|
-
}, menuEntrySeparator, {
|
|
1886
|
-
id: 'openFile',
|
|
1887
|
-
label: openFile(),
|
|
1888
|
-
flags: None,
|
|
1889
|
-
command: 'Dialog.openFile'
|
|
1890
|
-
}, {
|
|
1891
|
-
id: 'openFolder',
|
|
1892
|
-
label: openFolder(),
|
|
1893
|
-
flags: RestoreFocus,
|
|
1894
|
-
command: 'Dialog.openFolder'
|
|
1895
|
-
}, {
|
|
1896
|
-
id: OpenRecent,
|
|
1897
|
-
label: openRecent(),
|
|
1898
|
-
flags: SubMenu,
|
|
1899
|
-
command: ''
|
|
1900
|
-
}, menuEntrySeparator, {
|
|
1901
|
-
id: 'save',
|
|
1902
|
-
label: save(),
|
|
1903
|
-
flags: None,
|
|
1904
|
-
command: 'Main.save'
|
|
1905
|
-
}, {
|
|
1906
|
-
id: 'saveAll',
|
|
1907
|
-
label: saveAll(),
|
|
1908
|
-
flags: None,
|
|
1909
|
-
command: 'Main.saveAll'
|
|
1910
|
-
}];
|
|
1911
|
-
if (platform === Electron) {
|
|
1912
|
-
entries.push(menuEntrySeparator, {
|
|
1913
|
-
id: 'exit',
|
|
1914
|
-
label: exit(),
|
|
1915
|
-
flags: Ignore,
|
|
1916
|
-
command: 'Chrome.exit'
|
|
1917
|
-
});
|
|
1918
|
-
}
|
|
1919
|
-
return entries;
|
|
1876
|
+
const handleClickClose = async state => {
|
|
1877
|
+
await close();
|
|
1878
|
+
return state;
|
|
1920
1879
|
};
|
|
1921
1880
|
|
|
1922
|
-
const
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
id: id$8
|
|
1881
|
+
const handleClickMinimize = async state => {
|
|
1882
|
+
await minimize();
|
|
1883
|
+
return state;
|
|
1926
1884
|
};
|
|
1927
1885
|
|
|
1928
|
-
const
|
|
1929
|
-
const
|
|
1930
|
-
|
|
1886
|
+
const handleClickToggleMaximize = async state => {
|
|
1887
|
+
const fn = maximize;
|
|
1888
|
+
await fn();
|
|
1889
|
+
return state;
|
|
1931
1890
|
};
|
|
1932
1891
|
|
|
1933
|
-
const
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1892
|
+
const handleClick$1 = (state, className) => {
|
|
1893
|
+
if (className.includes('Minimize')) {
|
|
1894
|
+
return handleClickMinimize(state);
|
|
1895
|
+
}
|
|
1896
|
+
if (className.includes('Maximize') || className.includes('Restore')) {
|
|
1897
|
+
return handleClickToggleMaximize(state);
|
|
1898
|
+
}
|
|
1899
|
+
if (className.includes('Close')) {
|
|
1900
|
+
return handleClickClose(state);
|
|
1901
|
+
}
|
|
1902
|
+
return state;
|
|
1937
1903
|
};
|
|
1938
1904
|
|
|
1939
|
-
const
|
|
1940
|
-
return
|
|
1941
|
-
};
|
|
1942
|
-
const openProcessExplorer = () => {
|
|
1943
|
-
return i18nString(OpenProcessExplorer);
|
|
1944
|
-
};
|
|
1945
|
-
const checkForUpdates = () => {
|
|
1946
|
-
return i18nString(CheckForUpdates);
|
|
1947
|
-
};
|
|
1948
|
-
const about = () => {
|
|
1949
|
-
return i18nString(About);
|
|
1905
|
+
const handleContextMenu = state => {
|
|
1906
|
+
return state;
|
|
1950
1907
|
};
|
|
1951
1908
|
|
|
1952
|
-
const
|
|
1953
|
-
|
|
1954
|
-
|
|
1909
|
+
const getTitleBarIndexFromPosition = (titleBarEntries, x, y) => {
|
|
1910
|
+
let currentX = 0;
|
|
1911
|
+
for (let i = 0; i < titleBarEntries.length; i++) {
|
|
1912
|
+
const entry = titleBarEntries[i];
|
|
1913
|
+
const entryWidth = entry.width;
|
|
1914
|
+
if (x >= currentX && x < currentX + entryWidth) {
|
|
1915
|
+
return i;
|
|
1916
|
+
}
|
|
1917
|
+
currentX += entryWidth;
|
|
1955
1918
|
}
|
|
1956
|
-
return
|
|
1919
|
+
return -1;
|
|
1957
1920
|
};
|
|
1958
1921
|
|
|
1959
|
-
const
|
|
1960
|
-
|
|
1961
|
-
const
|
|
1962
|
-
|
|
1963
|
-
if (platform !== Web) {
|
|
1964
|
-
entries.push({
|
|
1965
|
-
id: 'toggleDeveloperTools',
|
|
1966
|
-
label: toggleDeveloperTools(),
|
|
1967
|
-
flags: None,
|
|
1968
|
-
command: 'Developer.toggleDeveloperTools'
|
|
1969
|
-
}, {
|
|
1970
|
-
id: 'openProcessExplorer',
|
|
1971
|
-
label: openProcessExplorer(),
|
|
1972
|
-
flags: RestoreFocus,
|
|
1973
|
-
command: 'Developer.openProcessExplorer'
|
|
1974
|
-
});
|
|
1975
|
-
}
|
|
1976
|
-
if (autoUpdateSupported) {
|
|
1977
|
-
entries.push(menuEntrySeparator, {
|
|
1978
|
-
id: 'checkForUpdates',
|
|
1979
|
-
label: checkForUpdates(),
|
|
1980
|
-
flags: RestoreFocus,
|
|
1981
|
-
command: 'AutoUpdater.checkForUpdates'
|
|
1982
|
-
});
|
|
1983
|
-
}
|
|
1984
|
-
if (entries.length > 0) {
|
|
1985
|
-
entries.push(menuEntrySeparator);
|
|
1922
|
+
const getTotalWidth = entries => {
|
|
1923
|
+
let total = 0;
|
|
1924
|
+
for (const entry of entries) {
|
|
1925
|
+
total += entry.width;
|
|
1986
1926
|
}
|
|
1987
|
-
|
|
1988
|
-
id: 'about',
|
|
1989
|
-
label: about(),
|
|
1990
|
-
flags: RestoreFocus,
|
|
1991
|
-
command: 'About.showAbout'
|
|
1992
|
-
});
|
|
1993
|
-
return entries;
|
|
1927
|
+
return total;
|
|
1994
1928
|
};
|
|
1995
1929
|
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
1930
|
+
// TODO lazyload menuEntries and use Command.execute (maybe)
|
|
1931
|
+
const CONTEXT_MENU_ITEM_HEIGHT = 26;
|
|
1932
|
+
const CONTEXT_MENU_SEPARATOR_HEIGHT = 11;
|
|
1933
|
+
const CONTEXT_MENU_PADDING = 8;
|
|
1934
|
+
const getMenuHeight = items => {
|
|
1935
|
+
let height = CONTEXT_MENU_PADDING;
|
|
1936
|
+
for (const item of items) {
|
|
1937
|
+
switch (item.flags) {
|
|
1938
|
+
case Separator$1:
|
|
1939
|
+
height += CONTEXT_MENU_SEPARATOR_HEIGHT;
|
|
1940
|
+
break;
|
|
1941
|
+
default:
|
|
1942
|
+
height += CONTEXT_MENU_ITEM_HEIGHT;
|
|
1943
|
+
break;
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
return height;
|
|
2000
1947
|
};
|
|
2001
1948
|
|
|
2002
|
-
|
|
2003
|
-
|
|
1949
|
+
// TODO lazyload menuEntries and use Command.execute (maybe)
|
|
1950
|
+
const MENU_WIDTH = 150;
|
|
1951
|
+
const CONTEXT_MENU_WIDTH = 250;
|
|
1952
|
+
const getMenuWidth = () => {
|
|
1953
|
+
return CONTEXT_MENU_WIDTH;
|
|
2004
1954
|
};
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
1955
|
+
|
|
1956
|
+
// TODO difference between focusing with mouse or keyboard
|
|
1957
|
+
// with mouse -> open submenu
|
|
1958
|
+
// with keyboard -> don't open submenu, only focus
|
|
1959
|
+
|
|
1960
|
+
const getIndexToFocusNextStartingAt = (items, startIndex) => {
|
|
1961
|
+
for (let i = startIndex; i < startIndex + items.length; i++) {
|
|
1962
|
+
const index = i % items.length;
|
|
1963
|
+
const item = items[index];
|
|
1964
|
+
if (canBeFocused(item)) {
|
|
1965
|
+
return index;
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
return -1;
|
|
2011
1969
|
};
|
|
2012
|
-
const
|
|
2013
|
-
|
|
1970
|
+
const getIndexToFocusFirst = items => {
|
|
1971
|
+
return getIndexToFocusNextStartingAt(items, 0);
|
|
2014
1972
|
};
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
return invoke(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
|
|
1973
|
+
const getIndexToFocusLast = items => {
|
|
1974
|
+
return getIndexToFocusPreviousStartingAt(items, items.length - 1);
|
|
2018
1975
|
};
|
|
2019
1976
|
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
1977
|
+
// TODO this code seems a bit too complicated, maybe it can be simplified
|
|
1978
|
+
const getIndexToFocusPreviousStartingAt = (items, startIndex) => {
|
|
1979
|
+
for (let i = startIndex; i > startIndex - items.length; i--) {
|
|
1980
|
+
const index = (i + items.length) % items.length;
|
|
1981
|
+
const item = items[index];
|
|
1982
|
+
if (canBeFocused(item)) {
|
|
1983
|
+
return index;
|
|
1984
|
+
}
|
|
2023
1985
|
}
|
|
2024
|
-
return
|
|
1986
|
+
return -1;
|
|
2025
1987
|
};
|
|
2026
|
-
|
|
2027
|
-
const
|
|
2028
|
-
|
|
2029
|
-
const label = getTitle(folder);
|
|
2030
|
-
return {
|
|
2031
|
-
label,
|
|
2032
|
-
flags: None,
|
|
2033
|
-
command: 'Workspace.setPath',
|
|
2034
|
-
args: [folder]
|
|
2035
|
-
};
|
|
1988
|
+
const getIndexToFocusPrevious = menu => {
|
|
1989
|
+
const startIndex = menu.focusedIndex === -1 ? menu.items.length - 1 : menu.focusedIndex - 1;
|
|
1990
|
+
return getIndexToFocusPreviousStartingAt(menu.items, startIndex);
|
|
2036
1991
|
};
|
|
2037
|
-
const
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
1992
|
+
const canBeFocused = item => {
|
|
1993
|
+
switch (item.flags) {
|
|
1994
|
+
case Separator$1:
|
|
1995
|
+
case Disabled:
|
|
1996
|
+
return false;
|
|
1997
|
+
default:
|
|
1998
|
+
return true;
|
|
2044
1999
|
}
|
|
2045
|
-
items.push({
|
|
2046
|
-
id: 'more',
|
|
2047
|
-
label: moreDot(),
|
|
2048
|
-
flags: None,
|
|
2049
|
-
command: 'QuickPick.showRecent'
|
|
2050
|
-
}, menuEntrySeparator, {
|
|
2051
|
-
id: 'clearRecentlyOpened',
|
|
2052
|
-
label: clearRecentlyOpened(),
|
|
2053
|
-
flags: None,
|
|
2054
|
-
command: 'RecentlyOpened.clearRecentlyOpened'
|
|
2055
|
-
});
|
|
2056
|
-
return items;
|
|
2057
2000
|
};
|
|
2058
|
-
|
|
2059
|
-
const
|
|
2060
|
-
|
|
2061
|
-
getMenuEntries: getMenuEntries$9,
|
|
2062
|
-
id: id$5
|
|
2001
|
+
const getIndexToFocusNext = menu => {
|
|
2002
|
+
const startIndex = menu.focusedIndex + 1;
|
|
2003
|
+
return getIndexToFocusNextStartingAt(menu.items, startIndex);
|
|
2063
2004
|
};
|
|
2064
2005
|
|
|
2065
|
-
|
|
2066
|
-
const getMenuEntries$8 = () => {
|
|
2067
|
-
return [];
|
|
2068
|
-
};
|
|
2006
|
+
// TODO handle printable letter and focus item that starts with that letter
|
|
2069
2007
|
|
|
2070
|
-
|
|
2071
|
-
__proto__: null,
|
|
2072
|
-
getMenuEntries: getMenuEntries$8,
|
|
2073
|
-
id: id$4
|
|
2074
|
-
};
|
|
2008
|
+
// TODO pageup / pagedown keys
|
|
2075
2009
|
|
|
2076
|
-
|
|
2077
|
-
const getMenuEntries$7 = () => {
|
|
2078
|
-
return [{
|
|
2079
|
-
id: 'selectAll',
|
|
2080
|
-
label: selectAll(),
|
|
2081
|
-
flags: None,
|
|
2082
|
-
command: 'Editor.selectAll'
|
|
2083
|
-
}, {
|
|
2084
|
-
id: 'copyLineUp',
|
|
2085
|
-
label: copyLineUp(),
|
|
2086
|
-
flags: None,
|
|
2087
|
-
command: 'Editor.copyLineUp'
|
|
2088
|
-
}, {
|
|
2089
|
-
id: 'copyLineDown',
|
|
2090
|
-
label: copyLineDown(),
|
|
2091
|
-
flags: None,
|
|
2092
|
-
command: 'Editor.copyLineDown'
|
|
2093
|
-
}, {
|
|
2094
|
-
id: 'moveLineUp',
|
|
2095
|
-
label: moveLineUp(),
|
|
2096
|
-
flags: Disabled,
|
|
2097
|
-
command: 'Editor.moveLineUp'
|
|
2098
|
-
}, {
|
|
2099
|
-
id: 'moveLineDown',
|
|
2100
|
-
label: moveLineDown(),
|
|
2101
|
-
flags: Disabled,
|
|
2102
|
-
command: 'Editor.moveLineDown'
|
|
2103
|
-
}];
|
|
2104
|
-
};
|
|
2010
|
+
// TODO more tests
|
|
2105
2011
|
|
|
2106
|
-
const
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2012
|
+
const menus = [MenuEntriesEdit, MenuEntriesFile, MenuEntriesGo, MenuEntriesHelp, MenuEntriesRun, MenuEntriesSelection, MenuEntriesTerminal, MenuEntriesTitleBar, MenuEntriesView, MenuEntriesOpenRecent];
|
|
2013
|
+
const getMenus = () => {
|
|
2014
|
+
return menus;
|
|
2015
|
+
};
|
|
2016
|
+
const getModule = id => {
|
|
2017
|
+
for (const module of menus) {
|
|
2018
|
+
if (module.id === id) {
|
|
2019
|
+
return module;
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2022
|
+
return undefined;
|
|
2023
|
+
};
|
|
2024
|
+
const getMenuEntries = async (id, ...args) => {
|
|
2025
|
+
try {
|
|
2026
|
+
const module = getModule(id);
|
|
2027
|
+
// @ts-ignore
|
|
2028
|
+
const inject = module.inject || [];
|
|
2029
|
+
// @ts-ignore
|
|
2030
|
+
return module.getMenuEntries(...args);
|
|
2031
|
+
} catch (error) {
|
|
2032
|
+
throw new VError(error, `Failed to load menu entries for id ${id}`);
|
|
2033
|
+
}
|
|
2110
2034
|
};
|
|
2111
2035
|
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
};
|
|
2118
|
-
|
|
2119
|
-
|
|
2036
|
+
const openMenuAtIndex = async (state, index, shouldBeFocused) => {
|
|
2037
|
+
const {
|
|
2038
|
+
titleBarEntries,
|
|
2039
|
+
titleBarHeight,
|
|
2040
|
+
x
|
|
2041
|
+
} = state;
|
|
2042
|
+
// TODO race conditions
|
|
2043
|
+
// TODO send renderer process
|
|
2044
|
+
// 1. open menu, items to show
|
|
2045
|
+
// 2. focus menu
|
|
2046
|
+
const titleBarEntry = titleBarEntries[index];
|
|
2047
|
+
const {
|
|
2048
|
+
id
|
|
2049
|
+
} = titleBarEntry;
|
|
2050
|
+
const items = await getMenuEntries(id);
|
|
2051
|
+
const relevantEntries = titleBarEntries.slice(0, index);
|
|
2052
|
+
const totalWidths = getTotalWidth(relevantEntries);
|
|
2053
|
+
const offset = totalWidths;
|
|
2054
|
+
// TODO race condition: another menu might already be open at this point
|
|
2055
|
+
|
|
2056
|
+
const menuX = x + offset;
|
|
2057
|
+
const menuY = titleBarHeight;
|
|
2058
|
+
const width = getMenuWidth();
|
|
2059
|
+
const height = getMenuHeight(items);
|
|
2060
|
+
const menuFocusedIndex = shouldBeFocused ? getIndexToFocusNextStartingAt(items, 0) : -1;
|
|
2061
|
+
const menu = {
|
|
2062
|
+
id,
|
|
2063
|
+
items,
|
|
2064
|
+
focusedIndex: menuFocusedIndex,
|
|
2065
|
+
level: 0,
|
|
2066
|
+
x: menuX,
|
|
2067
|
+
y: menuY,
|
|
2068
|
+
width,
|
|
2069
|
+
height
|
|
2070
|
+
};
|
|
2071
|
+
const menus = [menu];
|
|
2072
|
+
return {
|
|
2073
|
+
...state,
|
|
2074
|
+
isMenuOpen: true,
|
|
2075
|
+
focusedIndex: index,
|
|
2076
|
+
menus
|
|
2077
|
+
};
|
|
2120
2078
|
};
|
|
2121
2079
|
|
|
2122
|
-
const
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2080
|
+
const focusIndex = async (state, index) => {
|
|
2081
|
+
object(state);
|
|
2082
|
+
number(index);
|
|
2083
|
+
const {
|
|
2084
|
+
isMenuOpen,
|
|
2085
|
+
focusedIndex
|
|
2086
|
+
} = state;
|
|
2087
|
+
if (index === focusedIndex) {
|
|
2088
|
+
return state;
|
|
2089
|
+
}
|
|
2090
|
+
if (isMenuOpen) {
|
|
2091
|
+
return openMenuAtIndex(state, index, /* focus */false);
|
|
2092
|
+
}
|
|
2093
|
+
return {
|
|
2094
|
+
...state,
|
|
2095
|
+
focusedIndex: index
|
|
2096
|
+
};
|
|
2131
2097
|
};
|
|
2132
2098
|
|
|
2133
|
-
const
|
|
2134
|
-
|
|
2135
|
-
getMenuEntries: getMenuEntries$6,
|
|
2136
|
-
id: id$2
|
|
2099
|
+
const handleMouseOutMenuClosed = state => {
|
|
2100
|
+
return focusIndex(state, -1);
|
|
2137
2101
|
};
|
|
2138
2102
|
|
|
2139
|
-
const
|
|
2140
|
-
return
|
|
2141
|
-
};
|
|
2142
|
-
const edit = () => {
|
|
2143
|
-
return i18nString(Edit$1);
|
|
2144
|
-
};
|
|
2145
|
-
const selection = () => {
|
|
2146
|
-
return i18nString(Selection$1);
|
|
2147
|
-
};
|
|
2148
|
-
const view = () => {
|
|
2149
|
-
return i18nString(View$1);
|
|
2150
|
-
};
|
|
2151
|
-
const go = () => {
|
|
2152
|
-
return i18nString(Go$1);
|
|
2153
|
-
};
|
|
2154
|
-
const run = () => {
|
|
2155
|
-
return i18nString(Run$1);
|
|
2156
|
-
};
|
|
2157
|
-
const terminal = () => {
|
|
2158
|
-
return i18nString(Terminal$1);
|
|
2159
|
-
};
|
|
2160
|
-
const help = () => {
|
|
2161
|
-
return i18nString(Help$1);
|
|
2103
|
+
const handleMouseOutMenuOpen = state => {
|
|
2104
|
+
return state;
|
|
2162
2105
|
};
|
|
2163
2106
|
|
|
2164
|
-
const
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
}
|
|
2174
|
-
|
|
2175
|
-
label: selection(),
|
|
2176
|
-
flags: SubMenu
|
|
2177
|
-
}, {
|
|
2178
|
-
id: View,
|
|
2179
|
-
label: view(),
|
|
2180
|
-
flags: SubMenu
|
|
2181
|
-
}, {
|
|
2182
|
-
id: Go,
|
|
2183
|
-
label: go(),
|
|
2184
|
-
flags: SubMenu
|
|
2185
|
-
}, {
|
|
2186
|
-
id: Run,
|
|
2187
|
-
label: run(),
|
|
2188
|
-
keyboardShortCut: 'Alt+r',
|
|
2189
|
-
flags: SubMenu
|
|
2190
|
-
}, {
|
|
2191
|
-
id: Terminal,
|
|
2192
|
-
label: terminal(),
|
|
2193
|
-
keyboardShortCut: 'Alt+t',
|
|
2194
|
-
flags: SubMenu
|
|
2195
|
-
}, {
|
|
2196
|
-
id: Help,
|
|
2197
|
-
label: help(),
|
|
2198
|
-
keyboardShortCut: 'Alt+h',
|
|
2199
|
-
flags: SubMenu
|
|
2200
|
-
}];
|
|
2107
|
+
const ifElse = (menuOpenFunction, menuClosedFunction) => {
|
|
2108
|
+
const ifElseFunction = (state, ...args) => {
|
|
2109
|
+
const {
|
|
2110
|
+
isMenuOpen
|
|
2111
|
+
} = state;
|
|
2112
|
+
if (isMenuOpen) {
|
|
2113
|
+
return menuOpenFunction(state, ...args);
|
|
2114
|
+
}
|
|
2115
|
+
return menuClosedFunction(state, ...args);
|
|
2116
|
+
};
|
|
2117
|
+
return ifElseFunction;
|
|
2201
2118
|
};
|
|
2202
2119
|
|
|
2203
|
-
const
|
|
2204
|
-
return [{
|
|
2205
|
-
id: File,
|
|
2206
|
-
label: file(),
|
|
2207
|
-
flags: None
|
|
2208
|
-
}, {
|
|
2209
|
-
id: Edit,
|
|
2210
|
-
label: edit(),
|
|
2211
|
-
flags: None
|
|
2212
|
-
}, {
|
|
2213
|
-
id: Selection,
|
|
2214
|
-
label: selection(),
|
|
2215
|
-
flags: None
|
|
2216
|
-
}, {
|
|
2217
|
-
id: View,
|
|
2218
|
-
label: view(),
|
|
2219
|
-
flags: None
|
|
2220
|
-
}, {
|
|
2221
|
-
id: Go,
|
|
2222
|
-
label: go(),
|
|
2223
|
-
flags: None
|
|
2224
|
-
}, {
|
|
2225
|
-
id: Help,
|
|
2226
|
-
label: help(),
|
|
2227
|
-
flags: None
|
|
2228
|
-
}];
|
|
2229
|
-
};
|
|
2120
|
+
const handleMouseOut = ifElse(handleMouseOutMenuOpen, handleMouseOutMenuClosed);
|
|
2230
2121
|
|
|
2231
|
-
const
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
default:
|
|
2236
|
-
return getMenuEntries$5;
|
|
2122
|
+
const handlePointerOut = (state, clientX, clientY) => {
|
|
2123
|
+
const index = getTitleBarIndexFromPosition(state.titleBarEntries, clientX - state.x);
|
|
2124
|
+
if (index === -1) {
|
|
2125
|
+
return state;
|
|
2237
2126
|
}
|
|
2238
|
-
|
|
2239
|
-
const id$1 = TitleBar;
|
|
2240
|
-
const getMenuEntries$3 = async platform => {
|
|
2241
|
-
const fn = getFn(platform);
|
|
2242
|
-
return fn();
|
|
2243
|
-
};
|
|
2244
|
-
|
|
2245
|
-
const MenuEntriesTitleBar = {
|
|
2246
|
-
__proto__: null,
|
|
2247
|
-
getMenuEntries: getMenuEntries$3,
|
|
2248
|
-
id: id$1
|
|
2127
|
+
return handleMouseOut(state, index);
|
|
2249
2128
|
};
|
|
2250
2129
|
|
|
2251
|
-
const
|
|
2252
|
-
|
|
2253
|
-
return [];
|
|
2130
|
+
const handleMouseOverMenuClosed = (state, index) => {
|
|
2131
|
+
return focusIndex(state, index);
|
|
2254
2132
|
};
|
|
2255
2133
|
|
|
2256
|
-
const
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2134
|
+
const handleMouseOverMenuOpen = async (state, index) => {
|
|
2135
|
+
if (index === -1) {
|
|
2136
|
+
return state;
|
|
2137
|
+
}
|
|
2138
|
+
return focusIndex(state, index);
|
|
2260
2139
|
};
|
|
2261
2140
|
|
|
2262
|
-
const
|
|
2141
|
+
const handleMouseOver = ifElse(handleMouseOverMenuOpen, handleMouseOverMenuClosed);
|
|
2263
2142
|
|
|
2264
|
-
const
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
const menu = menus$1.find(item => item.id === id);
|
|
2269
|
-
if (!menu) {
|
|
2270
|
-
return [];
|
|
2143
|
+
const handlePointerOver = (state, clientX, clientY) => {
|
|
2144
|
+
const index = getTitleBarIndexFromPosition(state.titleBarEntries, clientX - state.x);
|
|
2145
|
+
if (index === -1) {
|
|
2146
|
+
return state;
|
|
2271
2147
|
}
|
|
2272
|
-
return
|
|
2148
|
+
return handleMouseOver(state, index);
|
|
2273
2149
|
};
|
|
2274
2150
|
|
|
2275
|
-
const
|
|
2276
|
-
return {
|
|
2277
|
-
type,
|
|
2278
|
-
className: `MaskIcon MaskIcon${icon}`,
|
|
2279
|
-
role: None$1,
|
|
2280
|
-
childCount: 0
|
|
2281
|
-
};
|
|
2151
|
+
const getFontString = (fontWeight, fontSize, fontFamily) => {
|
|
2152
|
+
return `${fontWeight} ${fontSize}px ${fontFamily}`;
|
|
2282
2153
|
};
|
|
2283
2154
|
|
|
2284
|
-
const
|
|
2285
|
-
const
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
const dom = [{
|
|
2292
|
-
type: Button,
|
|
2293
|
-
className: `TitleBarButton TitleBarButton${id}`,
|
|
2294
|
-
ariaLabel: label,
|
|
2295
|
-
childCount: 1,
|
|
2296
|
-
onClick
|
|
2297
|
-
}, getIconVirtualDom(icon, I)];
|
|
2298
|
-
return dom;
|
|
2155
|
+
const createTextMeasureContext = () => {
|
|
2156
|
+
const canvas = new OffscreenCanvas(0, 0);
|
|
2157
|
+
const ctx = canvas.getContext('2d');
|
|
2158
|
+
if (!ctx) {
|
|
2159
|
+
throw new Error('Failed to get canvas context 2d');
|
|
2160
|
+
}
|
|
2161
|
+
return ctx;
|
|
2299
2162
|
};
|
|
2300
2163
|
|
|
2301
|
-
const
|
|
2302
|
-
|
|
2303
|
-
type: Div,
|
|
2304
|
-
className: 'Viewlet TitleBarButtons',
|
|
2305
|
-
childCount: buttons.length
|
|
2306
|
-
}, ...buttons.flatMap(createTitleBarButton)];
|
|
2307
|
-
return dom;
|
|
2164
|
+
const state = {
|
|
2165
|
+
ctx: undefined
|
|
2308
2166
|
};
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
}, {
|
|
2316
|
-
type: Img,
|
|
2317
|
-
className: 'TitleBarIconIcon',
|
|
2318
|
-
src: iconSrc,
|
|
2319
|
-
alt: '',
|
|
2320
|
-
childCount: 0
|
|
2321
|
-
}];
|
|
2167
|
+
const getOrCreate = createCtx => {
|
|
2168
|
+
if (state.ctx) {
|
|
2169
|
+
return state.ctx;
|
|
2170
|
+
}
|
|
2171
|
+
state.ctx = createCtx();
|
|
2172
|
+
return state.ctx;
|
|
2322
2173
|
};
|
|
2323
2174
|
|
|
2324
|
-
const
|
|
2325
|
-
|
|
2175
|
+
const getContext = () => {
|
|
2176
|
+
const ctx = getOrCreate(createTextMeasureContext);
|
|
2177
|
+
return ctx;
|
|
2326
2178
|
};
|
|
2327
2179
|
|
|
2328
|
-
const
|
|
2329
|
-
|
|
2330
|
-
return state;
|
|
2180
|
+
const px = value => {
|
|
2181
|
+
return `${value}px`;
|
|
2331
2182
|
};
|
|
2332
2183
|
|
|
2333
|
-
const
|
|
2334
|
-
|
|
2335
|
-
|
|
2184
|
+
const getLetterSpacingString = letterSpacing => {
|
|
2185
|
+
return px(letterSpacing);
|
|
2186
|
+
};
|
|
2187
|
+
const measureTextWidth = (text, fontWeight, fontSize, fontFamily, letterSpacing, isMonoSpaceFont, charWidth) => {
|
|
2188
|
+
string(text);
|
|
2189
|
+
number(fontWeight);
|
|
2190
|
+
number(fontSize);
|
|
2191
|
+
string(fontFamily);
|
|
2192
|
+
boolean(isMonoSpaceFont);
|
|
2193
|
+
number(charWidth);
|
|
2194
|
+
if (typeof letterSpacing !== 'number') {
|
|
2195
|
+
throw new TypeError('letterSpacing must be of type number');
|
|
2196
|
+
}
|
|
2197
|
+
const letterSpacingString = getLetterSpacingString(letterSpacing);
|
|
2198
|
+
const fontString = getFontString(fontWeight, fontSize, fontFamily);
|
|
2199
|
+
const ctx = getContext();
|
|
2200
|
+
ctx.letterSpacing = letterSpacingString;
|
|
2201
|
+
ctx.font = fontString;
|
|
2202
|
+
const metrics = ctx.measureText(text);
|
|
2203
|
+
const {
|
|
2204
|
+
width
|
|
2205
|
+
} = metrics;
|
|
2206
|
+
return width;
|
|
2336
2207
|
};
|
|
2337
2208
|
|
|
2338
|
-
const
|
|
2339
|
-
|
|
2340
|
-
|
|
2209
|
+
const measureTitleBarEntryWidth = (label, fontWeight, fontSize, fontFamily, letterSpacing) => {
|
|
2210
|
+
const isMonospaceFont = false;
|
|
2211
|
+
const charWidth = 0;
|
|
2212
|
+
return measureTextWidth(label, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth);
|
|
2341
2213
|
};
|
|
2342
2214
|
|
|
2343
|
-
const
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2215
|
+
const addWidths = (entries, labelPadding, fontWeight, fontSize, fontFamily, letterSpacing) => {
|
|
2216
|
+
const withWidths = [];
|
|
2217
|
+
for (const entry of entries) {
|
|
2218
|
+
const textWidth = measureTitleBarEntryWidth(entry.label, fontWeight, fontSize, fontFamily, letterSpacing);
|
|
2219
|
+
const width = textWidth + labelPadding * 2;
|
|
2220
|
+
withWidths.push({
|
|
2221
|
+
...entry,
|
|
2222
|
+
width
|
|
2223
|
+
});
|
|
2352
2224
|
}
|
|
2353
|
-
return
|
|
2225
|
+
return withWidths;
|
|
2354
2226
|
};
|
|
2355
2227
|
|
|
2356
|
-
const
|
|
2357
|
-
|
|
2228
|
+
const loadContent = async (state, titleBarEntries) => {
|
|
2229
|
+
const {
|
|
2230
|
+
labelFontFamily,
|
|
2231
|
+
labelFontSize,
|
|
2232
|
+
labelFontWeight,
|
|
2233
|
+
labelLetterSpacing,
|
|
2234
|
+
labelPadding
|
|
2235
|
+
} = state;
|
|
2236
|
+
const withWidths = addWidths(titleBarEntries, labelPadding, labelFontWeight, labelFontSize, labelFontFamily, labelLetterSpacing);
|
|
2237
|
+
return {
|
|
2238
|
+
...state,
|
|
2239
|
+
titleBarEntries: withWidths
|
|
2240
|
+
};
|
|
2358
2241
|
};
|
|
2359
2242
|
|
|
2360
|
-
const
|
|
2361
|
-
let currentX = 0;
|
|
2362
|
-
for (let i = 0; i < titleBarEntries.length; i++) {
|
|
2363
|
-
const entry = titleBarEntries[i];
|
|
2364
|
-
const entryWidth = entry.width;
|
|
2365
|
-
if (x >= currentX && x < currentX + entryWidth) {
|
|
2366
|
-
return i;
|
|
2367
|
-
}
|
|
2368
|
-
currentX += entryWidth;
|
|
2369
|
-
}
|
|
2370
|
-
return -1;
|
|
2371
|
-
};
|
|
2243
|
+
const Ellipsis = 'Ellipsis';
|
|
2372
2244
|
|
|
2373
|
-
const
|
|
2245
|
+
const getVisibleTitleBarEntries = (entries, width, focusedIndex, isMenuOpen) => {
|
|
2246
|
+
array(entries);
|
|
2247
|
+
number(width);
|
|
2374
2248
|
let total = 0;
|
|
2375
|
-
|
|
2249
|
+
const visible = [];
|
|
2250
|
+
for (let i = 0; i < entries.length; i++) {
|
|
2251
|
+
const entry = entries[i];
|
|
2376
2252
|
total += entry.width;
|
|
2253
|
+
if (total >= width) {
|
|
2254
|
+
break;
|
|
2255
|
+
}
|
|
2256
|
+
const isOpen = i === focusedIndex && isMenuOpen;
|
|
2257
|
+
const isFocused = i === focusedIndex;
|
|
2258
|
+
visible.push({
|
|
2259
|
+
...entry,
|
|
2260
|
+
isOpen,
|
|
2261
|
+
isFocused
|
|
2262
|
+
});
|
|
2377
2263
|
}
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
const
|
|
2383
|
-
const
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
let height = CONTEXT_MENU_PADDING;
|
|
2387
|
-
for (const item of items) {
|
|
2388
|
-
switch (item.flags) {
|
|
2389
|
-
case Separator:
|
|
2390
|
-
height += CONTEXT_MENU_SEPARATOR_HEIGHT;
|
|
2391
|
-
break;
|
|
2392
|
-
default:
|
|
2393
|
-
height += CONTEXT_MENU_ITEM_HEIGHT;
|
|
2394
|
-
break;
|
|
2264
|
+
const hasOverflow = visible.length < entries.length;
|
|
2265
|
+
if (hasOverflow) {
|
|
2266
|
+
const padding = 8;
|
|
2267
|
+
const moreIconWidth = 22;
|
|
2268
|
+
const totalPadding = padding * 2;
|
|
2269
|
+
const hasStillOverflow = total + moreIconWidth + totalPadding > width;
|
|
2270
|
+
if (hasStillOverflow) {
|
|
2271
|
+
visible.pop();
|
|
2395
2272
|
}
|
|
2273
|
+
visible.push({
|
|
2274
|
+
ariaLabel: moreDot(),
|
|
2275
|
+
icon: Ellipsis,
|
|
2276
|
+
label: '',
|
|
2277
|
+
width: moreIconWidth + totalPadding
|
|
2278
|
+
});
|
|
2396
2279
|
}
|
|
2397
|
-
return
|
|
2280
|
+
return visible;
|
|
2398
2281
|
};
|
|
2399
2282
|
|
|
2400
|
-
|
|
2401
|
-
const
|
|
2402
|
-
const
|
|
2403
|
-
|
|
2404
|
-
return CONTEXT_MENU_WIDTH;
|
|
2283
|
+
const renderEntries = (oldState, newState) => {
|
|
2284
|
+
const visibleEntries = getVisibleTitleBarEntries(newState.titleBarEntries, newState.width, newState.focusedIndex, newState.isMenuOpen);
|
|
2285
|
+
const dom = getTitleBarMenuBarVirtualDom(visibleEntries, newState.focusedIndex);
|
|
2286
|
+
return ['Viewlet.setDom2', newState.uid, dom];
|
|
2405
2287
|
};
|
|
2406
2288
|
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
const getIndexToFocusNextStartingAt = (items, startIndex) => {
|
|
2412
|
-
for (let i = startIndex; i < startIndex + items.length; i++) {
|
|
2413
|
-
const index = i % items.length;
|
|
2414
|
-
const item = items[index];
|
|
2415
|
-
if (canBeFocused(item)) {
|
|
2416
|
-
return index;
|
|
2417
|
-
}
|
|
2289
|
+
const renderFocusedIndex = (oldState, newState) => {
|
|
2290
|
+
if (newState.focusedIndex === -1) {
|
|
2291
|
+
return [];
|
|
2418
2292
|
}
|
|
2419
|
-
return
|
|
2293
|
+
return ['Viewlet.focusSelector', '.ViewletTitleBarMenuBar'];
|
|
2420
2294
|
};
|
|
2421
|
-
|
|
2422
|
-
|
|
2295
|
+
|
|
2296
|
+
const checkboxChecked = {
|
|
2297
|
+
type: Div,
|
|
2298
|
+
className: mergeClassNames(MenuItem$1, MenuItemCheckMark),
|
|
2299
|
+
role: MenuItemCheckBox,
|
|
2300
|
+
ariaChecked: true,
|
|
2301
|
+
tabIndex: -1,
|
|
2302
|
+
childCount: 2
|
|
2423
2303
|
};
|
|
2424
|
-
const
|
|
2425
|
-
|
|
2304
|
+
const checkMark = {
|
|
2305
|
+
type: Div,
|
|
2306
|
+
className: mergeClassNames(MenuItemCheckmarkIcon, MaskIconCheck)
|
|
2307
|
+
};
|
|
2308
|
+
const getMenuItemCheckedDom = menuItem => {
|
|
2309
|
+
const {
|
|
2310
|
+
label
|
|
2311
|
+
} = menuItem;
|
|
2312
|
+
return [checkboxChecked, checkMark, text(label)];
|
|
2426
2313
|
};
|
|
2427
2314
|
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
const item = items[index];
|
|
2433
|
-
if (canBeFocused(item)) {
|
|
2434
|
-
return index;
|
|
2435
|
-
}
|
|
2315
|
+
const getKeyBindingString = (key, altKey, ctrlKey, shiftKey, metaKey) => {
|
|
2316
|
+
let string = '';
|
|
2317
|
+
if (ctrlKey) {
|
|
2318
|
+
string += 'Ctrl+';
|
|
2436
2319
|
}
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
const getIndexToFocusPrevious = menu => {
|
|
2440
|
-
const startIndex = menu.focusedIndex === -1 ? menu.items.length - 1 : menu.focusedIndex - 1;
|
|
2441
|
-
return getIndexToFocusPreviousStartingAt(menu.items, startIndex);
|
|
2442
|
-
};
|
|
2443
|
-
const canBeFocused = item => {
|
|
2444
|
-
switch (item.flags) {
|
|
2445
|
-
case Separator:
|
|
2446
|
-
case Disabled:
|
|
2447
|
-
return false;
|
|
2448
|
-
default:
|
|
2449
|
-
return true;
|
|
2320
|
+
if (shiftKey) {
|
|
2321
|
+
string += 'Shift+';
|
|
2450
2322
|
}
|
|
2323
|
+
string += key.toUpperCase();
|
|
2324
|
+
return string;
|
|
2451
2325
|
};
|
|
2452
|
-
const getIndexToFocusNext = menu => {
|
|
2453
|
-
const startIndex = menu.focusedIndex + 1;
|
|
2454
|
-
return getIndexToFocusNextStartingAt(menu.items, startIndex);
|
|
2455
|
-
};
|
|
2456
|
-
|
|
2457
|
-
// TODO handle printable letter and focus item that starts with that letter
|
|
2458
|
-
|
|
2459
|
-
// TODO pageup / pagedown keys
|
|
2460
2326
|
|
|
2461
|
-
|
|
2327
|
+
const Unknown = 'Unknown';
|
|
2328
|
+
const Backspace = 'Backspace';
|
|
2329
|
+
const Tab = 'Tab';
|
|
2330
|
+
const Enter = 'Enter';
|
|
2331
|
+
const Escape = 'Escape';
|
|
2332
|
+
const Space = 'Space';
|
|
2333
|
+
const PageUp = 'PageUp';
|
|
2334
|
+
const PageDown = 'PageDown';
|
|
2335
|
+
const End = 'End';
|
|
2336
|
+
const Home = 'Home';
|
|
2337
|
+
const LeftArrow = 'LeftArrow';
|
|
2338
|
+
const UpArrow = 'UpArrow';
|
|
2339
|
+
const RightArrow = 'RightArrow';
|
|
2340
|
+
const DownArrow = 'DownArrow';
|
|
2341
|
+
const Insert = 'Insert';
|
|
2342
|
+
const Delete = 'Delete';
|
|
2343
|
+
const Digit0 = '0';
|
|
2344
|
+
const Digit1 = '1';
|
|
2345
|
+
const Digit2 = '2';
|
|
2346
|
+
const Digit3 = '3';
|
|
2347
|
+
const Digit4 = '4';
|
|
2348
|
+
const Digit5 = '5';
|
|
2349
|
+
const Digit6 = '6';
|
|
2350
|
+
const Digit7 = '7';
|
|
2351
|
+
const Digit8 = '8';
|
|
2352
|
+
const Digit9 = '9';
|
|
2353
|
+
const KeyA = 'a';
|
|
2354
|
+
const KeyB = 'b';
|
|
2355
|
+
const KeyC = 'c';
|
|
2356
|
+
const KeyD = 'd';
|
|
2357
|
+
const KeyE = 'e';
|
|
2358
|
+
const KeyF = 'f';
|
|
2359
|
+
const KeyG = 'g';
|
|
2360
|
+
const KeyH = 'h';
|
|
2361
|
+
const KeyI = 'i';
|
|
2362
|
+
const KeyJ = 'j';
|
|
2363
|
+
const KeyK = 'k';
|
|
2364
|
+
const KeyL = 'l';
|
|
2365
|
+
const KeyM = 'm';
|
|
2366
|
+
const KeyN = 'n';
|
|
2367
|
+
const KeyO = 'o';
|
|
2368
|
+
const KeyP = 'p';
|
|
2369
|
+
const KeyQ = 'q';
|
|
2370
|
+
const KeyR = 'r';
|
|
2371
|
+
const KeyS = 's';
|
|
2372
|
+
const KeyT = 't';
|
|
2373
|
+
const KeyU = 'u';
|
|
2374
|
+
const KeyV = 'v';
|
|
2375
|
+
const KeyW = 'w';
|
|
2376
|
+
const KeyX = 'x';
|
|
2377
|
+
const KeyY = 'y';
|
|
2378
|
+
const KeyZ = 'z';
|
|
2379
|
+
const F1 = 'F1';
|
|
2380
|
+
const F2 = 'F2';
|
|
2381
|
+
const F3 = 'F3';
|
|
2382
|
+
const F4 = 'F4';
|
|
2383
|
+
const F5 = 'F5';
|
|
2384
|
+
const F6 = 'F6';
|
|
2385
|
+
const Equal = '=';
|
|
2386
|
+
const Comma = ',';
|
|
2387
|
+
const Minus = 'Minus';
|
|
2388
|
+
const Backquote = 'Backquote';
|
|
2389
|
+
const Backslash = 'Backslash';
|
|
2390
|
+
const Star = '*';
|
|
2391
|
+
const Plus = '+';
|
|
2462
2392
|
|
|
2463
|
-
const
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
return
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2393
|
+
const getKeyCodeString = keyCode => {
|
|
2394
|
+
switch (keyCode) {
|
|
2395
|
+
case Backspace$1:
|
|
2396
|
+
return Backspace;
|
|
2397
|
+
case Tab$1:
|
|
2398
|
+
return Tab;
|
|
2399
|
+
case Escape$1:
|
|
2400
|
+
return Escape;
|
|
2401
|
+
case Enter$1:
|
|
2402
|
+
return Enter;
|
|
2403
|
+
case Space$1:
|
|
2404
|
+
return Space;
|
|
2405
|
+
case PageUp$1:
|
|
2406
|
+
return PageUp;
|
|
2407
|
+
case PageDown$1:
|
|
2408
|
+
return PageDown;
|
|
2409
|
+
case End$1:
|
|
2410
|
+
return End;
|
|
2411
|
+
case Home$1:
|
|
2412
|
+
return Home;
|
|
2413
|
+
case LeftArrow$1:
|
|
2414
|
+
return LeftArrow;
|
|
2415
|
+
case UpArrow$1:
|
|
2416
|
+
return UpArrow;
|
|
2417
|
+
case RightArrow$1:
|
|
2418
|
+
return RightArrow;
|
|
2419
|
+
case DownArrow$1:
|
|
2420
|
+
return DownArrow;
|
|
2421
|
+
case Insert$1:
|
|
2422
|
+
return Insert;
|
|
2423
|
+
case Delete$1:
|
|
2424
|
+
return Delete;
|
|
2425
|
+
case Digit0$1:
|
|
2426
|
+
return Digit0;
|
|
2427
|
+
case Digit1$1:
|
|
2428
|
+
return Digit1;
|
|
2429
|
+
case Digit2$1:
|
|
2430
|
+
return Digit2;
|
|
2431
|
+
case Digit3$1:
|
|
2432
|
+
return Digit3;
|
|
2433
|
+
case Digit4$1:
|
|
2434
|
+
return Digit4;
|
|
2435
|
+
case Digit5$1:
|
|
2436
|
+
return Digit5;
|
|
2437
|
+
case Digit6$1:
|
|
2438
|
+
return Digit6;
|
|
2439
|
+
case Digit7$1:
|
|
2440
|
+
return Digit7;
|
|
2441
|
+
case Digit8$1:
|
|
2442
|
+
return Digit8;
|
|
2443
|
+
case Digit9$1:
|
|
2444
|
+
return Digit9;
|
|
2445
|
+
case KeyA$1:
|
|
2446
|
+
return KeyA;
|
|
2447
|
+
case KeyB$1:
|
|
2448
|
+
return KeyB;
|
|
2449
|
+
case KeyC$1:
|
|
2450
|
+
return KeyC;
|
|
2451
|
+
case KeyD$1:
|
|
2452
|
+
return KeyD;
|
|
2453
|
+
case KeyE$1:
|
|
2454
|
+
return KeyE;
|
|
2455
|
+
case KeyF$1:
|
|
2456
|
+
return KeyF;
|
|
2457
|
+
case KeyG$1:
|
|
2458
|
+
return KeyG;
|
|
2459
|
+
case KeyH$1:
|
|
2460
|
+
return KeyH;
|
|
2461
|
+
case KeyI$1:
|
|
2462
|
+
return KeyI;
|
|
2463
|
+
case KeyJ$1:
|
|
2464
|
+
return KeyJ;
|
|
2465
|
+
case KeyK$1:
|
|
2466
|
+
return KeyK;
|
|
2467
|
+
case KeyL$1:
|
|
2468
|
+
return KeyL;
|
|
2469
|
+
case KeyM$1:
|
|
2470
|
+
return KeyM;
|
|
2471
|
+
case KeyN$1:
|
|
2472
|
+
return KeyN;
|
|
2473
|
+
case KeyO$1:
|
|
2474
|
+
return KeyO;
|
|
2475
|
+
case KeyP$1:
|
|
2476
|
+
return KeyP;
|
|
2477
|
+
case KeyQ$1:
|
|
2478
|
+
return KeyQ;
|
|
2479
|
+
case KeyR$1:
|
|
2480
|
+
return KeyR;
|
|
2481
|
+
case KeyS$1:
|
|
2482
|
+
return KeyS;
|
|
2483
|
+
case KeyT$1:
|
|
2484
|
+
return KeyT;
|
|
2485
|
+
case KeyU$1:
|
|
2486
|
+
return KeyU;
|
|
2487
|
+
case KeyV$1:
|
|
2488
|
+
return KeyV;
|
|
2489
|
+
case KeyW$1:
|
|
2490
|
+
return KeyW;
|
|
2491
|
+
case KeyX$1:
|
|
2492
|
+
return KeyX;
|
|
2493
|
+
case KeyY$1:
|
|
2494
|
+
return KeyY;
|
|
2495
|
+
case KeyZ$1:
|
|
2496
|
+
return KeyZ;
|
|
2497
|
+
case F1$1:
|
|
2498
|
+
return F1;
|
|
2499
|
+
case F2$1:
|
|
2500
|
+
return F2;
|
|
2501
|
+
case F3$1:
|
|
2502
|
+
return F3;
|
|
2503
|
+
case F4$1:
|
|
2504
|
+
return F4;
|
|
2505
|
+
case F5$1:
|
|
2506
|
+
return F5;
|
|
2507
|
+
case F6$1:
|
|
2508
|
+
return F6;
|
|
2509
|
+
case Backslash$1:
|
|
2510
|
+
return Backslash;
|
|
2511
|
+
case Equal$1:
|
|
2512
|
+
return Equal;
|
|
2513
|
+
case Comma$1:
|
|
2514
|
+
return Comma;
|
|
2515
|
+
case Backquote$1:
|
|
2516
|
+
return Backquote;
|
|
2517
|
+
case Plus$1:
|
|
2518
|
+
return Plus;
|
|
2519
|
+
case Star$1:
|
|
2520
|
+
return Star;
|
|
2521
|
+
case Minus$1:
|
|
2522
|
+
return Minus;
|
|
2523
|
+
default:
|
|
2524
|
+
return Unknown;
|
|
2484
2525
|
}
|
|
2485
2526
|
};
|
|
2486
2527
|
|
|
2487
|
-
const
|
|
2488
|
-
|
|
2489
|
-
titleBarEntries,
|
|
2490
|
-
titleBarHeight,
|
|
2491
|
-
x
|
|
2492
|
-
} = state;
|
|
2493
|
-
// TODO race conditions
|
|
2494
|
-
// TODO send renderer process
|
|
2495
|
-
// 1. open menu, items to show
|
|
2496
|
-
// 2. focus menu
|
|
2497
|
-
const titleBarEntry = titleBarEntries[index];
|
|
2498
|
-
const {
|
|
2499
|
-
id
|
|
2500
|
-
} = titleBarEntry;
|
|
2501
|
-
const items = await getMenuEntries(id);
|
|
2502
|
-
const relevantEntries = titleBarEntries.slice(0, index);
|
|
2503
|
-
const totalWidths = getTotalWidth(relevantEntries);
|
|
2504
|
-
const offset = totalWidths;
|
|
2505
|
-
// TODO race condition: another menu might already be open at this point
|
|
2528
|
+
const CtrlCmd = 1 << 11 >>> 0;
|
|
2529
|
+
const Shift = 1 << 10 >>> 0;
|
|
2506
2530
|
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
const
|
|
2510
|
-
const
|
|
2511
|
-
const
|
|
2512
|
-
const
|
|
2513
|
-
id,
|
|
2514
|
-
items,
|
|
2515
|
-
focusedIndex: menuFocusedIndex,
|
|
2516
|
-
level: 0,
|
|
2517
|
-
x: menuX,
|
|
2518
|
-
y: menuY,
|
|
2519
|
-
width,
|
|
2520
|
-
height
|
|
2521
|
-
};
|
|
2522
|
-
const menus = [menu];
|
|
2531
|
+
const parseKey = rawKey => {
|
|
2532
|
+
number(rawKey);
|
|
2533
|
+
const isCtrl = Boolean(rawKey & CtrlCmd);
|
|
2534
|
+
const isShift = Boolean(rawKey & Shift);
|
|
2535
|
+
const keyCode = rawKey & 0x00_00_00_ff;
|
|
2536
|
+
const key = getKeyCodeString(keyCode);
|
|
2523
2537
|
return {
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
menus
|
|
2538
|
+
key,
|
|
2539
|
+
isCtrl,
|
|
2540
|
+
isShift
|
|
2528
2541
|
};
|
|
2529
2542
|
};
|
|
2530
2543
|
|
|
2531
|
-
const
|
|
2532
|
-
object(state);
|
|
2533
|
-
number(index);
|
|
2544
|
+
const getMenuItemDefaultDom = menuItem => {
|
|
2534
2545
|
const {
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2546
|
+
label,
|
|
2547
|
+
isFocused,
|
|
2548
|
+
key
|
|
2549
|
+
} = menuItem;
|
|
2550
|
+
let className = MenuItem$1;
|
|
2551
|
+
if (isFocused) {
|
|
2552
|
+
className += ' ' + MenuItemFocused;
|
|
2540
2553
|
}
|
|
2541
|
-
|
|
2542
|
-
|
|
2554
|
+
const dom = [];
|
|
2555
|
+
dom.push({
|
|
2556
|
+
type: Div,
|
|
2557
|
+
className,
|
|
2558
|
+
role: MenuItem,
|
|
2559
|
+
tabIndex: -1,
|
|
2560
|
+
childCount: 1
|
|
2561
|
+
}, text(label));
|
|
2562
|
+
if (key) {
|
|
2563
|
+
dom[0].childCount++;
|
|
2564
|
+
const parsedKey = parseKey(key);
|
|
2565
|
+
const keyBindingsString = getKeyBindingString(parsedKey.key, false, parsedKey.isCtrl, parsedKey.isShift);
|
|
2566
|
+
dom.push({
|
|
2567
|
+
type: Span,
|
|
2568
|
+
className: MenuItemKeyBinding,
|
|
2569
|
+
childCount: 1
|
|
2570
|
+
}, text(keyBindingsString));
|
|
2543
2571
|
}
|
|
2544
|
-
return
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2572
|
+
return dom;
|
|
2573
|
+
};
|
|
2574
|
+
|
|
2575
|
+
const disabled = {
|
|
2576
|
+
type: Div,
|
|
2577
|
+
className: MenuItem$1,
|
|
2578
|
+
role: MenuItem,
|
|
2579
|
+
tabIndex: -1,
|
|
2580
|
+
disabled: true,
|
|
2581
|
+
childCount: 1
|
|
2582
|
+
};
|
|
2583
|
+
const getMenuItemDisabledDom = menuItem => {
|
|
2584
|
+
const {
|
|
2585
|
+
label
|
|
2586
|
+
} = menuItem;
|
|
2587
|
+
return [disabled, text(label)];
|
|
2548
2588
|
};
|
|
2549
2589
|
|
|
2550
|
-
const
|
|
2551
|
-
return
|
|
2590
|
+
const getMenuItemsNoopDom = () => {
|
|
2591
|
+
return [];
|
|
2552
2592
|
};
|
|
2553
2593
|
|
|
2554
|
-
const
|
|
2555
|
-
|
|
2594
|
+
const separator = {
|
|
2595
|
+
type: Div,
|
|
2596
|
+
className: MenuItemSeparator,
|
|
2597
|
+
role: Separator,
|
|
2598
|
+
childCount: 1
|
|
2556
2599
|
};
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
isMenuOpen
|
|
2562
|
-
} = state;
|
|
2563
|
-
if (isMenuOpen) {
|
|
2564
|
-
return menuOpenFunction(state, ...args);
|
|
2565
|
-
}
|
|
2566
|
-
return menuClosedFunction(state, ...args);
|
|
2567
|
-
};
|
|
2568
|
-
return ifElseFunction;
|
|
2600
|
+
const separatorLine = {
|
|
2601
|
+
type: Div,
|
|
2602
|
+
className: MenuItemSeparatorLine,
|
|
2603
|
+
childCount: 0
|
|
2569
2604
|
};
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
const handlePointerOut = (state, clientX, clientY) => {
|
|
2574
|
-
const index = getTitleBarIndexFromPosition(state.titleBarEntries, clientX - state.x);
|
|
2575
|
-
if (index === -1) {
|
|
2576
|
-
return state;
|
|
2577
|
-
}
|
|
2578
|
-
return handleMouseOut(state, index);
|
|
2605
|
+
const getMenuItemSeparatorDom = menuItem => {
|
|
2606
|
+
return [separator, separatorLine];
|
|
2579
2607
|
};
|
|
2580
2608
|
|
|
2581
|
-
const
|
|
2582
|
-
|
|
2609
|
+
const arrowRight = {
|
|
2610
|
+
type: Div,
|
|
2611
|
+
className: MenuItemSubMenuArrowRight,
|
|
2612
|
+
childCount: 0
|
|
2583
2613
|
};
|
|
2584
|
-
|
|
2585
|
-
const
|
|
2586
|
-
|
|
2587
|
-
|
|
2614
|
+
const getMenuItemSubMenuDom = menuItem => {
|
|
2615
|
+
const {
|
|
2616
|
+
label,
|
|
2617
|
+
isFocused,
|
|
2618
|
+
isExpanded,
|
|
2619
|
+
level
|
|
2620
|
+
} = menuItem;
|
|
2621
|
+
let className = MenuItem$1;
|
|
2622
|
+
className += ' ' + MenuItemSubMenu;
|
|
2623
|
+
if (isFocused) {
|
|
2624
|
+
className += ' ' + MenuItemFocused;
|
|
2588
2625
|
}
|
|
2589
|
-
return
|
|
2626
|
+
return [{
|
|
2627
|
+
type: Div,
|
|
2628
|
+
className,
|
|
2629
|
+
role: MenuItem,
|
|
2630
|
+
tabIndex: -1,
|
|
2631
|
+
ariaHasPopup: true,
|
|
2632
|
+
ariaExpanded: isExpanded,
|
|
2633
|
+
ariaOwns: isExpanded ? `Menu-${level + 1}` : undefined,
|
|
2634
|
+
childCount: 2
|
|
2635
|
+
}, text(label), arrowRight];
|
|
2590
2636
|
};
|
|
2591
2637
|
|
|
2592
|
-
const
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
return handleMouseOver(state, index);
|
|
2638
|
+
const checkboxUnchecked = {
|
|
2639
|
+
type: Div,
|
|
2640
|
+
className: MenuItem$1,
|
|
2641
|
+
role: MenuItemCheckBox,
|
|
2642
|
+
ariaChecked: false,
|
|
2643
|
+
tabIndex: -1,
|
|
2644
|
+
childCount: 1
|
|
2600
2645
|
};
|
|
2601
|
-
|
|
2602
|
-
const
|
|
2603
|
-
|
|
2646
|
+
const getMenuItemUncheckedDom = menuItem => {
|
|
2647
|
+
const {
|
|
2648
|
+
label
|
|
2649
|
+
} = menuItem;
|
|
2650
|
+
return [checkboxUnchecked, text(label)];
|
|
2604
2651
|
};
|
|
2605
2652
|
|
|
2606
|
-
const
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2653
|
+
const getMenuItemRenderer = flags => {
|
|
2654
|
+
switch (flags) {
|
|
2655
|
+
case None$1:
|
|
2656
|
+
case RestoreFocus:
|
|
2657
|
+
case Ignore:
|
|
2658
|
+
return getMenuItemDefaultDom;
|
|
2659
|
+
case Separator$1:
|
|
2660
|
+
return getMenuItemSeparatorDom;
|
|
2661
|
+
case Checked:
|
|
2662
|
+
return getMenuItemCheckedDom;
|
|
2663
|
+
case Unchecked:
|
|
2664
|
+
return getMenuItemUncheckedDom;
|
|
2665
|
+
case Disabled:
|
|
2666
|
+
return getMenuItemDisabledDom;
|
|
2667
|
+
case SubMenu:
|
|
2668
|
+
return getMenuItemSubMenuDom;
|
|
2669
|
+
default:
|
|
2670
|
+
return getMenuItemsNoopDom;
|
|
2612
2671
|
}
|
|
2613
|
-
state.ctx = createCtx();
|
|
2614
|
-
return state.ctx;
|
|
2615
2672
|
};
|
|
2616
2673
|
|
|
2617
|
-
const
|
|
2618
|
-
const
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
return ctx;
|
|
2624
|
-
};
|
|
2625
|
-
const getContext = () => {
|
|
2626
|
-
const ctx = getOrCreate(createCtx);
|
|
2627
|
-
return ctx;
|
|
2674
|
+
const getMenuItemVirtualDom = menuItem => {
|
|
2675
|
+
const {
|
|
2676
|
+
flags
|
|
2677
|
+
} = menuItem;
|
|
2678
|
+
const fn = getMenuItemRenderer(flags);
|
|
2679
|
+
return fn(menuItem);
|
|
2628
2680
|
};
|
|
2629
2681
|
|
|
2630
|
-
const
|
|
2631
|
-
|
|
2682
|
+
const getMenuVirtualDom = menuItems => {
|
|
2683
|
+
const dom = [{
|
|
2684
|
+
type: Div,
|
|
2685
|
+
className: Menu$1,
|
|
2686
|
+
role: Menu,
|
|
2687
|
+
tabIndex: -1,
|
|
2688
|
+
childCount: menuItems.length
|
|
2689
|
+
}, ...menuItems.flatMap(getMenuItemVirtualDom)];
|
|
2690
|
+
return dom;
|
|
2632
2691
|
};
|
|
2633
2692
|
|
|
2634
|
-
const
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
const
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2693
|
+
const getVisible = (items, focusedIndex, expanded, level) => {
|
|
2694
|
+
const visibleItems = [];
|
|
2695
|
+
for (let i = 0; i < items.length; i++) {
|
|
2696
|
+
const item = items[i];
|
|
2697
|
+
const {
|
|
2698
|
+
flags,
|
|
2699
|
+
label
|
|
2700
|
+
} = item;
|
|
2701
|
+
visibleItems.push({
|
|
2702
|
+
label,
|
|
2703
|
+
flags,
|
|
2704
|
+
isFocused: i === focusedIndex,
|
|
2705
|
+
isExpanded: i === focusedIndex && expanded,
|
|
2706
|
+
level,
|
|
2707
|
+
key: item.key
|
|
2708
|
+
});
|
|
2646
2709
|
}
|
|
2647
|
-
|
|
2648
|
-
const fontString = getFontString(fontWeight, fontSize, fontFamily);
|
|
2649
|
-
const ctx = getContext();
|
|
2650
|
-
// @ts-ignore
|
|
2651
|
-
ctx.letterSpacing = letterSpacingString;
|
|
2652
|
-
ctx.font = fontString;
|
|
2653
|
-
const metrics = ctx.measureText(text);
|
|
2654
|
-
const {
|
|
2655
|
-
width
|
|
2656
|
-
} = metrics;
|
|
2657
|
-
return width;
|
|
2710
|
+
return visibleItems;
|
|
2658
2711
|
};
|
|
2659
2712
|
|
|
2660
|
-
const
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2713
|
+
const SetMenus = 'setMenus';
|
|
2714
|
+
|
|
2715
|
+
const renderMenus = (oldState, newState) => {
|
|
2716
|
+
const oldMenus = oldState.menus;
|
|
2717
|
+
const newMenus = newState.menus;
|
|
2718
|
+
const oldLength = oldMenus.length;
|
|
2719
|
+
const newLength = newMenus.length;
|
|
2720
|
+
const commonLength = Math.min(oldLength, newLength);
|
|
2721
|
+
const changes = [];
|
|
2722
|
+
for (let i = 0; i < commonLength; i++) {
|
|
2723
|
+
const oldMenu = oldMenus[i];
|
|
2724
|
+
const newMenu = newMenus[i];
|
|
2725
|
+
if (oldMenu !== newMenu) {
|
|
2726
|
+
const visible = getVisible(newMenu.items, newMenu.focusedIndex, newMenu.expanded, newMenu.level);
|
|
2727
|
+
const dom = getMenuVirtualDom(visible).slice(1);
|
|
2728
|
+
changes.push([/* method */'updateMenu', newMenu, /* newLength */newLength, dom]);
|
|
2729
|
+
}
|
|
2730
|
+
}
|
|
2731
|
+
const difference = newLength - oldLength;
|
|
2732
|
+
if (difference > 0) {
|
|
2733
|
+
const newMenu = newMenus.at(-1);
|
|
2734
|
+
const visible = getVisible(newMenu.items, newMenu.focusedIndex, newMenu.expanded, newMenu.level);
|
|
2735
|
+
const dom = getMenuVirtualDom(visible).slice(1);
|
|
2736
|
+
changes.push(['addMenu', newMenu, dom]);
|
|
2737
|
+
} else if (difference < 0) {
|
|
2738
|
+
changes.push(['closeMenus', newLength]);
|
|
2739
|
+
}
|
|
2740
|
+
return ['Viewlet.send', newState.uid, /* method */SetMenus, /* changes */changes, newState.uid];
|
|
2664
2741
|
};
|
|
2665
2742
|
|
|
2666
|
-
const
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2743
|
+
const getRenderer = diffType => {
|
|
2744
|
+
switch (diffType) {
|
|
2745
|
+
case RenderEntries:
|
|
2746
|
+
return renderEntries;
|
|
2747
|
+
case RenderFocusedIndex:
|
|
2748
|
+
return renderFocusedIndex;
|
|
2749
|
+
case RenderMenus:
|
|
2750
|
+
return renderMenus;
|
|
2751
|
+
default:
|
|
2752
|
+
throw new Error('unknown renderer');
|
|
2675
2753
|
}
|
|
2676
|
-
return withWidths;
|
|
2677
2754
|
};
|
|
2678
2755
|
|
|
2679
|
-
const
|
|
2680
|
-
const
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
return
|
|
2689
|
-
...state,
|
|
2690
|
-
titleBarEntries: withWidths
|
|
2691
|
-
};
|
|
2756
|
+
const applyRender = (oldState, newState, diffResult) => {
|
|
2757
|
+
const commands = [];
|
|
2758
|
+
for (const item of diffResult) {
|
|
2759
|
+
const fn = getRenderer(item);
|
|
2760
|
+
const result = fn(oldState, newState);
|
|
2761
|
+
if (result.length > 0) {
|
|
2762
|
+
commands.push(result);
|
|
2763
|
+
}
|
|
2764
|
+
}
|
|
2765
|
+
return commands;
|
|
2692
2766
|
};
|
|
2693
2767
|
|
|
2694
2768
|
const render2 = async (uid, diffResult) => {
|
|
@@ -2696,6 +2770,7 @@ const render2 = async (uid, diffResult) => {
|
|
|
2696
2770
|
oldState,
|
|
2697
2771
|
newState
|
|
2698
2772
|
} = get(uid);
|
|
2773
|
+
set(uid, newState, newState);
|
|
2699
2774
|
const commands = applyRender(oldState, newState, diffResult);
|
|
2700
2775
|
return commands;
|
|
2701
2776
|
};
|
|
@@ -2861,11 +2936,19 @@ const handleClickAt = async (state, button, x, y) => {
|
|
|
2861
2936
|
return handleClick(state, button, index);
|
|
2862
2937
|
};
|
|
2863
2938
|
|
|
2939
|
+
const setFocus = async focusKey => {
|
|
2940
|
+
await invoke('Focus.setFocus', focusKey);
|
|
2941
|
+
};
|
|
2942
|
+
|
|
2864
2943
|
// TODO remove this file and merge with whenExpressions
|
|
2865
2944
|
const TitleBarMenuBar = FocusTitleBarMenuBar;
|
|
2866
2945
|
|
|
2867
2946
|
const handleFocus = async state => {
|
|
2868
|
-
await
|
|
2947
|
+
await setFocus(TitleBarMenuBar);
|
|
2948
|
+
return state;
|
|
2949
|
+
};
|
|
2950
|
+
|
|
2951
|
+
const handleFocusOut = async state => {
|
|
2869
2952
|
return state;
|
|
2870
2953
|
};
|
|
2871
2954
|
|
|
@@ -3138,7 +3221,7 @@ const handleMenuClick = (state, level, index) => {
|
|
|
3138
3221
|
const menu = menus[level];
|
|
3139
3222
|
const item = menu.items[index];
|
|
3140
3223
|
switch (item.flags) {
|
|
3141
|
-
case None:
|
|
3224
|
+
case None$1:
|
|
3142
3225
|
return selectIndexNone(state, item);
|
|
3143
3226
|
case SubMenu:
|
|
3144
3227
|
return selectIndexSubMenu(state, menu, index);
|
|
@@ -3242,25 +3325,28 @@ const wrapCommand = fn => {
|
|
|
3242
3325
|
newState
|
|
3243
3326
|
} = get(uid);
|
|
3244
3327
|
const newerState = await fn(newState, ...args);
|
|
3245
|
-
|
|
3328
|
+
if (newState === newerState) {
|
|
3329
|
+
return;
|
|
3330
|
+
}
|
|
3331
|
+
const latest = get(uid);
|
|
3332
|
+
set(uid, latest.oldState, newerState);
|
|
3246
3333
|
};
|
|
3247
3334
|
return wrapped;
|
|
3248
3335
|
};
|
|
3249
3336
|
|
|
3250
3337
|
const commandMap = {
|
|
3251
3338
|
'TitleBar.getButtonsVirtualDom': getTitleBarButtonsVirtualDom,
|
|
3252
|
-
'TitleBar.handleContextMenu': handleContextMenu,
|
|
3253
3339
|
'TitleBar.getIconVirtualDom': getTitleBarIconVirtualDom,
|
|
3254
3340
|
'TitleBar.getMenuEntries': getMenuEntries$1,
|
|
3255
3341
|
'TitleBar.getMenuIds': getMenuIds,
|
|
3256
3342
|
'TitleBar.getTitleVirtualDom': getTitleVirtualDom,
|
|
3257
3343
|
'TitleBar.handleButtonsClick': handleClick$1,
|
|
3344
|
+
'TitleBar.handleContextMenu': handleContextMenu,
|
|
3258
3345
|
'TitleBar.renderEventListeners': renderEventListeners,
|
|
3259
3346
|
'TitleBarMenuBar.closeMenu': closeMenu,
|
|
3260
3347
|
'TitleBarMenuBar.create': create,
|
|
3261
|
-
'TitleBarMenuBar.focus': wrapCommand(focus),
|
|
3262
3348
|
'TitleBarMenuBar.diff2': diff2,
|
|
3263
|
-
'TitleBarMenuBar.
|
|
3349
|
+
'TitleBarMenuBar.focus': wrapCommand(focus),
|
|
3264
3350
|
'TitleBarMenuBar.focusFirst': wrapCommand(focusFirst),
|
|
3265
3351
|
'TitleBarMenuBar.focusIndex': wrapCommand(focusLast),
|
|
3266
3352
|
'TitleBarMenuBar.focusLast': wrapCommand(focusIndex),
|
|
@@ -3271,16 +3357,16 @@ const commandMap = {
|
|
|
3271
3357
|
'TitleBarMenuBar.getMenus': getMenus,
|
|
3272
3358
|
'TitleBarMenuBar.getVirtualDom': getTitleBarMenuBarVirtualDom,
|
|
3273
3359
|
'TitleBarMenuBar.handleClick': wrapCommand(handleClick),
|
|
3360
|
+
'TitleBarMenuBar.getTitleBarButtons': getTitleBarButtons,
|
|
3361
|
+
'TitleBarMenuBar.handleClickAt': wrapCommand(handleClickAt),
|
|
3274
3362
|
'TitleBarMenuBar.handleFocus': wrapCommand(handleFocus),
|
|
3363
|
+
'TitleBarMenuBar.handleFocusOut': wrapCommand(handleFocusOut),
|
|
3275
3364
|
'TitleBarMenuBar.handleKeyArrowDown': wrapCommand(handleKeyArrowDown),
|
|
3276
3365
|
'TitleBarMenuBar.handleKeyArrowLeft': wrapCommand(handleKeyArrowLeft),
|
|
3277
3366
|
'TitleBarMenuBar.handleKeyArrowRight': wrapCommand(handleKeyArrowRight),
|
|
3278
3367
|
'TitleBarMenuBar.handleKeyArrowUp': wrapCommand(handleKeyArrowUp),
|
|
3279
|
-
'TitleBarMenuBar.handleClickAt': wrapCommand(handleClickAt),
|
|
3280
|
-
'TitleBarMenuBar.handlePointerOver': wrapCommand(handlePointerOver),
|
|
3281
3368
|
'TitleBarMenuBar.handleKeyEnd': wrapCommand(handleKeyEnd),
|
|
3282
3369
|
'TitleBarMenuBar.handleKeyEnter': wrapCommand(handleKeyEnter),
|
|
3283
|
-
'TitleBarMenuBar.handlePointerOut': wrapCommand(handlePointerOut),
|
|
3284
3370
|
'TitleBarMenuBar.handleKeyEscape': wrapCommand(handleKeyEscape),
|
|
3285
3371
|
'TitleBarMenuBar.handleKeyHome': wrapCommand(handleKeyHome),
|
|
3286
3372
|
'TitleBarMenuBar.handleKeySpace': wrapCommand(handleKeySpace),
|
|
@@ -3288,14 +3374,14 @@ const commandMap = {
|
|
|
3288
3374
|
'TitleBarMenuBar.handleMenuMouseOver': wrapCommand(handleMenuMouseOver),
|
|
3289
3375
|
'TitleBarMenuBar.handleMouseOut': wrapCommand(handleMouseOut),
|
|
3290
3376
|
'TitleBarMenuBar.handleMouseOver': wrapCommand(handleMouseOver),
|
|
3377
|
+
'TitleBarMenuBar.handlePointerOut': wrapCommand(handlePointerOut),
|
|
3378
|
+
'TitleBarMenuBar.handlePointerOver': wrapCommand(handlePointerOver),
|
|
3291
3379
|
'TitleBarMenuBar.loadContent': wrapCommand(loadContent),
|
|
3380
|
+
'TitleBarMenuBar.render2': render2,
|
|
3292
3381
|
'TitleBarMenuBar.saveState': saveState,
|
|
3293
3382
|
'TitleBarMenuBar.terminate': terminate,
|
|
3294
3383
|
'TitleBarMenuBar.toggleIndex': wrapCommand(toggleIndex),
|
|
3295
|
-
'TitleBarMenuBar.toggleMenu': wrapCommand(toggleMenu)
|
|
3296
|
-
// deprecated
|
|
3297
|
-
'TitleBarMenuBar.diff': diff,
|
|
3298
|
-
'TitleBarMenuBar.render': doRender
|
|
3384
|
+
'TitleBarMenuBar.toggleMenu': wrapCommand(toggleMenu)
|
|
3299
3385
|
};
|
|
3300
3386
|
|
|
3301
3387
|
const listen = async () => {
|