custom-electron-titlebar 3.2.5 → 3.2.9
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/.vscode/launch.json +49 -0
- package/.vscode/tasks.json +34 -0
- package/README.md +15 -24
- package/_config.yml +1 -0
- package/{lib → build}/browser/browser.d.ts +0 -0
- package/{lib → build}/browser/browser.js +1 -0
- package/build/browser/browser.js.map +1 -0
- package/{lib → build}/browser/event.d.ts +0 -0
- package/{lib → build}/browser/event.js +3 -1
- package/build/browser/event.js.map +1 -0
- package/{lib → build}/browser/iframe.d.ts +0 -0
- package/{lib/base → build}/browser/iframe.js +1 -0
- package/build/browser/iframe.js.map +1 -0
- package/{lib → build}/browser/keyboardEvent.d.ts +0 -0
- package/{lib → build}/browser/keyboardEvent.js +1 -0
- package/build/browser/keyboardEvent.js.map +1 -0
- package/{lib → build}/browser/mouseEvent.d.ts +0 -0
- package/{lib → build}/browser/mouseEvent.js +1 -0
- package/build/browser/mouseEvent.js.map +1 -0
- package/{lib → build}/common/arrays.d.ts +0 -0
- package/{lib → build}/common/arrays.js +1 -0
- package/build/common/arrays.js.map +1 -0
- package/{lib → build}/common/async.d.ts +0 -0
- package/{lib → build}/common/async.js +1 -0
- package/build/common/async.js.map +1 -0
- package/{lib → build}/common/charCode.d.ts +0 -0
- package/{lib/base → build}/common/charCode.js +1 -0
- package/build/common/charCode.js.map +1 -0
- package/{lib → build}/common/color.d.ts +0 -0
- package/{lib → build}/common/color.js +1 -0
- package/build/common/color.js.map +1 -0
- package/{lib → build}/common/dom.d.ts +0 -0
- package/{lib → build}/common/dom.js +17 -14
- package/build/common/dom.js.map +1 -0
- package/{lib → build}/common/event.d.ts +0 -0
- package/{lib → build}/common/event.js +2 -1
- package/build/common/event.js.map +1 -0
- package/{lib → build}/common/iterator.d.ts +0 -0
- package/{lib → build}/common/iterator.js +1 -0
- package/build/common/iterator.js.map +1 -0
- package/{lib → build}/common/keyCodes.d.ts +0 -0
- package/{lib → build}/common/keyCodes.js +1 -0
- package/build/common/keyCodes.js.map +1 -0
- package/{lib → build}/common/lifecycle.d.ts +0 -0
- package/{lib → build}/common/lifecycle.js +1 -0
- package/build/common/lifecycle.js.map +1 -0
- package/{lib → build}/common/linkedList.d.ts +0 -0
- package/{lib → build}/common/linkedList.js +1 -0
- package/build/common/linkedList.js.map +1 -0
- package/{lib → build}/common/platform.d.ts +0 -0
- package/{lib → build}/common/platform.js +1 -0
- package/build/common/platform.js.map +1 -0
- package/{lib → build}/index.d.ts +0 -0
- package/{lib → build}/index.js +1 -0
- package/build/index.js.map +1 -0
- package/{lib → build}/menu/menu.d.ts +0 -0
- package/{lib → build}/menu/menu.js +39 -38
- package/build/menu/menu.js.map +1 -0
- package/{lib → build}/menu/menuitem.d.ts +10 -2
- package/{lib → build}/menu/menuitem.js +71 -29
- package/build/menu/menuitem.js.map +1 -0
- package/{lib → build}/menubar.d.ts +0 -0
- package/{lib → build}/menubar.js +38 -34
- package/build/menubar.js.map +1 -0
- package/{lib → build}/themebar.d.ts +0 -0
- package/{lib → build}/themebar.js +31 -2
- package/build/themebar.js.map +1 -0
- package/{lib → build}/titlebar.d.ts +0 -0
- package/{lib → build}/titlebar.js +72 -59
- package/build/titlebar.js.map +1 -0
- package/package.json +13 -7
- package/lib/base/browser/browser.d.ts +0 -25
- package/lib/base/browser/browser.js +0 -117
- package/lib/base/browser/canIUse.d.ts +0 -18
- package/lib/base/browser/canIUse.js +0 -63
- package/lib/base/browser/dom.d.ts +0 -230
- package/lib/base/browser/dom.js +0 -1080
- package/lib/base/browser/event.d.ts +0 -12
- package/lib/base/browser/event.js +0 -28
- package/lib/base/browser/iframe.d.ts +0 -33
- package/lib/base/browser/keyboardEvent.d.ts +0 -40
- package/lib/base/browser/keyboardEvent.js +0 -256
- package/lib/base/browser/mouseEvent.d.ts +0 -69
- package/lib/base/browser/mouseEvent.js +0 -146
- package/lib/base/common/arrays.d.ts +0 -149
- package/lib/base/common/arrays.js +0 -549
- package/lib/base/common/async.d.ts +0 -259
- package/lib/base/common/async.js +0 -728
- package/lib/base/common/cancellation.d.ts +0 -29
- package/lib/base/common/cancellation.js +0 -114
- package/lib/base/common/charCode.d.ts +0 -415
- package/lib/base/common/color.d.ts +0 -163
- package/lib/base/common/color.js +0 -495
- package/lib/base/common/errors.d.ts +0 -65
- package/lib/base/common/errors.js +0 -164
- package/lib/base/common/event.d.ts +0 -248
- package/lib/base/common/event.js +0 -703
- package/lib/base/common/functional.d.ts +0 -1
- package/lib/base/common/functional.js +0 -21
- package/lib/base/common/iterator.d.ts +0 -16
- package/lib/base/common/iterator.js +0 -82
- package/lib/base/common/keyCodes.d.ts +0 -268
- package/lib/base/common/keyCodes.js +0 -292
- package/lib/base/common/lifecycle.d.ts +0 -67
- package/lib/base/common/lifecycle.js +0 -234
- package/lib/base/common/linkedList.d.ts +0 -16
- package/lib/base/common/linkedList.js +0 -128
- package/lib/base/common/network.d.ts +0 -65
- package/lib/base/common/network.js +0 -124
- package/lib/base/common/path.d.ts +0 -39
- package/lib/base/common/path.js +0 -1407
- package/lib/base/common/platform.d.ts +0 -53
- package/lib/base/common/platform.js +0 -176
- package/lib/base/common/process.d.ts +0 -5
- package/lib/base/common/process.js +0 -18
- package/lib/base/common/sequence.d.ts +0 -27
- package/lib/base/common/sequence.js +0 -32
- package/lib/base/common/uri.d.ts +0 -153
- package/lib/base/common/uri.js +0 -612
- package/lib/browser/iframe.js +0 -109
- package/lib/common/charCode.js +0 -6
- package/lib/menu.d.ts +0 -53
- package/lib/menu.js +0 -532
- package/lib/menuitem.d.ts +0 -46
- package/lib/menuitem.js +0 -295
- package/lib/vs/base/browser/browser.d.ts +0 -25
- package/lib/vs/base/browser/browser.js +0 -117
- package/lib/vs/base/browser/canIUse.d.ts +0 -18
- package/lib/vs/base/browser/canIUse.js +0 -63
- package/lib/vs/base/browser/dom.d.ts +0 -230
- package/lib/vs/base/browser/dom.js +0 -1080
- package/lib/vs/base/browser/event.d.ts +0 -12
- package/lib/vs/base/browser/event.js +0 -28
- package/lib/vs/base/browser/iframe.d.ts +0 -33
- package/lib/vs/base/browser/iframe.js +0 -109
- package/lib/vs/base/browser/keyboardEvent.d.ts +0 -40
- package/lib/vs/base/browser/keyboardEvent.js +0 -256
- package/lib/vs/base/browser/mouseEvent.d.ts +0 -69
- package/lib/vs/base/browser/mouseEvent.js +0 -146
- package/lib/vs/base/common/arrays.d.ts +0 -149
- package/lib/vs/base/common/arrays.js +0 -549
- package/lib/vs/base/common/async.d.ts +0 -259
- package/lib/vs/base/common/async.js +0 -728
- package/lib/vs/base/common/cancellation.d.ts +0 -29
- package/lib/vs/base/common/cancellation.js +0 -114
- package/lib/vs/base/common/charCode.d.ts +0 -415
- package/lib/vs/base/common/charCode.js +0 -6
- package/lib/vs/base/common/color.d.ts +0 -163
- package/lib/vs/base/common/color.js +0 -495
- package/lib/vs/base/common/errors.d.ts +0 -65
- package/lib/vs/base/common/errors.js +0 -164
- package/lib/vs/base/common/event.d.ts +0 -248
- package/lib/vs/base/common/event.js +0 -703
- package/lib/vs/base/common/functional.d.ts +0 -1
- package/lib/vs/base/common/functional.js +0 -21
- package/lib/vs/base/common/iterator.d.ts +0 -16
- package/lib/vs/base/common/iterator.js +0 -82
- package/lib/vs/base/common/keyCodes.d.ts +0 -268
- package/lib/vs/base/common/keyCodes.js +0 -292
- package/lib/vs/base/common/lifecycle.d.ts +0 -67
- package/lib/vs/base/common/lifecycle.js +0 -234
- package/lib/vs/base/common/linkedList.d.ts +0 -16
- package/lib/vs/base/common/linkedList.js +0 -128
- package/lib/vs/base/common/network.d.ts +0 -65
- package/lib/vs/base/common/network.js +0 -124
- package/lib/vs/base/common/path.d.ts +0 -39
- package/lib/vs/base/common/path.js +0 -1407
- package/lib/vs/base/common/platform.d.ts +0 -53
- package/lib/vs/base/common/platform.js +0 -176
- package/lib/vs/base/common/process.d.ts +0 -5
- package/lib/vs/base/common/process.js +0 -18
- package/lib/vs/base/common/sequence.d.ts +0 -27
- package/lib/vs/base/common/sequence.js +0 -32
- package/lib/vs/base/common/uri.d.ts +0 -153
- package/lib/vs/base/common/uri.js +0 -612
package/lib/menu.js
DELETED
|
@@ -1,532 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*--------------------------------------------------------------------------------------------------------
|
|
3
|
-
* This file has been modified by @AlexTorresSk (http://github.com/AlexTorresSk)
|
|
4
|
-
* to work in custom-electron-titlebar.
|
|
5
|
-
*
|
|
6
|
-
* The original copy of this file and its respective license are in https://github.com/Microsoft/vscode/
|
|
7
|
-
*
|
|
8
|
-
* Copyright (c) 2018 Alex Torres
|
|
9
|
-
* Licensed under the MIT License. See License in the project root for license information.
|
|
10
|
-
*-------------------------------------------------------------------------------------------------------*/
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.cleanMnemonic = exports.CETMenu = exports.MENU_ESCAPED_MNEMONIC_REGEX = exports.MENU_MNEMONIC_REGEX = void 0;
|
|
13
|
-
const dom_1 = require("./base/browser/dom");
|
|
14
|
-
const keyCodes_1 = require("./base/common/keyCodes");
|
|
15
|
-
const platform_1 = require("./base/common/platform");
|
|
16
|
-
const keyboardEvent_1 = require("./base/browser/keyboardEvent");
|
|
17
|
-
const menuitem_1 = require("./menuitem");
|
|
18
|
-
const lifecycle_1 = require("./base/common/lifecycle");
|
|
19
|
-
const event_1 = require("./base/common/event");
|
|
20
|
-
const async_1 = require("./base/common/async");
|
|
21
|
-
exports.MENU_MNEMONIC_REGEX = /\(&([^\s&])\)|(^|[^&])&([^\s&])/;
|
|
22
|
-
exports.MENU_ESCAPED_MNEMONIC_REGEX = /(&)?(&)([^\s&])/g;
|
|
23
|
-
class CETMenu extends lifecycle_1.Disposable {
|
|
24
|
-
constructor(container, options = {}, closeSubMenu = () => {
|
|
25
|
-
}) {
|
|
26
|
-
super();
|
|
27
|
-
this.triggerKeys = {
|
|
28
|
-
keys: [3 /* Enter */, 10 /* Space */],
|
|
29
|
-
keyDown: true
|
|
30
|
-
};
|
|
31
|
-
this.parentData = {
|
|
32
|
-
parent: this
|
|
33
|
-
};
|
|
34
|
-
this._onDidCancel = this._register(new event_1.Emitter());
|
|
35
|
-
this.menuContainer = container;
|
|
36
|
-
this.options = options;
|
|
37
|
-
this.closeSubMenu = closeSubMenu;
|
|
38
|
-
this.items = [];
|
|
39
|
-
this.focusedItem = undefined;
|
|
40
|
-
this.mnemonics = new Map();
|
|
41
|
-
this._register(dom_1.addDisposableListener(this.menuContainer, dom_1.EventType.KEY_DOWN, e => {
|
|
42
|
-
const event = new keyboardEvent_1.StandardKeyboardEvent(e);
|
|
43
|
-
let eventHandled = true;
|
|
44
|
-
if (event.equals(16 /* UpArrow */)) {
|
|
45
|
-
this.focusPrevious();
|
|
46
|
-
}
|
|
47
|
-
else if (event.equals(18 /* DownArrow */)) {
|
|
48
|
-
this.focusNext();
|
|
49
|
-
}
|
|
50
|
-
else if (event.equals(9 /* Escape */)) {
|
|
51
|
-
this.cancel();
|
|
52
|
-
}
|
|
53
|
-
else if (this.isTriggerKeyEvent(event)) {
|
|
54
|
-
// Staying out of the else branch even if not triggered
|
|
55
|
-
if (this.triggerKeys && this.triggerKeys.keyDown) {
|
|
56
|
-
this.doTrigger(event);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
eventHandled = false;
|
|
61
|
-
}
|
|
62
|
-
if (eventHandled) {
|
|
63
|
-
event.preventDefault();
|
|
64
|
-
event.stopPropagation();
|
|
65
|
-
}
|
|
66
|
-
}));
|
|
67
|
-
this._register(dom_1.addDisposableListener(this.menuContainer, dom_1.EventType.KEY_UP, e => {
|
|
68
|
-
const event = new keyboardEvent_1.StandardKeyboardEvent(e);
|
|
69
|
-
// Run action on Enter/Space
|
|
70
|
-
if (this.isTriggerKeyEvent(event)) {
|
|
71
|
-
if (this.triggerKeys && !this.triggerKeys.keyDown) {
|
|
72
|
-
this.doTrigger(event);
|
|
73
|
-
}
|
|
74
|
-
event.preventDefault();
|
|
75
|
-
event.stopPropagation();
|
|
76
|
-
}
|
|
77
|
-
// Recompute focused item
|
|
78
|
-
else if (event.equals(2 /* Tab */) || event.equals(1024 /* Shift */ | 2 /* Tab */)) {
|
|
79
|
-
this.updateFocusedItem();
|
|
80
|
-
}
|
|
81
|
-
}));
|
|
82
|
-
if (options.enableMnemonics) {
|
|
83
|
-
this._register(dom_1.addDisposableListener(this.menuContainer, dom_1.EventType.KEY_DOWN, (e) => {
|
|
84
|
-
const key = keyCodes_1.KeyCodeUtils.fromString(e.key);
|
|
85
|
-
if (this.mnemonics.has(key)) {
|
|
86
|
-
const items = this.mnemonics.get(key);
|
|
87
|
-
if (items.length === 1) {
|
|
88
|
-
if (items[0] instanceof Submenu) {
|
|
89
|
-
this.focusItemByElement(items[0].getContainer());
|
|
90
|
-
}
|
|
91
|
-
items[0].onClick(e);
|
|
92
|
-
}
|
|
93
|
-
if (items.length > 1) {
|
|
94
|
-
const item = items.shift();
|
|
95
|
-
if (item) {
|
|
96
|
-
this.focusItemByElement(item.getContainer());
|
|
97
|
-
items.push(item);
|
|
98
|
-
}
|
|
99
|
-
this.mnemonics.set(key, items);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}));
|
|
103
|
-
}
|
|
104
|
-
if (platform_1.isLinux) {
|
|
105
|
-
this._register(dom_1.addDisposableListener(this.menuContainer, dom_1.EventType.KEY_DOWN, e => {
|
|
106
|
-
const event = new keyboardEvent_1.StandardKeyboardEvent(e);
|
|
107
|
-
if (event.equals(14 /* Home */) || event.equals(11 /* PageUp */)) {
|
|
108
|
-
this.focusedItem = this.items.length - 1;
|
|
109
|
-
this.focusNext();
|
|
110
|
-
dom_1.EventHelper.stop(e, true);
|
|
111
|
-
}
|
|
112
|
-
else if (event.equals(13 /* End */) || event.equals(12 /* PageDown */)) {
|
|
113
|
-
this.focusedItem = 0;
|
|
114
|
-
this.focusPrevious();
|
|
115
|
-
dom_1.EventHelper.stop(e, true);
|
|
116
|
-
}
|
|
117
|
-
}));
|
|
118
|
-
}
|
|
119
|
-
this._register(dom_1.addDisposableListener(this.menuContainer, dom_1.EventType.MOUSE_OUT, e => {
|
|
120
|
-
let relatedTarget = e.relatedTarget;
|
|
121
|
-
if (!dom_1.isAncestor(relatedTarget, this.menuContainer)) {
|
|
122
|
-
this.focusedItem = undefined;
|
|
123
|
-
this.updateFocus();
|
|
124
|
-
e.stopPropagation();
|
|
125
|
-
}
|
|
126
|
-
}));
|
|
127
|
-
this._register(dom_1.addDisposableListener(this.menuContainer, dom_1.EventType.MOUSE_UP, e => {
|
|
128
|
-
// Absorb clicks in menu dead space https://github.com/Microsoft/vscode/issues/63575
|
|
129
|
-
dom_1.EventHelper.stop(e, true);
|
|
130
|
-
}));
|
|
131
|
-
this._register(dom_1.addDisposableListener(this.menuContainer, dom_1.EventType.MOUSE_OVER, e => {
|
|
132
|
-
let target = e.target;
|
|
133
|
-
if (!target || !dom_1.isAncestor(target, this.menuContainer) || target === this.menuContainer) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
while (target.parentElement !== this.menuContainer && target.parentElement !== null) {
|
|
137
|
-
target = target.parentElement;
|
|
138
|
-
}
|
|
139
|
-
if (target.classList.contains('action-item')) {
|
|
140
|
-
const lastFocusedItem = this.focusedItem;
|
|
141
|
-
this.setFocusedItem(target);
|
|
142
|
-
if (lastFocusedItem !== this.focusedItem) {
|
|
143
|
-
this.updateFocus();
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}));
|
|
147
|
-
if (this.options.ariaLabel) {
|
|
148
|
-
this.menuContainer.setAttribute('aria-label', this.options.ariaLabel);
|
|
149
|
-
}
|
|
150
|
-
//container.style.maxHeight = `${Math.max(10, window.innerHeight - container.getBoundingClientRect().top - 70)}px`;
|
|
151
|
-
}
|
|
152
|
-
get onDidCancel() {
|
|
153
|
-
return this._onDidCancel.event;
|
|
154
|
-
}
|
|
155
|
-
/*setAriaLabel(label: string): void {
|
|
156
|
-
if (label) {
|
|
157
|
-
this.menuContainer.setAttribute('aria-label', label);
|
|
158
|
-
} else {
|
|
159
|
-
this.menuContainer.removeAttribute('aria-label');
|
|
160
|
-
}
|
|
161
|
-
}*/
|
|
162
|
-
isTriggerKeyEvent(event) {
|
|
163
|
-
let ret = false;
|
|
164
|
-
if (this.triggerKeys) {
|
|
165
|
-
this.triggerKeys.keys.forEach(keyCode => {
|
|
166
|
-
ret = ret || event.equals(keyCode);
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
return ret;
|
|
170
|
-
}
|
|
171
|
-
updateFocusedItem() {
|
|
172
|
-
for (let i = 0; i < this.menuContainer.children.length; i++) {
|
|
173
|
-
const elem = this.menuContainer.children[i];
|
|
174
|
-
if (dom_1.isAncestor(document.activeElement, elem)) {
|
|
175
|
-
this.focusedItem = i;
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
getContainer() {
|
|
181
|
-
return this.menuContainer;
|
|
182
|
-
}
|
|
183
|
-
createMenu(items) {
|
|
184
|
-
items.forEach((menuItem) => {
|
|
185
|
-
const itemElement = document.createElement('li');
|
|
186
|
-
itemElement.className = 'action-item';
|
|
187
|
-
itemElement.setAttribute('role', 'presentation');
|
|
188
|
-
// Prevent native context menu on actions
|
|
189
|
-
this._register(dom_1.addDisposableListener(itemElement, dom_1.EventType.CONTEXT_MENU, (e) => {
|
|
190
|
-
e.preventDefault();
|
|
191
|
-
e.stopPropagation();
|
|
192
|
-
}));
|
|
193
|
-
let item;
|
|
194
|
-
if (menuItem.type === 'separator') {
|
|
195
|
-
item = new Separator(menuItem, this.options);
|
|
196
|
-
}
|
|
197
|
-
else if (menuItem.type === 'submenu' || menuItem.submenu) {
|
|
198
|
-
const submenuItems = menuItem.submenu.items;
|
|
199
|
-
item = new Submenu(menuItem, submenuItems, this.parentData, this.options);
|
|
200
|
-
this.setMnemonics(item);
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
const menuItemOptions = { enableMnemonics: this.options.enableMnemonics };
|
|
204
|
-
item = new menuitem_1.CETMenuItem(menuItem, menuItemOptions, this.closeSubMenu);
|
|
205
|
-
this.setMnemonics(item);
|
|
206
|
-
}
|
|
207
|
-
item.render(itemElement);
|
|
208
|
-
this.menuContainer.appendChild(itemElement);
|
|
209
|
-
this.items.push(item);
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
focus(arg) {
|
|
213
|
-
let selectFirst = false;
|
|
214
|
-
let index = undefined;
|
|
215
|
-
if (arg === undefined) {
|
|
216
|
-
selectFirst = true;
|
|
217
|
-
}
|
|
218
|
-
else if (typeof arg === 'number') {
|
|
219
|
-
index = arg;
|
|
220
|
-
}
|
|
221
|
-
else if (typeof arg === 'boolean') {
|
|
222
|
-
selectFirst = arg;
|
|
223
|
-
}
|
|
224
|
-
if (selectFirst && typeof this.focusedItem === 'undefined') {
|
|
225
|
-
// Focus the first enabled item
|
|
226
|
-
this.focusedItem = this.items.length - 1;
|
|
227
|
-
this.focusNext();
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
if (index !== undefined) {
|
|
231
|
-
this.focusedItem = index;
|
|
232
|
-
}
|
|
233
|
-
this.updateFocus();
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
focusNext() {
|
|
237
|
-
if (typeof this.focusedItem === 'undefined') {
|
|
238
|
-
this.focusedItem = this.items.length - 1;
|
|
239
|
-
}
|
|
240
|
-
const startIndex = this.focusedItem;
|
|
241
|
-
let item;
|
|
242
|
-
do {
|
|
243
|
-
this.focusedItem = (this.focusedItem + 1) % this.items.length;
|
|
244
|
-
item = this.items[this.focusedItem];
|
|
245
|
-
} while ((this.focusedItem !== startIndex && !item.isEnabled()) || item.isSeparator());
|
|
246
|
-
if ((this.focusedItem === startIndex && !item.isEnabled()) || item.isSeparator()) {
|
|
247
|
-
this.focusedItem = undefined;
|
|
248
|
-
}
|
|
249
|
-
this.updateFocus();
|
|
250
|
-
}
|
|
251
|
-
focusPrevious() {
|
|
252
|
-
if (typeof this.focusedItem === 'undefined') {
|
|
253
|
-
this.focusedItem = 0;
|
|
254
|
-
}
|
|
255
|
-
const startIndex = this.focusedItem;
|
|
256
|
-
let item;
|
|
257
|
-
do {
|
|
258
|
-
this.focusedItem = this.focusedItem - 1;
|
|
259
|
-
if (this.focusedItem < 0) {
|
|
260
|
-
this.focusedItem = this.items.length - 1;
|
|
261
|
-
}
|
|
262
|
-
item = this.items[this.focusedItem];
|
|
263
|
-
} while ((this.focusedItem !== startIndex && !item.isEnabled()) || item.isSeparator());
|
|
264
|
-
if ((this.focusedItem === startIndex && !item.isEnabled()) || item.isSeparator()) {
|
|
265
|
-
this.focusedItem = undefined;
|
|
266
|
-
}
|
|
267
|
-
this.updateFocus();
|
|
268
|
-
}
|
|
269
|
-
updateFocus() {
|
|
270
|
-
if (typeof this.focusedItem === 'undefined') {
|
|
271
|
-
this.menuContainer.focus();
|
|
272
|
-
}
|
|
273
|
-
for (let i = 0; i < this.items.length; i++) {
|
|
274
|
-
const item = this.items[i];
|
|
275
|
-
if (i === this.focusedItem) {
|
|
276
|
-
if (item.isEnabled()) {
|
|
277
|
-
item.focus();
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
this.menuContainer.focus();
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
item.blur();
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
doTrigger(event) {
|
|
289
|
-
if (typeof this.focusedItem === 'undefined') {
|
|
290
|
-
return; //nothing to focus
|
|
291
|
-
}
|
|
292
|
-
// trigger action
|
|
293
|
-
const item = this.items[this.focusedItem];
|
|
294
|
-
if (item instanceof menuitem_1.CETMenuItem) {
|
|
295
|
-
item.onClick(event);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
cancel() {
|
|
299
|
-
if (document.activeElement instanceof HTMLElement) {
|
|
300
|
-
document.activeElement.blur(); // remove focus from focused action
|
|
301
|
-
}
|
|
302
|
-
this._onDidCancel.fire();
|
|
303
|
-
}
|
|
304
|
-
dispose() {
|
|
305
|
-
lifecycle_1.dispose(this.items);
|
|
306
|
-
this.items = [];
|
|
307
|
-
this.getContainer().remove();
|
|
308
|
-
super.dispose();
|
|
309
|
-
}
|
|
310
|
-
style(style) {
|
|
311
|
-
const container = this.getContainer();
|
|
312
|
-
container.style.backgroundColor = style.backgroundColor ? style.backgroundColor.toString() : null;
|
|
313
|
-
if (this.items) {
|
|
314
|
-
this.items.forEach(item => {
|
|
315
|
-
if (item instanceof menuitem_1.CETMenuItem || item instanceof Separator) {
|
|
316
|
-
item.style(style);
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
focusItemByElement(element) {
|
|
322
|
-
const lastFocusedItem = this.focusedItem;
|
|
323
|
-
this.setFocusedItem(element);
|
|
324
|
-
if (lastFocusedItem !== this.focusedItem) {
|
|
325
|
-
this.updateFocus();
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
setFocusedItem(element) {
|
|
329
|
-
for (let i = 0; i < this.menuContainer.children.length; i++) {
|
|
330
|
-
let elem = this.menuContainer.children[i];
|
|
331
|
-
if (element === elem) {
|
|
332
|
-
this.focusedItem = i;
|
|
333
|
-
break;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
setMnemonics(item) {
|
|
338
|
-
if (this.options.enableMnemonics) {
|
|
339
|
-
const mnemonic = item.getMnemonic();
|
|
340
|
-
if (mnemonic && item.isEnabled()) {
|
|
341
|
-
let actionItems = [];
|
|
342
|
-
if (this.mnemonics.has(mnemonic)) {
|
|
343
|
-
actionItems = this.mnemonics.get(mnemonic);
|
|
344
|
-
}
|
|
345
|
-
actionItems.push(item);
|
|
346
|
-
this.mnemonics.set(mnemonic, actionItems);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
exports.CETMenu = CETMenu;
|
|
352
|
-
class Submenu extends menuitem_1.CETMenuItem {
|
|
353
|
-
constructor(item, submenuItems, parentData, submenuOptions) {
|
|
354
|
-
super(item, submenuOptions);
|
|
355
|
-
this.submenuItems = submenuItems;
|
|
356
|
-
this.parentData = parentData;
|
|
357
|
-
this.submenuOptions = submenuOptions;
|
|
358
|
-
this.submenuDisposables = [];
|
|
359
|
-
this.showScheduler = new async_1.RunOnceScheduler(() => {
|
|
360
|
-
if (this.mouseOver) {
|
|
361
|
-
this.cleanupExistingSubmenu(false);
|
|
362
|
-
this.createSubmenu(false);
|
|
363
|
-
}
|
|
364
|
-
}, 250);
|
|
365
|
-
this.hideScheduler = new async_1.RunOnceScheduler(() => {
|
|
366
|
-
if (this.container && (!dom_1.isAncestor(document.activeElement, this.container) && this.parentData.submenu === this.submenu)) {
|
|
367
|
-
this.parentData.parent.focus(false);
|
|
368
|
-
this.cleanupExistingSubmenu(true);
|
|
369
|
-
}
|
|
370
|
-
}, 750);
|
|
371
|
-
}
|
|
372
|
-
render(container) {
|
|
373
|
-
super.render(container);
|
|
374
|
-
if (!this.itemElement) {
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
377
|
-
this.itemElement.classList.add('submenu-item');
|
|
378
|
-
this.itemElement.setAttribute('aria-haspopup', 'true');
|
|
379
|
-
this.submenuIndicator = dom_1.append(this.itemElement, dom_1.$('span.submenu-indicator'));
|
|
380
|
-
this.submenuIndicator.setAttribute('aria-hidden', 'true');
|
|
381
|
-
this._register(dom_1.addDisposableListener(this.container, dom_1.EventType.KEY_UP, e => {
|
|
382
|
-
let event = new keyboardEvent_1.StandardKeyboardEvent(e);
|
|
383
|
-
if (event.equals(17 /* RightArrow */) || event.equals(3 /* Enter */)) {
|
|
384
|
-
dom_1.EventHelper.stop(e, true);
|
|
385
|
-
this.createSubmenu(true);
|
|
386
|
-
}
|
|
387
|
-
}));
|
|
388
|
-
this._register(dom_1.addDisposableListener(this.container, dom_1.EventType.KEY_DOWN, e => {
|
|
389
|
-
let event = new keyboardEvent_1.StandardKeyboardEvent(e);
|
|
390
|
-
if (event.equals(17 /* RightArrow */) || event.equals(3 /* Enter */)) {
|
|
391
|
-
dom_1.EventHelper.stop(e, true);
|
|
392
|
-
}
|
|
393
|
-
}));
|
|
394
|
-
this._register(dom_1.addDisposableListener(this.container, dom_1.EventType.MOUSE_OVER, () => {
|
|
395
|
-
if (!this.mouseOver) {
|
|
396
|
-
this.mouseOver = true;
|
|
397
|
-
this.showScheduler.schedule();
|
|
398
|
-
}
|
|
399
|
-
}));
|
|
400
|
-
this._register(dom_1.addDisposableListener(this.container, dom_1.EventType.MOUSE_LEAVE, () => {
|
|
401
|
-
this.mouseOver = false;
|
|
402
|
-
}));
|
|
403
|
-
this._register(dom_1.addDisposableListener(this.container, dom_1.EventType.FOCUS_OUT, () => {
|
|
404
|
-
if (this.container && !dom_1.isAncestor(document.activeElement, this.container)) {
|
|
405
|
-
this.hideScheduler.schedule();
|
|
406
|
-
}
|
|
407
|
-
}));
|
|
408
|
-
}
|
|
409
|
-
onClick(e) {
|
|
410
|
-
// stop clicking from trying to run an action
|
|
411
|
-
dom_1.EventHelper.stop(e, true);
|
|
412
|
-
this.cleanupExistingSubmenu(false);
|
|
413
|
-
this.createSubmenu(false);
|
|
414
|
-
}
|
|
415
|
-
cleanupExistingSubmenu(force) {
|
|
416
|
-
if (this.parentData.submenu && (force || (this.parentData.submenu !== this.submenu))) {
|
|
417
|
-
this.parentData.submenu.dispose();
|
|
418
|
-
this.parentData.submenu = undefined;
|
|
419
|
-
if (this.submenuContainer) {
|
|
420
|
-
this.submenuContainer = undefined;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
createSubmenu(selectFirstItem = true) {
|
|
425
|
-
if (!this.itemElement) {
|
|
426
|
-
return;
|
|
427
|
-
}
|
|
428
|
-
if (!this.parentData.submenu) {
|
|
429
|
-
this.submenuContainer = dom_1.append(this.container, dom_1.$('ul.submenu'));
|
|
430
|
-
this.submenuContainer.classList.add('menubar-menu-container');
|
|
431
|
-
this.parentData.submenu = new CETMenu(this.submenuContainer, this.submenuOptions);
|
|
432
|
-
this.parentData.submenu.createMenu(this.submenuItems);
|
|
433
|
-
if (this.menuStyle) {
|
|
434
|
-
this.parentData.submenu.style(this.menuStyle);
|
|
435
|
-
}
|
|
436
|
-
const boundingRect = this.container.getBoundingClientRect();
|
|
437
|
-
const childBoundingRect = this.submenuContainer.getBoundingClientRect();
|
|
438
|
-
const computedStyles = getComputedStyle(this.parentData.parent.getContainer());
|
|
439
|
-
const paddingTop = parseFloat(computedStyles.paddingTop || '0') || 0;
|
|
440
|
-
if (window.innerWidth <= boundingRect.right + childBoundingRect.width) {
|
|
441
|
-
this.submenuContainer.style.left = '10px';
|
|
442
|
-
this.submenuContainer.style.top = `${this.container.offsetTop + boundingRect.height}px`;
|
|
443
|
-
}
|
|
444
|
-
else {
|
|
445
|
-
this.submenuContainer.style.left = `${this.container.offsetWidth}px`;
|
|
446
|
-
this.submenuContainer.style.top = `${this.container.offsetTop - paddingTop}px`;
|
|
447
|
-
}
|
|
448
|
-
this.submenuDisposables.push(dom_1.addDisposableListener(this.submenuContainer, dom_1.EventType.KEY_UP, e => {
|
|
449
|
-
let event = new keyboardEvent_1.StandardKeyboardEvent(e);
|
|
450
|
-
if (event.equals(15 /* LeftArrow */)) {
|
|
451
|
-
dom_1.EventHelper.stop(e, true);
|
|
452
|
-
this.parentData.parent.focus();
|
|
453
|
-
if (this.parentData.submenu) {
|
|
454
|
-
this.parentData.submenu.dispose();
|
|
455
|
-
this.parentData.submenu = undefined;
|
|
456
|
-
}
|
|
457
|
-
this.submenuDisposables = lifecycle_1.dispose(this.submenuDisposables);
|
|
458
|
-
this.submenuContainer = undefined;
|
|
459
|
-
}
|
|
460
|
-
}));
|
|
461
|
-
this.submenuDisposables.push(dom_1.addDisposableListener(this.submenuContainer, dom_1.EventType.KEY_DOWN, e => {
|
|
462
|
-
let event = new keyboardEvent_1.StandardKeyboardEvent(e);
|
|
463
|
-
if (event.equals(15 /* LeftArrow */)) {
|
|
464
|
-
dom_1.EventHelper.stop(e, true);
|
|
465
|
-
}
|
|
466
|
-
}));
|
|
467
|
-
this.submenuDisposables.push(this.parentData.submenu.onDidCancel(() => {
|
|
468
|
-
this.parentData.parent.focus();
|
|
469
|
-
if (this.parentData.submenu) {
|
|
470
|
-
this.parentData.submenu.dispose();
|
|
471
|
-
this.parentData.submenu = undefined;
|
|
472
|
-
}
|
|
473
|
-
this.submenuDisposables = lifecycle_1.dispose(this.submenuDisposables);
|
|
474
|
-
this.submenuContainer = undefined;
|
|
475
|
-
}));
|
|
476
|
-
this.parentData.submenu.focus(selectFirstItem);
|
|
477
|
-
this.submenu = this.parentData.submenu;
|
|
478
|
-
}
|
|
479
|
-
else {
|
|
480
|
-
this.parentData.submenu.focus(false);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
applyStyle() {
|
|
484
|
-
super.applyStyle();
|
|
485
|
-
if (!this.menuStyle) {
|
|
486
|
-
return;
|
|
487
|
-
}
|
|
488
|
-
const isSelected = this.container && this.container.classList.contains('focused');
|
|
489
|
-
const fgColor = isSelected && this.menuStyle.selectionForegroundColor ? this.menuStyle.selectionForegroundColor : this.menuStyle.foregroundColor;
|
|
490
|
-
this.submenuIndicator.style.backgroundColor = fgColor ? `${fgColor}` : null;
|
|
491
|
-
if (this.parentData.submenu) {
|
|
492
|
-
this.parentData.submenu.style(this.menuStyle);
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
dispose() {
|
|
496
|
-
super.dispose();
|
|
497
|
-
this.hideScheduler.dispose();
|
|
498
|
-
if (this.submenu) {
|
|
499
|
-
this.submenu.dispose();
|
|
500
|
-
this.submenu = null;
|
|
501
|
-
}
|
|
502
|
-
if (this.submenuContainer) {
|
|
503
|
-
this.submenuDisposables = lifecycle_1.dispose(this.submenuDisposables);
|
|
504
|
-
this.submenuContainer = undefined;
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
class Separator extends menuitem_1.CETMenuItem {
|
|
509
|
-
constructor(item, options) {
|
|
510
|
-
super(item, options);
|
|
511
|
-
}
|
|
512
|
-
render(container) {
|
|
513
|
-
if (container) {
|
|
514
|
-
this.separatorElement = dom_1.append(container, dom_1.$('a.action-label'));
|
|
515
|
-
this.separatorElement.setAttribute('role', 'presentation');
|
|
516
|
-
this.separatorElement.classList.add('separator');
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
style(style) {
|
|
520
|
-
this.separatorElement.style.borderBottomColor = style.separatorColor ? `${style.separatorColor}` : null;
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
function cleanMnemonic(label) {
|
|
524
|
-
const regex = exports.MENU_MNEMONIC_REGEX;
|
|
525
|
-
const matches = regex.exec(label);
|
|
526
|
-
if (!matches) {
|
|
527
|
-
return label;
|
|
528
|
-
}
|
|
529
|
-
const mnemonicInText = !matches[1];
|
|
530
|
-
return label.replace(regex, mnemonicInText ? '$2$3' : '').trim();
|
|
531
|
-
}
|
|
532
|
-
exports.cleanMnemonic = cleanMnemonic;
|
package/lib/menuitem.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { MenuItem } from "electron";
|
|
2
|
-
import { EventLike } from "./base/browser/dom";
|
|
3
|
-
import { KeyCode } from "./base/common/keyCodes";
|
|
4
|
-
import { Disposable } from "./base/common/lifecycle";
|
|
5
|
-
import { IMenuOptions, IMenuStyle } from "./menu";
|
|
6
|
-
export interface IMenuItem {
|
|
7
|
-
render(element: HTMLElement): void;
|
|
8
|
-
isEnabled(): boolean;
|
|
9
|
-
isSeparator(): boolean;
|
|
10
|
-
focus(): void;
|
|
11
|
-
blur(): void;
|
|
12
|
-
dispose(): void;
|
|
13
|
-
}
|
|
14
|
-
export declare class CETMenuItem extends Disposable implements IMenuItem {
|
|
15
|
-
protected options: IMenuOptions;
|
|
16
|
-
protected menuStyle: IMenuStyle;
|
|
17
|
-
protected container: HTMLElement;
|
|
18
|
-
protected itemElement: HTMLElement;
|
|
19
|
-
private readonly item;
|
|
20
|
-
private labelElement;
|
|
21
|
-
private checkElement;
|
|
22
|
-
private iconElement;
|
|
23
|
-
private readonly mnemonic;
|
|
24
|
-
private readonly closeSubMenu;
|
|
25
|
-
private event;
|
|
26
|
-
private readonly currentWindow;
|
|
27
|
-
constructor(item: MenuItem, options?: IMenuOptions, closeSubMenu?: () => void);
|
|
28
|
-
getContainer(): HTMLElement;
|
|
29
|
-
isEnabled(): boolean;
|
|
30
|
-
isSeparator(): boolean;
|
|
31
|
-
render(container: HTMLElement): void;
|
|
32
|
-
onClick(event: EventLike): void;
|
|
33
|
-
focus(): void;
|
|
34
|
-
blur(): void;
|
|
35
|
-
setAccelerator(): void;
|
|
36
|
-
updateLabel(): void;
|
|
37
|
-
updateIcon(): void;
|
|
38
|
-
updateTooltip(): void;
|
|
39
|
-
updateEnabled(): void;
|
|
40
|
-
updateVisibility(): void;
|
|
41
|
-
updateChecked(): void;
|
|
42
|
-
dispose(): void;
|
|
43
|
-
getMnemonic(): KeyCode;
|
|
44
|
-
protected applyStyle(): void;
|
|
45
|
-
style(style: IMenuStyle): void;
|
|
46
|
-
}
|