custom-electron-titlebar 3.2.6 → 3.2.10

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.
Files changed (239) hide show
  1. package/.github/FUNDING.yml +1 -0
  2. package/README.md +15 -24
  3. package/_config.yml +1 -0
  4. package/{lib → build}/browser/browser.d.ts +0 -0
  5. package/{lib → build}/browser/browser.js +0 -0
  6. package/{lib → build}/browser/browser.js.map +0 -0
  7. package/{lib → build}/browser/event.d.ts +0 -0
  8. package/{lib → build}/browser/event.js +2 -1
  9. package/{lib → build}/browser/event.js.map +1 -1
  10. package/{lib → build}/browser/iframe.d.ts +0 -0
  11. package/{lib → build}/browser/iframe.js +0 -0
  12. package/{lib → build}/browser/iframe.js.map +0 -0
  13. package/{lib → build}/browser/keyboardEvent.d.ts +0 -0
  14. package/{lib → build}/browser/keyboardEvent.js +0 -0
  15. package/{lib → build}/browser/keyboardEvent.js.map +0 -0
  16. package/{lib → build}/browser/mouseEvent.d.ts +0 -0
  17. package/{lib → build}/browser/mouseEvent.js +0 -0
  18. package/{lib → build}/browser/mouseEvent.js.map +0 -0
  19. package/{lib → build}/common/arrays.d.ts +0 -0
  20. package/{lib → build}/common/arrays.js +0 -0
  21. package/{lib → build}/common/arrays.js.map +0 -0
  22. package/{lib → build}/common/async.d.ts +0 -0
  23. package/{lib → build}/common/async.js +0 -0
  24. package/{lib → build}/common/async.js.map +0 -0
  25. package/{lib → build}/common/charCode.d.ts +0 -0
  26. package/{lib → build}/common/charCode.js +0 -0
  27. package/{lib → build}/common/charCode.js.map +0 -0
  28. package/{lib → build}/common/color.d.ts +0 -0
  29. package/{lib → build}/common/color.js +0 -0
  30. package/{lib → build}/common/color.js.map +0 -0
  31. package/{lib → build}/common/dom.d.ts +0 -0
  32. package/{lib → build}/common/dom.js +16 -14
  33. package/build/common/dom.js.map +1 -0
  34. package/{lib → build}/common/event.d.ts +0 -0
  35. package/{lib → build}/common/event.js +1 -1
  36. package/build/common/event.js.map +1 -0
  37. package/{lib → build}/common/iterator.d.ts +0 -0
  38. package/{lib → build}/common/iterator.js +0 -0
  39. package/{lib → build}/common/iterator.js.map +0 -0
  40. package/{lib → build}/common/keyCodes.d.ts +0 -0
  41. package/{lib → build}/common/keyCodes.js +0 -0
  42. package/{lib → build}/common/keyCodes.js.map +0 -0
  43. package/{lib → build}/common/lifecycle.d.ts +0 -0
  44. package/{lib → build}/common/lifecycle.js +0 -0
  45. package/{lib → build}/common/lifecycle.js.map +0 -0
  46. package/{lib → build}/common/linkedList.d.ts +0 -0
  47. package/{lib → build}/common/linkedList.js +0 -0
  48. package/{lib → build}/common/linkedList.js.map +0 -0
  49. package/{lib → build}/common/platform.d.ts +0 -0
  50. package/{lib → build}/common/platform.js +0 -0
  51. package/{lib → build}/common/platform.js.map +0 -0
  52. package/{lib → build}/index.d.ts +0 -0
  53. package/{lib → build}/index.js +0 -0
  54. package/{lib → build}/index.js.map +0 -0
  55. package/{lib → build}/menu/menu.d.ts +0 -0
  56. package/{lib → build}/menu/menu.js +38 -38
  57. package/build/menu/menu.js.map +1 -0
  58. package/{lib → build}/menu/menuitem.d.ts +10 -2
  59. package/{lib → build}/menu/menuitem.js +70 -34
  60. package/build/menu/menuitem.js.map +1 -0
  61. package/{lib → build}/menubar.d.ts +0 -0
  62. package/{lib → build}/menubar.js +29 -30
  63. package/build/menubar.js.map +1 -0
  64. package/{lib → build}/themebar.d.ts +0 -0
  65. package/{lib → build}/themebar.js +2 -2
  66. package/build/themebar.js.map +1 -0
  67. package/{lib → build}/titlebar.d.ts +0 -0
  68. package/{lib → build}/titlebar.js +61 -58
  69. package/build/titlebar.js.map +1 -0
  70. package/package.json +13 -7
  71. package/lib/common/dom.js.map +0 -1
  72. package/lib/common/enableNativeMenuCommands.d.ts +0 -1
  73. package/lib/common/enableNativeMenuCommands.js +0 -32
  74. package/lib/common/enableNativeMenuCommands.js.map +0 -1
  75. package/lib/common/event.js.map +0 -1
  76. package/lib/main.d.ts +0 -1
  77. package/lib/main.js +0 -14
  78. package/lib/main.js.map +0 -1
  79. package/lib/menu/menu.js.map +0 -1
  80. package/lib/menu/menuitem.js.map +0 -1
  81. package/lib/menubar.js.map +0 -1
  82. package/lib/themebar.js.map +0 -1
  83. package/lib/titlebar.js.map +0 -1
  84. package/lib/vs/base/browser/browser.js +0 -150
  85. package/lib/vs/base/browser/canIUse.js +0 -58
  86. package/lib/vs/base/browser/codicons.js +0 -37
  87. package/lib/vs/base/browser/contextmenu.js +0 -9
  88. package/lib/vs/base/browser/dnd.js +0 -113
  89. package/lib/vs/base/browser/dom.js +0 -1417
  90. package/lib/vs/base/browser/event.js +0 -36
  91. package/lib/vs/base/browser/fastDomNode.js +0 -265
  92. package/lib/vs/base/browser/formattedTextRenderer.js +0 -248
  93. package/lib/vs/base/browser/globalMouseMoveMonitor.js +0 -137
  94. package/lib/vs/base/browser/history.js +0 -9
  95. package/lib/vs/base/browser/iframe.js +0 -126
  96. package/lib/vs/base/browser/keyboardEvent.js +0 -599
  97. package/lib/vs/base/browser/mouseEvent.js +0 -155
  98. package/lib/vs/base/browser/touch.js +0 -315
  99. package/lib/vs/base/browser/ui/actionbar/actionViewItems.js +0 -397
  100. package/lib/vs/base/browser/ui/actionbar/actionbar.js +0 -583
  101. package/lib/vs/base/browser/ui/checkbox/checkbox.js +0 -251
  102. package/lib/vs/base/browser/ui/codicons/codiconLabel.js +0 -31
  103. package/lib/vs/base/browser/ui/codicons/codiconStyles.js +0 -47
  104. package/lib/vs/base/browser/ui/contextview/contextview.js +0 -367
  105. package/lib/vs/base/browser/ui/dropdown/dropdown.js +0 -256
  106. package/lib/vs/base/browser/ui/dropdown/dropdownActionViewItem.js +0 -120
  107. package/lib/vs/base/browser/ui/keybindingLabel/keybindingLabel.js +0 -118
  108. package/lib/vs/base/browser/ui/list/list.js +0 -54
  109. package/lib/vs/base/browser/ui/list/listPaging.js +0 -322
  110. package/lib/vs/base/browser/ui/list/listView.js +0 -1388
  111. package/lib/vs/base/browser/ui/list/listWidget.js +0 -1709
  112. package/lib/vs/base/browser/ui/list/rangeMap.js +0 -223
  113. package/lib/vs/base/browser/ui/list/rowCache.js +0 -113
  114. package/lib/vs/base/browser/ui/list/splice.js +0 -23
  115. package/lib/vs/base/browser/ui/menu/menu.js +0 -1371
  116. package/lib/vs/base/browser/ui/menu/menubar.js +0 -1139
  117. package/lib/vs/base/browser/ui/scrollbar/abstractScrollbar.js +0 -278
  118. package/lib/vs/base/browser/ui/scrollbar/horizontalScrollbar.js +0 -115
  119. package/lib/vs/base/browser/ui/scrollbar/scrollableElement.js +0 -646
  120. package/lib/vs/base/browser/ui/scrollbar/scrollableElementOptions.js +0 -9
  121. package/lib/vs/base/browser/ui/scrollbar/scrollbarArrow.js +0 -106
  122. package/lib/vs/base/browser/ui/scrollbar/scrollbarState.js +0 -184
  123. package/lib/vs/base/browser/ui/scrollbar/scrollbarVisibilityController.js +0 -116
  124. package/lib/vs/base/browser/ui/scrollbar/verticalScrollbar.js +0 -114
  125. package/lib/vs/base/browser/ui/selectBox/selectBox.js +0 -85
  126. package/lib/vs/base/browser/ui/selectBox/selectBoxCustom.js +0 -985
  127. package/lib/vs/base/browser/ui/selectBox/selectBoxNative.js +0 -188
  128. package/lib/vs/base/browser/ui/toolbar/toolbar.js +0 -206
  129. package/lib/vs/base/browser/ui/widget.js +0 -69
  130. package/lib/vs/base/common/actions.js +0 -224
  131. package/lib/vs/base/common/amd.js +0 -31
  132. package/lib/vs/base/common/arrays.js +0 -641
  133. package/lib/vs/base/common/assert.js +0 -21
  134. package/lib/vs/base/common/async.js +0 -966
  135. package/lib/vs/base/common/buffer.js +0 -250
  136. package/lib/vs/base/common/cache.js +0 -40
  137. package/lib/vs/base/common/cancellation.js +0 -146
  138. package/lib/vs/base/common/charCode.js +0 -9
  139. package/lib/vs/base/common/codicon.js +0 -136
  140. package/lib/vs/base/common/codicons.js +0 -1378
  141. package/lib/vs/base/common/collections.js +0 -133
  142. package/lib/vs/base/common/color.js +0 -716
  143. package/lib/vs/base/common/comparers.js +0 -280
  144. package/lib/vs/base/common/console.js +0 -142
  145. package/lib/vs/base/common/date.js +0 -113
  146. package/lib/vs/base/common/decorators.js +0 -169
  147. package/lib/vs/base/common/errorMessage.js +0 -93
  148. package/lib/vs/base/common/errors.js +0 -213
  149. package/lib/vs/base/common/errorsWithActions.js +0 -28
  150. package/lib/vs/base/common/event.js +0 -873
  151. package/lib/vs/base/common/extpath.js +0 -401
  152. package/lib/vs/base/common/filters.js +0 -948
  153. package/lib/vs/base/common/functional.js +0 -28
  154. package/lib/vs/base/common/fuzzyScorer.js +0 -811
  155. package/lib/vs/base/common/glob.js +0 -696
  156. package/lib/vs/base/common/hash.js +0 -359
  157. package/lib/vs/base/common/history.js +0 -116
  158. package/lib/vs/base/common/htmlContent.js +0 -162
  159. package/lib/vs/base/common/idGenerator.js +0 -25
  160. package/lib/vs/base/common/iterator.js +0 -118
  161. package/lib/vs/base/common/json.js +0 -1624
  162. package/lib/vs/base/common/jsonEdit.js +0 -272
  163. package/lib/vs/base/common/jsonErrorMessages.js +0 -69
  164. package/lib/vs/base/common/jsonFormatter.js +0 -316
  165. package/lib/vs/base/common/jsonSchema.js +0 -9
  166. package/lib/vs/base/common/keyCodes.js +0 -591
  167. package/lib/vs/base/common/keybindingLabels.js +0 -231
  168. package/lib/vs/base/common/keybindingParser.js +0 -142
  169. package/lib/vs/base/common/labels.js +0 -430
  170. package/lib/vs/base/common/lazy.js +0 -71
  171. package/lib/vs/base/common/lifecycle.js +0 -308
  172. package/lib/vs/base/common/linkedList.js +0 -152
  173. package/lib/vs/base/common/linkedText.js +0 -73
  174. package/lib/vs/base/common/map.js +0 -1108
  175. package/lib/vs/base/common/marshalling.js +0 -80
  176. package/lib/vs/base/common/mime.js +0 -321
  177. package/lib/vs/base/common/navigator.js +0 -50
  178. package/lib/vs/base/common/network.js +0 -160
  179. package/lib/vs/base/common/normalization.js +0 -78
  180. package/lib/vs/base/common/numbers.js +0 -55
  181. package/lib/vs/base/common/objects.js +0 -268
  182. package/lib/vs/base/common/paging.js +0 -190
  183. package/lib/vs/base/common/parsers.js +0 -78
  184. package/lib/vs/base/common/path.js +0 -1550
  185. package/lib/vs/base/common/platform.js +0 -245
  186. package/lib/vs/base/common/process.js +0 -52
  187. package/lib/vs/base/common/processes.js +0 -32
  188. package/lib/vs/base/common/range.js +0 -79
  189. package/lib/vs/base/common/resourceTree.js +0 -185
  190. package/lib/vs/base/common/resources.js +0 -421
  191. package/lib/vs/base/common/scanCode.js +0 -1472
  192. package/lib/vs/base/common/scrollable.js +0 -397
  193. package/lib/vs/base/common/search.js +0 -55
  194. package/lib/vs/base/common/sequence.js +0 -64
  195. package/lib/vs/base/common/severity.js +0 -55
  196. package/lib/vs/base/common/skipList.js +0 -234
  197. package/lib/vs/base/common/stopwatch.js +0 -45
  198. package/lib/vs/base/common/stream.js +0 -418
  199. package/lib/vs/base/common/strings.js +0 -1283
  200. package/lib/vs/base/common/styler.js +0 -9
  201. package/lib/vs/base/common/types.js +0 -296
  202. package/lib/vs/base/common/uint.js +0 -46
  203. package/lib/vs/base/common/uri.js +0 -756
  204. package/lib/vs/base/common/uriIpc.js +0 -154
  205. package/lib/vs/base/common/uuid.js +0 -70
  206. package/lib/vs/nls.mock.js +0 -31
  207. package/lib/vs/platform/actions/browser/menuEntryActionViewItem.js +0 -342
  208. package/lib/vs/platform/actions/common/actions.js +0 -456
  209. package/lib/vs/platform/actions/common/menuService.js +0 -194
  210. package/lib/vs/platform/clipboard/browser/clipboardService.js +0 -99
  211. package/lib/vs/platform/clipboard/common/clipboardService.js +0 -14
  212. package/lib/vs/platform/contextkey/common/contextkey.js +0 -1210
  213. package/lib/vs/platform/contextkey/common/contextkeys.js +0 -23
  214. package/lib/vs/platform/contextview/browser/contextView.js +0 -15
  215. package/lib/vs/platform/contextview/browser/contextViewService.js +0 -96
  216. package/lib/vs/platform/environment/common/argv.js +0 -9
  217. package/lib/vs/platform/environment/common/environment.js +0 -15
  218. package/lib/vs/platform/instantiation/common/descriptors.js +0 -25
  219. package/lib/vs/platform/instantiation/common/extensions.js +0 -26
  220. package/lib/vs/platform/instantiation/common/graph.js +0 -93
  221. package/lib/vs/platform/instantiation/common/instantiation.js +0 -84
  222. package/lib/vs/platform/instantiation/common/instantiationService.js +0 -361
  223. package/lib/vs/platform/instantiation/common/serviceCollection.js +0 -39
  224. package/lib/vs/platform/keybinding/common/baseResolvedKeybinding.js +0 -73
  225. package/lib/vs/platform/keybinding/common/keybinding.js +0 -14
  226. package/lib/vs/platform/keybinding/common/keybindingResolver.js +0 -391
  227. package/lib/vs/platform/keybinding/common/keybindingsRegistry.js +0 -229
  228. package/lib/vs/platform/keybinding/common/resolvedKeybindingItem.js +0 -47
  229. package/lib/vs/platform/keybinding/common/usLayoutResolvedKeybinding.js +0 -160
  230. package/lib/vs/platform/layout/browser/layoutService.js +0 -14
  231. package/lib/vs/platform/menubar/common/menubar.js +0 -34
  232. package/lib/vs/platform/registry/common/platform.js +0 -38
  233. package/lib/vs/platform/theme/browser/checkbox.js +0 -32
  234. package/lib/vs/platform/theme/common/colorRegistry.js +0 -1154
  235. package/lib/vs/platform/theme/common/styler.js +0 -290
  236. package/lib/vs/platform/theme/common/theme.js +0 -21
  237. package/lib/vs/platform/theme/common/themeService.js +0 -176
  238. package/lib/vs/platform/theme/common/tokenClassificationRegistry.js +0 -540
  239. package/lib/vs/platform/theme/test/common/testThemeService.js +0 -98
@@ -1,1139 +0,0 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Microsoft Corporation. All rights reserved.
4
- * Licensed under the MIT License. See License.txt in the project root for license information.
5
- *--------------------------------------------------------------------------------------------*/
6
-
7
- Object.defineProperty(exports, "__esModule", {
8
- value: true
9
- });
10
- exports.MenuBar = void 0;
11
-
12
- require("../../../../css!./menubar");
13
-
14
- const browser = require("../../browser");
15
-
16
- const DOM = require("../../dom");
17
-
18
- const strings = require("../../../common/strings");
19
-
20
- const nls = require("../../../../nls");
21
-
22
- const event_1 = require("../../event");
23
-
24
- const keyboardEvent_1 = require("../../keyboardEvent");
25
-
26
- const touch_1 = require("../../touch");
27
-
28
- const menu_1 = require("./menu");
29
-
30
- const actions_1 = require("../../../common/actions");
31
-
32
- const async_1 = require("../../../common/async");
33
-
34
- const event_2 = require("../../../common/event");
35
-
36
- const lifecycle_1 = require("../../../common/lifecycle");
37
-
38
- const types_1 = require("../../../common/types");
39
-
40
- const arrays_1 = require("../../../common/arrays");
41
-
42
- const scanCode_1 = require("../../../common/scanCode");
43
-
44
- const platform_1 = require("../../../common/platform");
45
-
46
- const mouseEvent_1 = require("../../mouseEvent");
47
-
48
- const codicons_1 = require("../../../common/codicons");
49
-
50
- const $ = DOM.$;
51
- const menuBarMoreIcon = codicons_1.registerIcon('menubar-more', codicons_1.Codicon.more);
52
- var MenubarState;
53
-
54
- (function (MenubarState) {
55
- MenubarState[MenubarState["HIDDEN"] = 0] = "HIDDEN";
56
- MenubarState[MenubarState["VISIBLE"] = 1] = "VISIBLE";
57
- MenubarState[MenubarState["FOCUSED"] = 2] = "FOCUSED";
58
- MenubarState[MenubarState["OPEN"] = 3] = "OPEN";
59
- })(MenubarState || (MenubarState = {}));
60
-
61
- class MenuBar extends lifecycle_1.Disposable {
62
- constructor(container, options = {}) {
63
- super();
64
- this.container = container;
65
- this.options = options; // Input-related
66
-
67
- this._mnemonicsInUse = false;
68
- this.openedViaKeyboard = false;
69
- this.awaitingAltRelease = false;
70
- this.ignoreNextMouseUp = false;
71
- this.updatePending = false;
72
- this.numMenusShown = 0;
73
- this.overflowLayoutScheduled = undefined;
74
- this.container.setAttribute('role', 'menubar');
75
-
76
- if (this.options.compactMode !== undefined) {
77
- this.container.classList.add('compact');
78
- }
79
-
80
- this.menuCache = [];
81
- this.mnemonics = new Map();
82
- this._focusState = MenubarState.VISIBLE;
83
- this._onVisibilityChange = this._register(new event_2.Emitter());
84
- this._onFocusStateChange = this._register(new event_2.Emitter());
85
- this.createOverflowMenu();
86
- this.menuUpdater = this._register(new async_1.RunOnceScheduler(() => this.update(), 200));
87
- this.actionRunner = this._register(new actions_1.ActionRunner());
88
-
89
- this._register(this.actionRunner.onDidBeforeRun(() => {
90
- this.setUnfocusedState();
91
- }));
92
-
93
- this._register(ModifierKeyEmitter.getInstance().event(this.onModifierKeyToggled, this));
94
-
95
- this._register(DOM.addDisposableListener(this.container, DOM.EventType.KEY_DOWN, e => {
96
- let event = new keyboardEvent_1.StandardKeyboardEvent(e);
97
- let eventHandled = true;
98
- const key = !!e.key ? e.key.toLocaleLowerCase() : '';
99
-
100
- if (event.equals(15
101
- /* LeftArrow */
102
- ) || platform_1.isMacintosh && event.equals(2
103
- /* Tab */
104
- | 1024
105
- /* Shift */
106
- )) {
107
- this.focusPrevious();
108
- } else if (event.equals(17
109
- /* RightArrow */
110
- ) || platform_1.isMacintosh && event.equals(2
111
- /* Tab */
112
- )) {
113
- this.focusNext();
114
- } else if (event.equals(9
115
- /* Escape */
116
- ) && this.isFocused && !this.isOpen) {
117
- this.setUnfocusedState();
118
- } else if (!this.isOpen && !event.ctrlKey && this.options.enableMnemonics && this.mnemonicsInUse && this.mnemonics.has(key)) {
119
- const menuIndex = this.mnemonics.get(key);
120
- this.onMenuTriggered(menuIndex, false);
121
- } else {
122
- eventHandled = false;
123
- } // Never allow default tab behavior when not compact
124
-
125
-
126
- if (this.options.compactMode === undefined && (event.equals(2
127
- /* Tab */
128
- | 1024
129
- /* Shift */
130
- ) || event.equals(2
131
- /* Tab */
132
- ))) {
133
- event.preventDefault();
134
- }
135
-
136
- if (eventHandled) {
137
- event.preventDefault();
138
- event.stopPropagation();
139
- }
140
- }));
141
-
142
- this._register(DOM.addDisposableListener(window, DOM.EventType.MOUSE_DOWN, () => {
143
- // This mouse event is outside the menubar so it counts as a focus out
144
- if (this.isFocused) {
145
- this.setUnfocusedState();
146
- }
147
- }));
148
-
149
- this._register(DOM.addDisposableListener(this.container, DOM.EventType.FOCUS_IN, e => {
150
- let event = e;
151
-
152
- if (event.relatedTarget) {
153
- if (!this.container.contains(event.relatedTarget)) {
154
- this.focusToReturn = event.relatedTarget;
155
- }
156
- }
157
- }));
158
-
159
- this._register(DOM.addDisposableListener(this.container, DOM.EventType.FOCUS_OUT, e => {
160
- let event = e; // We are losing focus and there is no related target, e.g. webview case
161
-
162
- if (!event.relatedTarget) {
163
- this.setUnfocusedState();
164
- } // We are losing focus and there is a target, reset focusToReturn value as not to redirect
165
- else if (event.relatedTarget && !this.container.contains(event.relatedTarget)) {
166
- this.focusToReturn = undefined;
167
- this.setUnfocusedState();
168
- }
169
- }));
170
-
171
- this._register(DOM.addDisposableListener(window, DOM.EventType.KEY_DOWN, e => {
172
- if (!this.options.enableMnemonics || !e.altKey || e.ctrlKey || e.defaultPrevented) {
173
- return;
174
- }
175
-
176
- const key = e.key.toLocaleLowerCase();
177
-
178
- if (!this.mnemonics.has(key)) {
179
- return;
180
- }
181
-
182
- this.mnemonicsInUse = true;
183
- this.updateMnemonicVisibility(true);
184
- const menuIndex = this.mnemonics.get(key);
185
- this.onMenuTriggered(menuIndex, false);
186
- }));
187
-
188
- this.setUnfocusedState();
189
- }
190
-
191
- push(arg) {
192
- const menus = arrays_1.asArray(arg);
193
- menus.forEach(menuBarMenu => {
194
- const menuIndex = this.menuCache.length;
195
- const cleanMenuLabel = menu_1.cleanMnemonic(menuBarMenu.label);
196
- const buttonElement = $('div.menubar-menu-button', {
197
- 'role': 'menuitem',
198
- 'tabindex': -1,
199
- 'aria-label': cleanMenuLabel,
200
- 'aria-haspopup': true
201
- });
202
- const titleElement = $('div.menubar-menu-title', {
203
- 'role': 'none',
204
- 'aria-hidden': true
205
- });
206
- buttonElement.appendChild(titleElement);
207
- this.container.insertBefore(buttonElement, this.overflowMenu.buttonElement);
208
- let mnemonicMatches = menu_1.MENU_MNEMONIC_REGEX.exec(menuBarMenu.label); // Register mnemonics
209
-
210
- if (mnemonicMatches) {
211
- let mnemonic = !!mnemonicMatches[1] ? mnemonicMatches[1] : mnemonicMatches[3];
212
- this.registerMnemonic(this.menuCache.length, mnemonic);
213
- }
214
-
215
- this.updateLabels(titleElement, buttonElement, menuBarMenu.label);
216
-
217
- this._register(DOM.addDisposableListener(buttonElement, DOM.EventType.KEY_UP, e => {
218
- let event = new keyboardEvent_1.StandardKeyboardEvent(e);
219
- let eventHandled = true;
220
-
221
- if ((event.equals(18
222
- /* DownArrow */
223
- ) || event.equals(3
224
- /* Enter */
225
- )) && !this.isOpen) {
226
- this.focusedMenu = {
227
- index: menuIndex
228
- };
229
- this.openedViaKeyboard = true;
230
- this.focusState = MenubarState.OPEN;
231
- } else {
232
- eventHandled = false;
233
- }
234
-
235
- if (eventHandled) {
236
- event.preventDefault();
237
- event.stopPropagation();
238
- }
239
- }));
240
-
241
- this._register(touch_1.Gesture.addTarget(buttonElement));
242
-
243
- this._register(DOM.addDisposableListener(buttonElement, touch_1.EventType.Tap, e => {
244
- // Ignore this touch if the menu is touched
245
- if (this.isOpen && this.focusedMenu && this.focusedMenu.holder && DOM.isAncestor(e.initialTarget, this.focusedMenu.holder)) {
246
- return;
247
- }
248
-
249
- this.ignoreNextMouseUp = false;
250
- this.onMenuTriggered(menuIndex, true);
251
- e.preventDefault();
252
- e.stopPropagation();
253
- }));
254
-
255
- this._register(DOM.addDisposableListener(buttonElement, DOM.EventType.MOUSE_DOWN, e => {
256
- // Ignore non-left-click
257
- const mouseEvent = new mouseEvent_1.StandardMouseEvent(e);
258
-
259
- if (!mouseEvent.leftButton) {
260
- e.preventDefault();
261
- return;
262
- }
263
-
264
- if (!this.isOpen) {
265
- // Open the menu with mouse down and ignore the following mouse up event
266
- this.ignoreNextMouseUp = true;
267
- this.onMenuTriggered(menuIndex, true);
268
- } else {
269
- this.ignoreNextMouseUp = false;
270
- }
271
-
272
- e.preventDefault();
273
- e.stopPropagation();
274
- }));
275
-
276
- this._register(DOM.addDisposableListener(buttonElement, DOM.EventType.MOUSE_UP, e => {
277
- if (e.defaultPrevented) {
278
- return;
279
- }
280
-
281
- if (!this.ignoreNextMouseUp) {
282
- if (this.isFocused) {
283
- this.onMenuTriggered(menuIndex, true);
284
- }
285
- } else {
286
- this.ignoreNextMouseUp = false;
287
- }
288
- }));
289
-
290
- this._register(DOM.addDisposableListener(buttonElement, DOM.EventType.MOUSE_ENTER, () => {
291
- if (this.isOpen && !this.isCurrentMenu(menuIndex)) {
292
- this.menuCache[menuIndex].buttonElement.focus();
293
- this.cleanupCustomMenu();
294
- this.showCustomMenu(menuIndex, false);
295
- } else if (this.isFocused && !this.isOpen) {
296
- this.focusedMenu = {
297
- index: menuIndex
298
- };
299
- buttonElement.focus();
300
- }
301
- }));
302
-
303
- this.menuCache.push({
304
- label: menuBarMenu.label,
305
- actions: menuBarMenu.actions,
306
- buttonElement: buttonElement,
307
- titleElement: titleElement
308
- });
309
- });
310
- }
311
-
312
- createOverflowMenu() {
313
- const label = this.options.compactMode !== undefined ? nls.localize('mAppMenu', 'Application Menu') : nls.localize('mMore', 'More');
314
- const title = this.options.compactMode !== undefined ? label : undefined;
315
- const buttonElement = $('div.menubar-menu-button', {
316
- 'role': 'menuitem',
317
- 'tabindex': this.options.compactMode !== undefined ? 0 : -1,
318
- 'aria-label': label,
319
- 'title': title,
320
- 'aria-haspopup': true
321
- });
322
- const titleElement = $('div.menubar-menu-title.toolbar-toggle-more' + menuBarMoreIcon.cssSelector, {
323
- 'role': 'none',
324
- 'aria-hidden': true
325
- });
326
- buttonElement.appendChild(titleElement);
327
- this.container.appendChild(buttonElement);
328
- buttonElement.style.visibility = 'hidden';
329
-
330
- this._register(DOM.addDisposableListener(buttonElement, DOM.EventType.KEY_UP, e => {
331
- let event = new keyboardEvent_1.StandardKeyboardEvent(e);
332
- let eventHandled = true;
333
- const triggerKeys = [3
334
- /* Enter */
335
- ];
336
-
337
- if (this.options.compactMode === undefined) {
338
- triggerKeys.push(18
339
- /* DownArrow */
340
- );
341
- } else {
342
- triggerKeys.push(10
343
- /* Space */
344
- );
345
- triggerKeys.push(this.options.compactMode === menu_1.Direction.Right ? 17
346
- /* RightArrow */
347
- : 15
348
- /* LeftArrow */
349
- );
350
- }
351
-
352
- if (triggerKeys.some(k => event.equals(k)) && !this.isOpen) {
353
- this.focusedMenu = {
354
- index: MenuBar.OVERFLOW_INDEX
355
- };
356
- this.openedViaKeyboard = true;
357
- this.focusState = MenubarState.OPEN;
358
- } else {
359
- eventHandled = false;
360
- }
361
-
362
- if (eventHandled) {
363
- event.preventDefault();
364
- event.stopPropagation();
365
- }
366
- }));
367
-
368
- this._register(touch_1.Gesture.addTarget(buttonElement));
369
-
370
- this._register(DOM.addDisposableListener(buttonElement, touch_1.EventType.Tap, e => {
371
- // Ignore this touch if the menu is touched
372
- if (this.isOpen && this.focusedMenu && this.focusedMenu.holder && DOM.isAncestor(e.initialTarget, this.focusedMenu.holder)) {
373
- return;
374
- }
375
-
376
- this.ignoreNextMouseUp = false;
377
- this.onMenuTriggered(MenuBar.OVERFLOW_INDEX, true);
378
- e.preventDefault();
379
- e.stopPropagation();
380
- }));
381
-
382
- this._register(DOM.addDisposableListener(buttonElement, DOM.EventType.MOUSE_DOWN, e => {
383
- // Ignore non-left-click
384
- const mouseEvent = new mouseEvent_1.StandardMouseEvent(e);
385
-
386
- if (!mouseEvent.leftButton) {
387
- e.preventDefault();
388
- return;
389
- }
390
-
391
- if (!this.isOpen) {
392
- // Open the menu with mouse down and ignore the following mouse up event
393
- this.ignoreNextMouseUp = true;
394
- this.onMenuTriggered(MenuBar.OVERFLOW_INDEX, true);
395
- } else {
396
- this.ignoreNextMouseUp = false;
397
- }
398
-
399
- e.preventDefault();
400
- e.stopPropagation();
401
- }));
402
-
403
- this._register(DOM.addDisposableListener(buttonElement, DOM.EventType.MOUSE_UP, e => {
404
- if (e.defaultPrevented) {
405
- return;
406
- }
407
-
408
- if (!this.ignoreNextMouseUp) {
409
- if (this.isFocused) {
410
- this.onMenuTriggered(MenuBar.OVERFLOW_INDEX, true);
411
- }
412
- } else {
413
- this.ignoreNextMouseUp = false;
414
- }
415
- }));
416
-
417
- this._register(DOM.addDisposableListener(buttonElement, DOM.EventType.MOUSE_ENTER, () => {
418
- if (this.isOpen && !this.isCurrentMenu(MenuBar.OVERFLOW_INDEX)) {
419
- this.overflowMenu.buttonElement.focus();
420
- this.cleanupCustomMenu();
421
- this.showCustomMenu(MenuBar.OVERFLOW_INDEX, false);
422
- } else if (this.isFocused && !this.isOpen) {
423
- this.focusedMenu = {
424
- index: MenuBar.OVERFLOW_INDEX
425
- };
426
- buttonElement.focus();
427
- }
428
- }));
429
-
430
- this.overflowMenu = {
431
- buttonElement: buttonElement,
432
- titleElement: titleElement,
433
- label: 'More'
434
- };
435
- }
436
-
437
- updateMenu(menu) {
438
- const menuToUpdate = this.menuCache.filter(menuBarMenu => menuBarMenu.label === menu.label);
439
-
440
- if (menuToUpdate && menuToUpdate.length) {
441
- menuToUpdate[0].actions = menu.actions;
442
- }
443
- }
444
-
445
- dispose() {
446
- super.dispose();
447
- this.menuCache.forEach(menuBarMenu => {
448
- menuBarMenu.titleElement.remove();
449
- menuBarMenu.buttonElement.remove();
450
- });
451
- this.overflowMenu.titleElement.remove();
452
- this.overflowMenu.buttonElement.remove();
453
- lifecycle_1.dispose(this.overflowLayoutScheduled);
454
- this.overflowLayoutScheduled = undefined;
455
- }
456
-
457
- blur() {
458
- this.setUnfocusedState();
459
- }
460
-
461
- getWidth() {
462
- if (this.menuCache) {
463
- const left = this.menuCache[0].buttonElement.getBoundingClientRect().left;
464
- const right = this.hasOverflow ? this.overflowMenu.buttonElement.getBoundingClientRect().right : this.menuCache[this.menuCache.length - 1].buttonElement.getBoundingClientRect().right;
465
- return right - left;
466
- }
467
-
468
- return 0;
469
- }
470
-
471
- getHeight() {
472
- return this.container.clientHeight;
473
- }
474
-
475
- toggleFocus() {
476
- if (!this.isFocused && this.options.visibility !== 'hidden') {
477
- this.mnemonicsInUse = true;
478
- this.focusedMenu = {
479
- index: this.numMenusShown > 0 ? 0 : MenuBar.OVERFLOW_INDEX
480
- };
481
- this.focusState = MenubarState.FOCUSED;
482
- } else if (!this.isOpen) {
483
- this.setUnfocusedState();
484
- }
485
- }
486
-
487
- updateOverflowAction() {
488
- var _a, _b;
489
-
490
- if (!this.menuCache || !this.menuCache.length) {
491
- return;
492
- }
493
-
494
- const sizeAvailable = this.container.offsetWidth;
495
- let currentSize = 0;
496
- let full = this.options.compactMode !== undefined;
497
- const prevNumMenusShown = this.numMenusShown;
498
- this.numMenusShown = 0;
499
-
500
- for (let menuBarMenu of this.menuCache) {
501
- if (!full) {
502
- const size = menuBarMenu.buttonElement.offsetWidth;
503
-
504
- if (currentSize + size > sizeAvailable) {
505
- full = true;
506
- } else {
507
- currentSize += size;
508
- this.numMenusShown++;
509
-
510
- if (this.numMenusShown > prevNumMenusShown) {
511
- menuBarMenu.buttonElement.style.visibility = 'visible';
512
- }
513
- }
514
- }
515
-
516
- if (full) {
517
- menuBarMenu.buttonElement.style.visibility = 'hidden';
518
- }
519
- } // Overflow
520
-
521
-
522
- if (full) {
523
- // Can't fit the more button, need to remove more menus
524
- while (currentSize + this.overflowMenu.buttonElement.offsetWidth > sizeAvailable && this.numMenusShown > 0) {
525
- this.numMenusShown--;
526
- const size = this.menuCache[this.numMenusShown].buttonElement.offsetWidth;
527
- this.menuCache[this.numMenusShown].buttonElement.style.visibility = 'hidden';
528
- currentSize -= size;
529
- }
530
-
531
- this.overflowMenu.actions = [];
532
-
533
- for (let idx = this.numMenusShown; idx < this.menuCache.length; idx++) {
534
- this.overflowMenu.actions.push(new actions_1.SubmenuAction(`menubar.submenu.${this.menuCache[idx].label}`, this.menuCache[idx].label, this.menuCache[idx].actions || []));
535
- }
536
-
537
- if (this.overflowMenu.buttonElement.nextElementSibling !== this.menuCache[this.numMenusShown].buttonElement) {
538
- this.overflowMenu.buttonElement.remove();
539
- this.container.insertBefore(this.overflowMenu.buttonElement, this.menuCache[this.numMenusShown].buttonElement);
540
- this.overflowMenu.buttonElement.style.visibility = 'visible';
541
- }
542
-
543
- const compactMenuActions = (_b = (_a = this.options).getCompactMenuActions) === null || _b === void 0 ? void 0 : _b.call(_a);
544
-
545
- if (compactMenuActions && compactMenuActions.length) {
546
- this.overflowMenu.actions.push(new actions_1.Separator());
547
- this.overflowMenu.actions.push(...compactMenuActions);
548
- }
549
- } else {
550
- this.overflowMenu.buttonElement.remove();
551
- this.container.appendChild(this.overflowMenu.buttonElement);
552
- this.overflowMenu.buttonElement.style.visibility = 'hidden';
553
- }
554
- }
555
-
556
- updateLabels(titleElement, buttonElement, label) {
557
- const cleanMenuLabel = menu_1.cleanMnemonic(label); // Update the button label to reflect mnemonics
558
-
559
- if (this.options.enableMnemonics) {
560
- let cleanLabel = strings.escape(label); // This is global so reset it
561
-
562
- menu_1.MENU_ESCAPED_MNEMONIC_REGEX.lastIndex = 0;
563
- let escMatch = menu_1.MENU_ESCAPED_MNEMONIC_REGEX.exec(cleanLabel); // We can't use negative lookbehind so we match our negative and skip
564
-
565
- while (escMatch && escMatch[1]) {
566
- escMatch = menu_1.MENU_ESCAPED_MNEMONIC_REGEX.exec(cleanLabel);
567
- }
568
-
569
- const replaceDoubleEscapes = str => str.replace(/&amp;&amp;/g, '&amp;');
570
-
571
- if (escMatch) {
572
- titleElement.innerText = '';
573
- titleElement.append(strings.ltrim(replaceDoubleEscapes(cleanLabel.substr(0, escMatch.index)), ' '), $('mnemonic', {
574
- 'aria-hidden': 'true'
575
- }, escMatch[3]), strings.rtrim(replaceDoubleEscapes(cleanLabel.substr(escMatch.index + escMatch[0].length)), ' '));
576
- } else {
577
- titleElement.innerText = replaceDoubleEscapes(cleanLabel).trim();
578
- }
579
- } else {
580
- titleElement.innerText = cleanMenuLabel.replace(/&&/g, '&');
581
- }
582
-
583
- let mnemonicMatches = menu_1.MENU_MNEMONIC_REGEX.exec(label); // Register mnemonics
584
-
585
- if (mnemonicMatches) {
586
- let mnemonic = !!mnemonicMatches[1] ? mnemonicMatches[1] : mnemonicMatches[3];
587
-
588
- if (this.options.enableMnemonics) {
589
- buttonElement.setAttribute('aria-keyshortcuts', 'Alt+' + mnemonic.toLocaleLowerCase());
590
- } else {
591
- buttonElement.removeAttribute('aria-keyshortcuts');
592
- }
593
- }
594
- }
595
-
596
- style(style) {
597
- this.menuStyle = style;
598
- }
599
-
600
- update(options) {
601
- if (options) {
602
- this.options = options;
603
- } // Don't update while using the menu
604
-
605
-
606
- if (this.isFocused) {
607
- this.updatePending = true;
608
- return;
609
- }
610
-
611
- this.menuCache.forEach(menuBarMenu => {
612
- this.updateLabels(menuBarMenu.titleElement, menuBarMenu.buttonElement, menuBarMenu.label);
613
- });
614
-
615
- if (!this.overflowLayoutScheduled) {
616
- this.overflowLayoutScheduled = DOM.scheduleAtNextAnimationFrame(() => {
617
- this.updateOverflowAction();
618
- this.overflowLayoutScheduled = undefined;
619
- });
620
- }
621
-
622
- this.setUnfocusedState();
623
- }
624
-
625
- registerMnemonic(menuIndex, mnemonic) {
626
- this.mnemonics.set(mnemonic.toLocaleLowerCase(), menuIndex);
627
- }
628
-
629
- hideMenubar() {
630
- if (this.container.style.display !== 'none') {
631
- this.container.style.display = 'none';
632
-
633
- this._onVisibilityChange.fire(false);
634
- }
635
- }
636
-
637
- showMenubar() {
638
- if (this.container.style.display !== 'flex') {
639
- this.container.style.display = 'flex';
640
-
641
- this._onVisibilityChange.fire(true);
642
-
643
- this.updateOverflowAction();
644
- }
645
- }
646
-
647
- get focusState() {
648
- return this._focusState;
649
- }
650
-
651
- set focusState(value) {
652
- if (this._focusState >= MenubarState.FOCUSED && value < MenubarState.FOCUSED) {
653
- // Losing focus, update the menu if needed
654
- if (this.updatePending) {
655
- this.menuUpdater.schedule();
656
- this.updatePending = false;
657
- }
658
- }
659
-
660
- if (value === this._focusState) {
661
- return;
662
- }
663
-
664
- const isVisible = this.isVisible;
665
- const isOpen = this.isOpen;
666
- const isFocused = this.isFocused;
667
- this._focusState = value;
668
-
669
- switch (value) {
670
- case MenubarState.HIDDEN:
671
- if (isVisible) {
672
- this.hideMenubar();
673
- }
674
-
675
- if (isOpen) {
676
- this.cleanupCustomMenu();
677
- }
678
-
679
- if (isFocused) {
680
- this.focusedMenu = undefined;
681
-
682
- if (this.focusToReturn) {
683
- this.focusToReturn.focus();
684
- this.focusToReturn = undefined;
685
- }
686
- }
687
-
688
- break;
689
-
690
- case MenubarState.VISIBLE:
691
- if (!isVisible) {
692
- this.showMenubar();
693
- }
694
-
695
- if (isOpen) {
696
- this.cleanupCustomMenu();
697
- }
698
-
699
- if (isFocused) {
700
- if (this.focusedMenu) {
701
- if (this.focusedMenu.index === MenuBar.OVERFLOW_INDEX) {
702
- this.overflowMenu.buttonElement.blur();
703
- } else {
704
- this.menuCache[this.focusedMenu.index].buttonElement.blur();
705
- }
706
- }
707
-
708
- this.focusedMenu = undefined;
709
-
710
- if (this.focusToReturn) {
711
- this.focusToReturn.focus();
712
- this.focusToReturn = undefined;
713
- }
714
- }
715
-
716
- break;
717
-
718
- case MenubarState.FOCUSED:
719
- if (!isVisible) {
720
- this.showMenubar();
721
- }
722
-
723
- if (isOpen) {
724
- this.cleanupCustomMenu();
725
- }
726
-
727
- if (this.focusedMenu) {
728
- if (this.focusedMenu.index === MenuBar.OVERFLOW_INDEX) {
729
- this.overflowMenu.buttonElement.focus();
730
- } else {
731
- this.menuCache[this.focusedMenu.index].buttonElement.focus();
732
- }
733
- }
734
-
735
- break;
736
-
737
- case MenubarState.OPEN:
738
- if (!isVisible) {
739
- this.showMenubar();
740
- }
741
-
742
- if (this.focusedMenu) {
743
- this.showCustomMenu(this.focusedMenu.index, this.openedViaKeyboard);
744
- }
745
-
746
- break;
747
- }
748
-
749
- this._focusState = value;
750
-
751
- this._onFocusStateChange.fire(this.focusState >= MenubarState.FOCUSED);
752
- }
753
-
754
- get isVisible() {
755
- return this.focusState >= MenubarState.VISIBLE;
756
- }
757
-
758
- get isFocused() {
759
- return this.focusState >= MenubarState.FOCUSED;
760
- }
761
-
762
- get isOpen() {
763
- return this.focusState >= MenubarState.OPEN;
764
- }
765
-
766
- get hasOverflow() {
767
- return this.numMenusShown < this.menuCache.length;
768
- }
769
-
770
- setUnfocusedState() {
771
- if (this.options.visibility === 'toggle' || this.options.visibility === 'hidden') {
772
- this.focusState = MenubarState.HIDDEN;
773
- } else if (this.options.visibility === 'default' && browser.isFullscreen()) {
774
- this.focusState = MenubarState.HIDDEN;
775
- } else {
776
- this.focusState = MenubarState.VISIBLE;
777
- }
778
-
779
- this.ignoreNextMouseUp = false;
780
- this.mnemonicsInUse = false;
781
- this.updateMnemonicVisibility(false);
782
- }
783
-
784
- focusPrevious() {
785
- if (!this.focusedMenu || this.numMenusShown === 0) {
786
- return;
787
- }
788
-
789
- let newFocusedIndex = (this.focusedMenu.index - 1 + this.numMenusShown) % this.numMenusShown;
790
-
791
- if (this.focusedMenu.index === MenuBar.OVERFLOW_INDEX) {
792
- newFocusedIndex = this.numMenusShown - 1;
793
- } else if (this.focusedMenu.index === 0 && this.hasOverflow) {
794
- newFocusedIndex = MenuBar.OVERFLOW_INDEX;
795
- }
796
-
797
- if (newFocusedIndex === this.focusedMenu.index) {
798
- return;
799
- }
800
-
801
- if (this.isOpen) {
802
- this.cleanupCustomMenu();
803
- this.showCustomMenu(newFocusedIndex);
804
- } else if (this.isFocused) {
805
- this.focusedMenu.index = newFocusedIndex;
806
-
807
- if (newFocusedIndex === MenuBar.OVERFLOW_INDEX) {
808
- this.overflowMenu.buttonElement.focus();
809
- } else {
810
- this.menuCache[newFocusedIndex].buttonElement.focus();
811
- }
812
- }
813
- }
814
-
815
- focusNext() {
816
- if (!this.focusedMenu || this.numMenusShown === 0) {
817
- return;
818
- }
819
-
820
- let newFocusedIndex = (this.focusedMenu.index + 1) % this.numMenusShown;
821
-
822
- if (this.focusedMenu.index === MenuBar.OVERFLOW_INDEX) {
823
- newFocusedIndex = 0;
824
- } else if (this.focusedMenu.index === this.numMenusShown - 1) {
825
- newFocusedIndex = MenuBar.OVERFLOW_INDEX;
826
- }
827
-
828
- if (newFocusedIndex === this.focusedMenu.index) {
829
- return;
830
- }
831
-
832
- if (this.isOpen) {
833
- this.cleanupCustomMenu();
834
- this.showCustomMenu(newFocusedIndex);
835
- } else if (this.isFocused) {
836
- this.focusedMenu.index = newFocusedIndex;
837
-
838
- if (newFocusedIndex === MenuBar.OVERFLOW_INDEX) {
839
- this.overflowMenu.buttonElement.focus();
840
- } else {
841
- this.menuCache[newFocusedIndex].buttonElement.focus();
842
- }
843
- }
844
- }
845
-
846
- updateMnemonicVisibility(visible) {
847
- if (this.menuCache) {
848
- this.menuCache.forEach(menuBarMenu => {
849
- if (menuBarMenu.titleElement.children.length) {
850
- let child = menuBarMenu.titleElement.children.item(0);
851
-
852
- if (child) {
853
- child.style.textDecoration = this.options.alwaysOnMnemonics || visible ? 'underline' : '';
854
- }
855
- }
856
- });
857
- }
858
- }
859
-
860
- get mnemonicsInUse() {
861
- return this._mnemonicsInUse;
862
- }
863
-
864
- set mnemonicsInUse(value) {
865
- this._mnemonicsInUse = value;
866
- }
867
-
868
- get onVisibilityChange() {
869
- return this._onVisibilityChange.event;
870
- }
871
-
872
- get onFocusStateChange() {
873
- return this._onFocusStateChange.event;
874
- }
875
-
876
- onMenuTriggered(menuIndex, clicked) {
877
- if (this.isOpen) {
878
- if (this.isCurrentMenu(menuIndex)) {
879
- this.setUnfocusedState();
880
- } else {
881
- this.cleanupCustomMenu();
882
- this.showCustomMenu(menuIndex, this.openedViaKeyboard);
883
- }
884
- } else {
885
- this.focusedMenu = {
886
- index: menuIndex
887
- };
888
- this.openedViaKeyboard = !clicked;
889
- this.focusState = MenubarState.OPEN;
890
- }
891
- }
892
-
893
- onModifierKeyToggled(modifierKeyStatus) {
894
- const allModifiersReleased = !modifierKeyStatus.altKey && !modifierKeyStatus.ctrlKey && !modifierKeyStatus.shiftKey;
895
-
896
- if (this.options.visibility === 'hidden') {
897
- return;
898
- } // Prevent alt-key default if the menu is not hidden and we use alt to focus
899
-
900
-
901
- if (modifierKeyStatus.event && !this.options.disableAltFocus) {
902
- if (scanCode_1.ScanCodeUtils.toEnum(modifierKeyStatus.event.code) === 159
903
- /* AltLeft */
904
- ) {
905
- modifierKeyStatus.event.preventDefault();
906
- }
907
- } // Alt key pressed while menu is focused. This should return focus away from the menubar
908
-
909
-
910
- if (this.isFocused && modifierKeyStatus.lastKeyPressed === 'alt' && modifierKeyStatus.altKey) {
911
- this.setUnfocusedState();
912
- this.mnemonicsInUse = false;
913
- this.awaitingAltRelease = true;
914
- } // Clean alt key press and release
915
-
916
-
917
- if (allModifiersReleased && modifierKeyStatus.lastKeyPressed === 'alt' && modifierKeyStatus.lastKeyReleased === 'alt') {
918
- if (!this.awaitingAltRelease) {
919
- if (!this.isFocused && !(this.options.disableAltFocus && this.options.visibility !== 'toggle')) {
920
- this.mnemonicsInUse = true;
921
- this.focusedMenu = {
922
- index: this.numMenusShown > 0 ? 0 : MenuBar.OVERFLOW_INDEX
923
- };
924
- this.focusState = MenubarState.FOCUSED;
925
- } else if (!this.isOpen) {
926
- this.setUnfocusedState();
927
- }
928
- }
929
- } // Alt key released
930
-
931
-
932
- if (!modifierKeyStatus.altKey && modifierKeyStatus.lastKeyReleased === 'alt') {
933
- this.awaitingAltRelease = false;
934
- }
935
-
936
- if (this.options.enableMnemonics && this.menuCache && !this.isOpen) {
937
- this.updateMnemonicVisibility(!this.awaitingAltRelease && modifierKeyStatus.altKey || this.mnemonicsInUse);
938
- }
939
- }
940
-
941
- isCurrentMenu(menuIndex) {
942
- if (!this.focusedMenu) {
943
- return false;
944
- }
945
-
946
- return this.focusedMenu.index === menuIndex;
947
- }
948
-
949
- cleanupCustomMenu() {
950
- if (this.focusedMenu) {
951
- // Remove focus from the menus first
952
- if (this.focusedMenu.index === MenuBar.OVERFLOW_INDEX) {
953
- this.overflowMenu.buttonElement.focus();
954
- } else {
955
- this.menuCache[this.focusedMenu.index].buttonElement.focus();
956
- }
957
-
958
- if (this.focusedMenu.holder) {
959
- if (this.focusedMenu.holder.parentElement) {
960
- this.focusedMenu.holder.parentElement.classList.remove('open');
961
- }
962
-
963
- this.focusedMenu.holder.remove();
964
- }
965
-
966
- if (this.focusedMenu.widget) {
967
- this.focusedMenu.widget.dispose();
968
- }
969
-
970
- this.focusedMenu = {
971
- index: this.focusedMenu.index
972
- };
973
- }
974
- }
975
-
976
- showCustomMenu(menuIndex, selectFirst = true) {
977
- const actualMenuIndex = menuIndex >= this.numMenusShown ? MenuBar.OVERFLOW_INDEX : menuIndex;
978
- const customMenu = actualMenuIndex === MenuBar.OVERFLOW_INDEX ? this.overflowMenu : this.menuCache[actualMenuIndex];
979
-
980
- if (!customMenu.actions) {
981
- return;
982
- }
983
-
984
- const menuHolder = $('div.menubar-menu-items-holder', {
985
- 'title': ''
986
- });
987
- customMenu.buttonElement.classList.add('open');
988
-
989
- if (this.options.compactMode === menu_1.Direction.Right) {
990
- menuHolder.style.top = `0px`;
991
- menuHolder.style.left = `${customMenu.buttonElement.getBoundingClientRect().left + this.container.clientWidth}px`;
992
- } else if (this.options.compactMode === menu_1.Direction.Left) {
993
- menuHolder.style.top = `0px`;
994
- menuHolder.style.right = `${this.container.clientWidth}px`;
995
- menuHolder.style.left = 'auto';
996
- } else {
997
- menuHolder.style.top = `${this.container.clientHeight}px`;
998
- menuHolder.style.left = `${customMenu.buttonElement.getBoundingClientRect().left}px`;
999
- }
1000
-
1001
- customMenu.buttonElement.appendChild(menuHolder);
1002
- let menuOptions = {
1003
- getKeyBinding: this.options.getKeybinding,
1004
- actionRunner: this.actionRunner,
1005
- enableMnemonics: this.options.alwaysOnMnemonics || this.mnemonicsInUse && this.options.enableMnemonics,
1006
- ariaLabel: types_1.withNullAsUndefined(customMenu.buttonElement.getAttribute('aria-label')),
1007
- expandDirection: this.options.compactMode !== undefined ? this.options.compactMode : menu_1.Direction.Right,
1008
- useEventAsContext: true
1009
- };
1010
-
1011
- let menuWidget = this._register(new menu_1.Menu(menuHolder, customMenu.actions, menuOptions));
1012
-
1013
- if (this.menuStyle) {
1014
- menuWidget.style(this.menuStyle);
1015
- }
1016
-
1017
- this._register(menuWidget.onDidCancel(() => {
1018
- this.focusState = MenubarState.FOCUSED;
1019
- }));
1020
-
1021
- if (actualMenuIndex !== menuIndex) {
1022
- menuWidget.trigger(menuIndex - this.numMenusShown);
1023
- } else {
1024
- menuWidget.focus(selectFirst);
1025
- }
1026
-
1027
- this.focusedMenu = {
1028
- index: actualMenuIndex,
1029
- holder: menuHolder,
1030
- widget: menuWidget
1031
- };
1032
- }
1033
-
1034
- }
1035
-
1036
- exports.MenuBar = MenuBar;
1037
- MenuBar.OVERFLOW_INDEX = -1;
1038
-
1039
- class ModifierKeyEmitter extends event_2.Emitter {
1040
- constructor() {
1041
- super();
1042
- this._subscriptions = new lifecycle_1.DisposableStore();
1043
- this._keyStatus = {
1044
- altKey: false,
1045
- shiftKey: false,
1046
- ctrlKey: false
1047
- };
1048
-
1049
- this._subscriptions.add(event_1.domEvent(document.body, 'keydown', true)(e => {
1050
- const event = new keyboardEvent_1.StandardKeyboardEvent(e);
1051
-
1052
- if (e.altKey && !this._keyStatus.altKey) {
1053
- this._keyStatus.lastKeyPressed = 'alt';
1054
- } else if (e.ctrlKey && !this._keyStatus.ctrlKey) {
1055
- this._keyStatus.lastKeyPressed = 'ctrl';
1056
- } else if (e.shiftKey && !this._keyStatus.shiftKey) {
1057
- this._keyStatus.lastKeyPressed = 'shift';
1058
- } else if (event.keyCode !== 6
1059
- /* Alt */
1060
- ) {
1061
- this._keyStatus.lastKeyPressed = undefined;
1062
- } else {
1063
- return;
1064
- }
1065
-
1066
- this._keyStatus.altKey = e.altKey;
1067
- this._keyStatus.ctrlKey = e.ctrlKey;
1068
- this._keyStatus.shiftKey = e.shiftKey;
1069
-
1070
- if (this._keyStatus.lastKeyPressed) {
1071
- this._keyStatus.event = e;
1072
- this.fire(this._keyStatus);
1073
- }
1074
- }));
1075
-
1076
- this._subscriptions.add(event_1.domEvent(document.body, 'keyup', true)(e => {
1077
- if (!e.altKey && this._keyStatus.altKey) {
1078
- this._keyStatus.lastKeyReleased = 'alt';
1079
- } else if (!e.ctrlKey && this._keyStatus.ctrlKey) {
1080
- this._keyStatus.lastKeyReleased = 'ctrl';
1081
- } else if (!e.shiftKey && this._keyStatus.shiftKey) {
1082
- this._keyStatus.lastKeyReleased = 'shift';
1083
- } else {
1084
- this._keyStatus.lastKeyReleased = undefined;
1085
- }
1086
-
1087
- if (this._keyStatus.lastKeyPressed !== this._keyStatus.lastKeyReleased) {
1088
- this._keyStatus.lastKeyPressed = undefined;
1089
- }
1090
-
1091
- this._keyStatus.altKey = e.altKey;
1092
- this._keyStatus.ctrlKey = e.ctrlKey;
1093
- this._keyStatus.shiftKey = e.shiftKey;
1094
-
1095
- if (this._keyStatus.lastKeyReleased) {
1096
- this._keyStatus.event = e;
1097
- this.fire(this._keyStatus);
1098
- }
1099
- }));
1100
-
1101
- this._subscriptions.add(event_1.domEvent(document.body, 'mousedown', true)(e => {
1102
- this._keyStatus.lastKeyPressed = undefined;
1103
- }));
1104
-
1105
- this._subscriptions.add(event_1.domEvent(document.body, 'mouseup', true)(e => {
1106
- this._keyStatus.lastKeyPressed = undefined;
1107
- }));
1108
-
1109
- this._subscriptions.add(event_1.domEvent(document.body, 'mousemove', true)(e => {
1110
- if (e.buttons) {
1111
- this._keyStatus.lastKeyPressed = undefined;
1112
- }
1113
- }));
1114
-
1115
- this._subscriptions.add(event_1.domEvent(window, 'blur')(e => {
1116
- this._keyStatus.lastKeyPressed = undefined;
1117
- this._keyStatus.lastKeyReleased = undefined;
1118
- this._keyStatus.altKey = false;
1119
- this._keyStatus.shiftKey = false;
1120
- this._keyStatus.shiftKey = false;
1121
- this.fire(this._keyStatus);
1122
- }));
1123
- }
1124
-
1125
- static getInstance() {
1126
- if (!ModifierKeyEmitter.instance) {
1127
- ModifierKeyEmitter.instance = new ModifierKeyEmitter();
1128
- }
1129
-
1130
- return ModifierKeyEmitter.instance;
1131
- }
1132
-
1133
- dispose() {
1134
- super.dispose();
1135
-
1136
- this._subscriptions.dispose();
1137
- }
1138
-
1139
- }