custom-electron-titlebar 4.2.0 → 4.2.1
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/base/browser/browser.d.ts +26 -0
- package/dist/base/browser/browser.js +317 -0
- package/dist/base/browser/event.d.ts +12 -0
- package/dist/base/browser/event.js +215 -0
- package/dist/base/browser/keyboardEvent.d.ts +38 -0
- package/dist/base/browser/keyboardEvent.js +466 -0
- package/dist/base/browser/mouseEvent.d.ts +61 -0
- package/dist/base/browser/mouseEvent.js +327 -0
- package/dist/base/browser/touch.d.ts +39 -0
- package/dist/base/browser/touch.js +454 -0
- package/dist/base/common/arrays.d.ts +10 -0
- package/dist/base/common/arrays.js +210 -0
- package/dist/base/common/async.d.ts +35 -0
- package/dist/base/common/async.js +280 -0
- package/dist/base/common/charCode.d.ts +405 -0
- package/dist/base/common/charCode.js +9 -0
- package/dist/base/common/color.d.ts +159 -0
- package/dist/base/common/color.js +709 -0
- package/dist/base/common/decorators.d.ts +6 -0
- package/dist/base/common/decorators.js +300 -0
- package/dist/base/common/dom.d.ts +221 -0
- package/dist/base/common/dom.js +1478 -0
- package/dist/base/common/event.d.ts +213 -0
- package/dist/base/common/event.js +804 -0
- package/dist/base/common/iterator.d.ts +69 -0
- package/dist/base/common/iterator.js +381 -0
- package/dist/base/common/keyCodes.d.ts +478 -0
- package/dist/base/common/keyCodes.js +479 -0
- package/dist/base/common/lifecycle.d.ts +17 -0
- package/dist/base/common/lifecycle.js +258 -0
- package/dist/base/common/linkedList.d.ts +17 -0
- package/dist/base/common/linkedList.js +319 -0
- package/dist/base/common/platform.d.ts +33 -0
- package/dist/base/common/platform.js +302 -0
- package/dist/base/common/strings.d.ts +23 -0
- package/dist/base/common/strings.js +273 -0
- package/dist/consts.d.ts +49 -0
- package/dist/consts.js +303 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +211 -0
- package/dist/main/attach-titlebar-to-window.d.ts +3 -0
- package/dist/main/attach-titlebar-to-window.js +207 -0
- package/dist/main/index.d.ts +3 -0
- package/dist/main/index.js +202 -0
- package/dist/main/setup-titlebar.d.ts +2 -0
- package/dist/main/setup-titlebar.js +242 -0
- package/dist/menubar/index.d.ts +86 -0
- package/dist/menubar/index.js +1118 -0
- package/dist/menubar/menu/index.d.ts +46 -0
- package/dist/menubar/menu/index.js +556 -0
- package/dist/menubar/menu/item.d.ts +67 -0
- package/dist/menubar/menu/item.js +575 -0
- package/dist/menubar/menu/separator.d.ts +11 -0
- package/dist/menubar/menu/separator.js +213 -0
- package/dist/menubar/menu/submenu.d.ts +32 -0
- package/dist/menubar/menu/submenu.js +372 -0
- package/dist/menubar/menubar-options.d.ts +55 -0
- package/dist/menubar/menubar-options.js +9 -0
- package/dist/titlebar/index.d.ts +99 -0
- package/dist/titlebar/index.js +663 -0
- package/dist/titlebar/options.d.ts +84 -0
- package/dist/titlebar/options.js +9 -0
- package/dist/titlebar/themebar.d.ts +20 -0
- package/dist/titlebar/themebar.js +267 -0
- package/package.json +1 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { MenuItem } from 'electron';
|
|
2
|
+
import { Disposable } from '../../base/common/lifecycle';
|
|
3
|
+
import { IMenuStyle } from './item';
|
|
4
|
+
import { Event } from '../../base/common/event';
|
|
5
|
+
import { MenuBarOptions } from '../menubar-options';
|
|
6
|
+
import { ISubMenuData } from './submenu';
|
|
7
|
+
import { IMenuIcons } from '../../menubar';
|
|
8
|
+
export declare enum Direction {
|
|
9
|
+
Right = 0,
|
|
10
|
+
Left = 1
|
|
11
|
+
}
|
|
12
|
+
export interface IMenuOptions {
|
|
13
|
+
ariaLabel?: string;
|
|
14
|
+
enableMnemonics?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare class CETMenu extends Disposable {
|
|
17
|
+
private menuContainer;
|
|
18
|
+
private menuIcons;
|
|
19
|
+
private parentOptions;
|
|
20
|
+
private currentOptions;
|
|
21
|
+
private closeSubMenu;
|
|
22
|
+
private focusedItem?;
|
|
23
|
+
private items;
|
|
24
|
+
private mnemonics;
|
|
25
|
+
private triggerKeys;
|
|
26
|
+
parentData: ISubMenuData;
|
|
27
|
+
private _onDidCancel;
|
|
28
|
+
constructor(menuContainer: HTMLElement, menuIcons: IMenuIcons, parentOptions: MenuBarOptions, currentOptions: IMenuOptions, closeSubMenu?: () => void);
|
|
29
|
+
trigger(index: number): void;
|
|
30
|
+
createMenu(menuItems: MenuItem[] | undefined): void;
|
|
31
|
+
private isTriggerKeyEvent;
|
|
32
|
+
private updateFocusedItem;
|
|
33
|
+
focus(index?: number): void;
|
|
34
|
+
focus(selectFirst?: boolean): void;
|
|
35
|
+
private focusNext;
|
|
36
|
+
private focusPrevious;
|
|
37
|
+
private updateFocus;
|
|
38
|
+
private doTrigger;
|
|
39
|
+
private cancel;
|
|
40
|
+
private focusItemByElement;
|
|
41
|
+
private setFocusedItem;
|
|
42
|
+
applyStyle(style: IMenuStyle): void;
|
|
43
|
+
get container(): HTMLElement;
|
|
44
|
+
get onDidCancel(): Event<void>;
|
|
45
|
+
dispose(): void;
|
|
46
|
+
}
|
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/* ---------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright (c) AlexTorresDev. All rights reserved.
|
|
5
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
6
|
+
*-------------------------------------------------------------------------------------------- */
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports.CETMenu = exports.Direction = void 0;
|
|
11
|
+
const dom_1 = require("../../base/common/dom");
|
|
12
|
+
const lifecycle_1 = require("../../base/common/lifecycle");
|
|
13
|
+
const item_1 = require("./item");
|
|
14
|
+
const keyCodes_1 = require("../../base/common/keyCodes");
|
|
15
|
+
const keyboardEvent_1 = require("../../base/browser/keyboardEvent");
|
|
16
|
+
const color_1 = require("../../base/common/color");
|
|
17
|
+
const event_1 = require("../../base/common/event");
|
|
18
|
+
const separator_1 = require("./separator");
|
|
19
|
+
const submenu_1 = require("./submenu");
|
|
20
|
+
const platform_1 = require("../../base/common/platform");
|
|
21
|
+
var Direction;
|
|
22
|
+
(function (Direction) {
|
|
23
|
+
Direction[Direction["Right"] = 0] = "Right";
|
|
24
|
+
Direction[Direction["Left"] = 1] = "Left";
|
|
25
|
+
})(_assign__("Direction", exports.Direction || (exports.Direction = {})));
|
|
26
|
+
class CETMenu extends _get__("lifecycle_1").Disposable {
|
|
27
|
+
constructor(menuContainer, menuIcons, parentOptions, currentOptions, closeSubMenu = () => {}) {
|
|
28
|
+
super();
|
|
29
|
+
this.menuContainer = menuContainer;
|
|
30
|
+
this.menuIcons = menuIcons;
|
|
31
|
+
this.parentOptions = parentOptions;
|
|
32
|
+
this.currentOptions = currentOptions;
|
|
33
|
+
this.closeSubMenu = closeSubMenu;
|
|
34
|
+
this.focusedItem = undefined;
|
|
35
|
+
this.items = [];
|
|
36
|
+
this.triggerKeys = {
|
|
37
|
+
keys: [3 /* KeyCode.Enter */, 10 /* KeyCode.Space */],
|
|
38
|
+
keyDown: true
|
|
39
|
+
};
|
|
40
|
+
this.parentData = {
|
|
41
|
+
parent: this
|
|
42
|
+
};
|
|
43
|
+
this._onDidCancel = this._register(new (_get__("event_1").Emitter)());
|
|
44
|
+
this.mnemonics = new Map();
|
|
45
|
+
this._register((0, _get__("dom_1").addDisposableListener)(this.menuContainer, _get__("dom_1").EventType.KEY_DOWN, e => {
|
|
46
|
+
const event = new (_get__("keyboardEvent_1").StandardKeyboardEvent)(e);
|
|
47
|
+
let eventHandled = true;
|
|
48
|
+
if (event.equals(16 /* KeyCode.UpArrow */)) {
|
|
49
|
+
this.focusPrevious();
|
|
50
|
+
} else if (event.equals(18 /* KeyCode.DownArrow */)) {
|
|
51
|
+
this.focusNext();
|
|
52
|
+
} else if (event.equals(9 /* KeyCode.Escape */)) {
|
|
53
|
+
this.cancel();
|
|
54
|
+
} else if (this.isTriggerKeyEvent(event)) {
|
|
55
|
+
// Staying out of the else branch even if not triggered
|
|
56
|
+
if (this.triggerKeys && this.triggerKeys.keyDown) {
|
|
57
|
+
this.doTrigger(event);
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
eventHandled = false;
|
|
61
|
+
}
|
|
62
|
+
if (eventHandled) {
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
event.stopPropagation();
|
|
65
|
+
}
|
|
66
|
+
}));
|
|
67
|
+
this._register((0, _get__("dom_1").addDisposableListener)(this.menuContainer, _get__("dom_1").EventType.KEY_UP, e => {
|
|
68
|
+
const event = new (_get__("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
|
+
// Recompute focused item
|
|
77
|
+
} else if (event.equals(2 /* KeyCode.Tab */) || event.equals(1024 /* KeyMod.Shift */ | 2 /* KeyCode.Tab */)) {
|
|
78
|
+
this.updateFocusedItem();
|
|
79
|
+
}
|
|
80
|
+
}));
|
|
81
|
+
if (this.currentOptions.enableMnemonics) {
|
|
82
|
+
this._register((0, _get__("dom_1").addDisposableListener)(this.menuContainer, _get__("dom_1").EventType.KEY_DOWN, e => {
|
|
83
|
+
const key = _get__("keyCodes_1").KeyCodeUtils.fromString(e.key);
|
|
84
|
+
if (this.mnemonics.has(key)) {
|
|
85
|
+
const items = this.mnemonics.get(key);
|
|
86
|
+
if (items.length === 1) {
|
|
87
|
+
if (items[0] instanceof _get__("submenu_1").CETSubMenu) {
|
|
88
|
+
this.focusItemByElement(items[0].element);
|
|
89
|
+
}
|
|
90
|
+
items[0].onClick(e);
|
|
91
|
+
}
|
|
92
|
+
if (items.length > 1) {
|
|
93
|
+
const item = items.shift();
|
|
94
|
+
if (item) {
|
|
95
|
+
this.focusItemByElement(item.element);
|
|
96
|
+
items.push(item);
|
|
97
|
+
}
|
|
98
|
+
this.mnemonics.set(key, items);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
if (_get__("platform_1").isLinux) {
|
|
104
|
+
this._register((0, _get__("dom_1").addDisposableListener)(this.menuContainer, _get__("dom_1").EventType.KEY_DOWN, e => {
|
|
105
|
+
const event = new (_get__("keyboardEvent_1").StandardKeyboardEvent)(e);
|
|
106
|
+
if (event.equals(14 /* KeyCode.Home */) || event.equals(11 /* KeyCode.PageUp */)) {
|
|
107
|
+
this.focusedItem = this.items.length - 1;
|
|
108
|
+
this.focusNext();
|
|
109
|
+
_get__("dom_1").EventHelper.stop(e, true);
|
|
110
|
+
} else if (event.equals(13 /* KeyCode.End */) || event.equals(12 /* KeyCode.PageDown */)) {
|
|
111
|
+
this.focusedItem = 0;
|
|
112
|
+
this.focusPrevious();
|
|
113
|
+
_get__("dom_1").EventHelper.stop(e, true);
|
|
114
|
+
}
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
this._register((0, _get__("dom_1").addDisposableListener)(this.menuContainer, _get__("dom_1").EventType.MOUSE_OUT, e => {
|
|
118
|
+
const relatedTarget = e.relatedTarget;
|
|
119
|
+
if (!(0, _get__("dom_1").isAncestor)(relatedTarget, this.menuContainer)) {
|
|
120
|
+
this.focusedItem = undefined;
|
|
121
|
+
this.updateFocus();
|
|
122
|
+
e.stopPropagation();
|
|
123
|
+
}
|
|
124
|
+
}));
|
|
125
|
+
this._register((0, _get__("dom_1").addDisposableListener)(this.menuContainer, _get__("dom_1").EventType.MOUSE_UP, e => {
|
|
126
|
+
// Absorb clicks in menu dead space https://github.com/Microsoft/vscode/issues/63575
|
|
127
|
+
_get__("dom_1").EventHelper.stop(e, true);
|
|
128
|
+
}));
|
|
129
|
+
this._register((0, _get__("dom_1").addDisposableListener)(this.menuContainer, _get__("dom_1").EventType.MOUSE_OVER, e => {
|
|
130
|
+
let target = e.target;
|
|
131
|
+
if (!target || !(0, _get__("dom_1").isAncestor)(target, this.menuContainer) || target === this.menuContainer) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
while (target.parentElement !== this.menuContainer && target.parentElement !== null) {
|
|
135
|
+
target = target.parentElement;
|
|
136
|
+
}
|
|
137
|
+
if ((0, _get__("dom_1").hasClass)(target, 'cet-action-item')) {
|
|
138
|
+
const lastFocusedItem = this.focusedItem;
|
|
139
|
+
this.setFocusedItem(target);
|
|
140
|
+
if (lastFocusedItem !== this.focusedItem) {
|
|
141
|
+
this.updateFocus();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}));
|
|
145
|
+
if (this.currentOptions.ariaLabel) {
|
|
146
|
+
this.menuContainer.setAttribute('aria-label', this.currentOptions.ariaLabel);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
trigger(index) {
|
|
150
|
+
if (index <= this.items.length && index >= 0) {
|
|
151
|
+
const item = this.items[index];
|
|
152
|
+
if (item instanceof _get__("submenu_1").CETSubMenu) {
|
|
153
|
+
this.focus(index);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
createMenu(menuItems) {
|
|
158
|
+
if (!menuItems) return;
|
|
159
|
+
menuItems.forEach(menuItem => {
|
|
160
|
+
if (!menuItem) return;
|
|
161
|
+
const itemElement = (0, _get__("dom_1").$)('li.cet-action-item', {
|
|
162
|
+
role: 'presentation'
|
|
163
|
+
});
|
|
164
|
+
// Prevent native context menu on actions
|
|
165
|
+
this._register((0, _get__("dom_1").addDisposableListener)(itemElement, _get__("dom_1").EventType.CONTEXT_MENU, e => {
|
|
166
|
+
e.preventDefault();
|
|
167
|
+
e.stopPropagation();
|
|
168
|
+
}));
|
|
169
|
+
let item;
|
|
170
|
+
if (menuItem.type === 'separator') {
|
|
171
|
+
item = new (_get__("separator_1").CETSeparator)(menuItem, this.menuIcons, this.parentOptions, this.currentOptions);
|
|
172
|
+
} else if (menuItem.type === 'submenu' || menuItem.submenu) {
|
|
173
|
+
const submenuItems = menuItem.submenu.items;
|
|
174
|
+
item = new (_get__("submenu_1").CETSubMenu)(menuItem, this.menuIcons, submenuItems, this.parentData, this.parentOptions, this.currentOptions, this.closeSubMenu);
|
|
175
|
+
if (this.currentOptions.enableMnemonics) {
|
|
176
|
+
const mnemonic = item.mnemonic;
|
|
177
|
+
if (mnemonic && item.isEnabled()) {
|
|
178
|
+
let actionItems = [];
|
|
179
|
+
if (this.mnemonics.has(mnemonic)) {
|
|
180
|
+
actionItems = this.mnemonics.get(mnemonic);
|
|
181
|
+
}
|
|
182
|
+
actionItems.push(item);
|
|
183
|
+
this.mnemonics.set(mnemonic, actionItems);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
} else {
|
|
187
|
+
item = new (_get__("item_1").CETMenuItem)(menuItem, this.menuIcons, this.parentOptions, this.currentOptions, this.items, this.closeSubMenu);
|
|
188
|
+
if (this.currentOptions.enableMnemonics) {
|
|
189
|
+
const mnemonic = item.mnemonic;
|
|
190
|
+
if (mnemonic && item.isEnabled()) {
|
|
191
|
+
let actionItems = [];
|
|
192
|
+
if (this.mnemonics.has(mnemonic)) {
|
|
193
|
+
actionItems = this.mnemonics.get(mnemonic);
|
|
194
|
+
}
|
|
195
|
+
actionItems.push(item);
|
|
196
|
+
this.mnemonics.set(mnemonic, actionItems);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
item.render(itemElement);
|
|
201
|
+
this.items.push(item);
|
|
202
|
+
(0, _get__("dom_1").append)(this.menuContainer, itemElement);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
isTriggerKeyEvent(event) {
|
|
206
|
+
let ret = false;
|
|
207
|
+
if (this.triggerKeys) {
|
|
208
|
+
this.triggerKeys.keys.forEach(keyCode => {
|
|
209
|
+
ret = ret || event.equals(keyCode);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
return ret;
|
|
213
|
+
}
|
|
214
|
+
updateFocusedItem() {
|
|
215
|
+
for (let i = 0; i < this.menuContainer.children.length; i++) {
|
|
216
|
+
const elem = this.menuContainer.children[i];
|
|
217
|
+
if ((0, _get__("dom_1").isAncestor)(document.activeElement, elem)) {
|
|
218
|
+
this.focusedItem = i;
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
focus(arg) {
|
|
224
|
+
let selectFirst = false;
|
|
225
|
+
let index;
|
|
226
|
+
if (arg === undefined) {
|
|
227
|
+
selectFirst = true;
|
|
228
|
+
} else if (typeof arg === 'number') {
|
|
229
|
+
index = arg;
|
|
230
|
+
} else if (typeof arg === 'boolean') {
|
|
231
|
+
selectFirst = arg;
|
|
232
|
+
}
|
|
233
|
+
if (selectFirst && typeof this.focusedItem === 'undefined') {
|
|
234
|
+
// Focus the first enabled item
|
|
235
|
+
this.focusedItem = this.items.length - 1;
|
|
236
|
+
this.focusNext();
|
|
237
|
+
} else {
|
|
238
|
+
if (index !== undefined) {
|
|
239
|
+
this.focusedItem = index;
|
|
240
|
+
}
|
|
241
|
+
this.updateFocus();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
focusNext() {
|
|
245
|
+
if (typeof this.focusedItem === 'undefined') {
|
|
246
|
+
this.focusedItem = this.items.length - 1;
|
|
247
|
+
}
|
|
248
|
+
const startIndex = this.focusedItem;
|
|
249
|
+
let item;
|
|
250
|
+
do {
|
|
251
|
+
this.focusedItem = (this.focusedItem + 1) % this.items.length;
|
|
252
|
+
item = this.items[this.focusedItem];
|
|
253
|
+
} while (this.focusedItem !== startIndex && !item.isEnabled() || item.isSeparator());
|
|
254
|
+
if (this.focusedItem === startIndex && !item.isEnabled() || item.isSeparator()) {
|
|
255
|
+
this.focusedItem = undefined;
|
|
256
|
+
}
|
|
257
|
+
this.updateFocus();
|
|
258
|
+
}
|
|
259
|
+
focusPrevious() {
|
|
260
|
+
if (typeof this.focusedItem === 'undefined') {
|
|
261
|
+
this.focusedItem = 0;
|
|
262
|
+
}
|
|
263
|
+
const startIndex = this.focusedItem;
|
|
264
|
+
let item;
|
|
265
|
+
do {
|
|
266
|
+
this.focusedItem = this.focusedItem - 1;
|
|
267
|
+
if (this.focusedItem < 0) {
|
|
268
|
+
this.focusedItem = this.items.length - 1;
|
|
269
|
+
}
|
|
270
|
+
item = this.items[this.focusedItem];
|
|
271
|
+
} while (this.focusedItem !== startIndex && !item.isEnabled() || item.isSeparator());
|
|
272
|
+
if (this.focusedItem === startIndex && !item.isEnabled() || item.isSeparator()) {
|
|
273
|
+
this.focusedItem = undefined;
|
|
274
|
+
}
|
|
275
|
+
this.updateFocus();
|
|
276
|
+
}
|
|
277
|
+
updateFocus() {
|
|
278
|
+
if (typeof this.focusedItem === 'undefined') {
|
|
279
|
+
this.menuContainer.focus();
|
|
280
|
+
}
|
|
281
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
282
|
+
const item = this.items[i];
|
|
283
|
+
if (i === this.focusedItem) {
|
|
284
|
+
if (item.isEnabled()) {
|
|
285
|
+
item.focus();
|
|
286
|
+
} else {
|
|
287
|
+
this.menuContainer.focus();
|
|
288
|
+
}
|
|
289
|
+
} else {
|
|
290
|
+
item.blur();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
doTrigger(event) {
|
|
295
|
+
if (typeof this.focusedItem === 'undefined') {
|
|
296
|
+
return; // nothing to focus
|
|
297
|
+
}
|
|
298
|
+
// trigger action
|
|
299
|
+
const item = this.items[this.focusedItem];
|
|
300
|
+
if (item instanceof _get__("item_1").CETMenuItem) {
|
|
301
|
+
item.onClick(event);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
cancel() {
|
|
305
|
+
if (document.activeElement instanceof HTMLElement) {
|
|
306
|
+
document.activeElement.blur(); // remove focus from focused action
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
this._onDidCancel.fire();
|
|
310
|
+
}
|
|
311
|
+
focusItemByElement(element) {
|
|
312
|
+
const lastFocusedItem = this.focusedItem;
|
|
313
|
+
if (element) this.setFocusedItem(element);
|
|
314
|
+
if (lastFocusedItem !== this.focusedItem) {
|
|
315
|
+
this.updateFocus();
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
setFocusedItem(element) {
|
|
319
|
+
this.focusedItem = Array.prototype.findIndex.call(this.container.children, elem => elem === element);
|
|
320
|
+
}
|
|
321
|
+
applyStyle(style) {
|
|
322
|
+
const container = this.menuContainer;
|
|
323
|
+
if (style?.backgroundColor) {
|
|
324
|
+
let transparency = this.parentOptions?.menuTransparency;
|
|
325
|
+
if (transparency < 0) transparency = 0;
|
|
326
|
+
if (transparency > 1) transparency = 1;
|
|
327
|
+
const rgba = style.backgroundColor?.rgba;
|
|
328
|
+
const color = new (_get__("color_1").Color)(new (_get__("color_1").RGBA)(rgba.r, rgba.g, rgba.b, 1 - transparency));
|
|
329
|
+
container.style.backgroundColor = color.toString();
|
|
330
|
+
}
|
|
331
|
+
if (this.items) {
|
|
332
|
+
this.items.forEach(item => {
|
|
333
|
+
if (item instanceof _get__("item_1").CETMenuItem || item instanceof _get__("separator_1").CETSeparator) {
|
|
334
|
+
item.updateStyle(style);
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
get container() {
|
|
340
|
+
return this.menuContainer;
|
|
341
|
+
}
|
|
342
|
+
get onDidCancel() {
|
|
343
|
+
return this._onDidCancel.event;
|
|
344
|
+
}
|
|
345
|
+
dispose() {
|
|
346
|
+
(0, _get__("lifecycle_1").dispose)(this.items);
|
|
347
|
+
this.items = [];
|
|
348
|
+
(0, _get__("dom_1").removeNode)(this.container);
|
|
349
|
+
super.dispose();
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
exports.CETMenu = _get__("CETMenu");
|
|
353
|
+
function _getGlobalObject() {
|
|
354
|
+
try {
|
|
355
|
+
if (!!global) {
|
|
356
|
+
return global;
|
|
357
|
+
}
|
|
358
|
+
} catch (e) {
|
|
359
|
+
try {
|
|
360
|
+
if (!!window) {
|
|
361
|
+
return window;
|
|
362
|
+
}
|
|
363
|
+
} catch (e) {
|
|
364
|
+
return this;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
;
|
|
369
|
+
var _RewireModuleId__ = null;
|
|
370
|
+
function _getRewireModuleId__() {
|
|
371
|
+
if (_RewireModuleId__ === null) {
|
|
372
|
+
let globalVariable = _getGlobalObject();
|
|
373
|
+
if (!globalVariable.__$$GLOBAL_REWIRE_NEXT_MODULE_ID__) {
|
|
374
|
+
globalVariable.__$$GLOBAL_REWIRE_NEXT_MODULE_ID__ = 0;
|
|
375
|
+
}
|
|
376
|
+
_RewireModuleId__ = __$$GLOBAL_REWIRE_NEXT_MODULE_ID__++;
|
|
377
|
+
}
|
|
378
|
+
return _RewireModuleId__;
|
|
379
|
+
}
|
|
380
|
+
function _getRewireRegistry__() {
|
|
381
|
+
let theGlobalVariable = _getGlobalObject();
|
|
382
|
+
if (!theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__) {
|
|
383
|
+
theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__ = Object.create(null);
|
|
384
|
+
}
|
|
385
|
+
return theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__;
|
|
386
|
+
}
|
|
387
|
+
function _getRewiredData__() {
|
|
388
|
+
let moduleId = _getRewireModuleId__();
|
|
389
|
+
let registry = _getRewireRegistry__();
|
|
390
|
+
let rewireData = registry[moduleId];
|
|
391
|
+
if (!rewireData) {
|
|
392
|
+
registry[moduleId] = Object.create(null);
|
|
393
|
+
rewireData = registry[moduleId];
|
|
394
|
+
}
|
|
395
|
+
return rewireData;
|
|
396
|
+
}
|
|
397
|
+
(function registerResetAll() {
|
|
398
|
+
let theGlobalVariable = _getGlobalObject();
|
|
399
|
+
if (!theGlobalVariable['__rewire_reset_all__']) {
|
|
400
|
+
theGlobalVariable['__rewire_reset_all__'] = function () {
|
|
401
|
+
theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__ = Object.create(null);
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
})();
|
|
405
|
+
var INTENTIONAL_UNDEFINED = '__INTENTIONAL_UNDEFINED__';
|
|
406
|
+
let _RewireAPI__ = {};
|
|
407
|
+
(function () {
|
|
408
|
+
function addPropertyToAPIObject(name, value) {
|
|
409
|
+
Object.defineProperty(_RewireAPI__, name, {
|
|
410
|
+
value: value,
|
|
411
|
+
enumerable: false,
|
|
412
|
+
configurable: true
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
addPropertyToAPIObject('__get__', _get__);
|
|
416
|
+
addPropertyToAPIObject('__GetDependency__', _get__);
|
|
417
|
+
addPropertyToAPIObject('__Rewire__', _set__);
|
|
418
|
+
addPropertyToAPIObject('__set__', _set__);
|
|
419
|
+
addPropertyToAPIObject('__reset__', _reset__);
|
|
420
|
+
addPropertyToAPIObject('__ResetDependency__', _reset__);
|
|
421
|
+
addPropertyToAPIObject('__with__', _with__);
|
|
422
|
+
})();
|
|
423
|
+
function _get__(variableName) {
|
|
424
|
+
let rewireData = _getRewiredData__();
|
|
425
|
+
if (rewireData[variableName] === undefined) {
|
|
426
|
+
return _get_original__(variableName);
|
|
427
|
+
} else {
|
|
428
|
+
var value = rewireData[variableName];
|
|
429
|
+
if (value === INTENTIONAL_UNDEFINED) {
|
|
430
|
+
return undefined;
|
|
431
|
+
} else {
|
|
432
|
+
return value;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
function _get_original__(variableName) {
|
|
437
|
+
switch (variableName) {
|
|
438
|
+
case "Direction":
|
|
439
|
+
return Direction;
|
|
440
|
+
case "event_1":
|
|
441
|
+
return event_1;
|
|
442
|
+
case "dom_1":
|
|
443
|
+
return dom_1;
|
|
444
|
+
case "keyboardEvent_1":
|
|
445
|
+
return keyboardEvent_1;
|
|
446
|
+
case "keyCodes_1":
|
|
447
|
+
return keyCodes_1;
|
|
448
|
+
case "submenu_1":
|
|
449
|
+
return submenu_1;
|
|
450
|
+
case "platform_1":
|
|
451
|
+
return platform_1;
|
|
452
|
+
case "separator_1":
|
|
453
|
+
return separator_1;
|
|
454
|
+
case "item_1":
|
|
455
|
+
return item_1;
|
|
456
|
+
case "color_1":
|
|
457
|
+
return color_1;
|
|
458
|
+
case "lifecycle_1":
|
|
459
|
+
return lifecycle_1;
|
|
460
|
+
case "CETMenu":
|
|
461
|
+
return CETMenu;
|
|
462
|
+
}
|
|
463
|
+
return undefined;
|
|
464
|
+
}
|
|
465
|
+
function _assign__(variableName, value) {
|
|
466
|
+
let rewireData = _getRewiredData__();
|
|
467
|
+
if (rewireData[variableName] === undefined) {
|
|
468
|
+
return _set_original__(variableName, value);
|
|
469
|
+
} else {
|
|
470
|
+
return rewireData[variableName] = value;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
function _set_original__(variableName, _value) {
|
|
474
|
+
switch (variableName) {
|
|
475
|
+
case "Direction":
|
|
476
|
+
return Direction = _value;
|
|
477
|
+
}
|
|
478
|
+
return undefined;
|
|
479
|
+
}
|
|
480
|
+
function _update_operation__(operation, variableName, prefix) {
|
|
481
|
+
var oldValue = _get__(variableName);
|
|
482
|
+
var newValue = operation === '++' ? oldValue + 1 : oldValue - 1;
|
|
483
|
+
_assign__(variableName, newValue);
|
|
484
|
+
return prefix ? newValue : oldValue;
|
|
485
|
+
}
|
|
486
|
+
function _set__(variableName, value) {
|
|
487
|
+
let rewireData = _getRewiredData__();
|
|
488
|
+
if (typeof variableName === 'object') {
|
|
489
|
+
Object.keys(variableName).forEach(function (name) {
|
|
490
|
+
rewireData[name] = variableName[name];
|
|
491
|
+
});
|
|
492
|
+
return function () {
|
|
493
|
+
Object.keys(variableName).forEach(function (name) {
|
|
494
|
+
_reset__(variableName);
|
|
495
|
+
});
|
|
496
|
+
};
|
|
497
|
+
} else {
|
|
498
|
+
if (value === undefined) {
|
|
499
|
+
rewireData[variableName] = INTENTIONAL_UNDEFINED;
|
|
500
|
+
} else {
|
|
501
|
+
rewireData[variableName] = value;
|
|
502
|
+
}
|
|
503
|
+
return function () {
|
|
504
|
+
_reset__(variableName);
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
function _reset__(variableName) {
|
|
509
|
+
let rewireData = _getRewiredData__();
|
|
510
|
+
delete rewireData[variableName];
|
|
511
|
+
if (Object.keys(rewireData).length == 0) {
|
|
512
|
+
delete _getRewireRegistry__()[_getRewireModuleId__];
|
|
513
|
+
}
|
|
514
|
+
;
|
|
515
|
+
}
|
|
516
|
+
function _with__(object) {
|
|
517
|
+
let rewireData = _getRewiredData__();
|
|
518
|
+
var rewiredVariableNames = Object.keys(object);
|
|
519
|
+
var previousValues = {};
|
|
520
|
+
function reset() {
|
|
521
|
+
rewiredVariableNames.forEach(function (variableName) {
|
|
522
|
+
rewireData[variableName] = previousValues[variableName];
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
return function (callback) {
|
|
526
|
+
rewiredVariableNames.forEach(function (variableName) {
|
|
527
|
+
previousValues[variableName] = rewireData[variableName];
|
|
528
|
+
rewireData[variableName] = object[variableName];
|
|
529
|
+
});
|
|
530
|
+
let result = callback();
|
|
531
|
+
if (!!result && typeof result.then == 'function') {
|
|
532
|
+
result.then(reset).catch(reset);
|
|
533
|
+
} else {
|
|
534
|
+
reset();
|
|
535
|
+
}
|
|
536
|
+
return result;
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
let _typeOfOriginalExport = typeof module.exports;
|
|
540
|
+
function addNonEnumerableProperty(name, value) {
|
|
541
|
+
Object.defineProperty(module.exports, name, {
|
|
542
|
+
value: value,
|
|
543
|
+
enumerable: false,
|
|
544
|
+
configurable: true
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
if ((_typeOfOriginalExport === 'object' || _typeOfOriginalExport === 'function') && Object.isExtensible(module.exports)) {
|
|
548
|
+
addNonEnumerableProperty('__get__', _get__);
|
|
549
|
+
addNonEnumerableProperty('__GetDependency__', _get__);
|
|
550
|
+
addNonEnumerableProperty('__Rewire__', _set__);
|
|
551
|
+
addNonEnumerableProperty('__set__', _set__);
|
|
552
|
+
addNonEnumerableProperty('__reset__', _reset__);
|
|
553
|
+
addNonEnumerableProperty('__ResetDependency__', _reset__);
|
|
554
|
+
addNonEnumerableProperty('__with__', _with__);
|
|
555
|
+
addNonEnumerableProperty('__RewireAPI__', _RewireAPI__);
|
|
556
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { MenuItem } from 'electron';
|
|
2
|
+
import { Color } from '../../base/common/color';
|
|
3
|
+
import { EventLike } from '../../base/common/dom';
|
|
4
|
+
import { KeyCode } from '../../base/common/keyCodes';
|
|
5
|
+
import { Disposable } from '../../base/common/lifecycle';
|
|
6
|
+
import { MenuBarOptions } from '../menubar-options';
|
|
7
|
+
import { IMenuOptions } from './index';
|
|
8
|
+
import { IMenuIcons } from '../../menubar';
|
|
9
|
+
export interface IMenuStyle {
|
|
10
|
+
foregroundColor?: Color;
|
|
11
|
+
backgroundColor?: Color;
|
|
12
|
+
selectionForegroundColor?: Color;
|
|
13
|
+
selectionBackgroundColor?: Color;
|
|
14
|
+
separatorColor?: Color;
|
|
15
|
+
svgColor?: Color;
|
|
16
|
+
}
|
|
17
|
+
export interface IMenuItem {
|
|
18
|
+
render(element: HTMLElement): void;
|
|
19
|
+
updateStyle(style: IMenuStyle): void;
|
|
20
|
+
onClick(event: EventLike): void;
|
|
21
|
+
dispose(): void;
|
|
22
|
+
isEnabled(): boolean;
|
|
23
|
+
isSeparator(): boolean;
|
|
24
|
+
focus(): void;
|
|
25
|
+
blur(): void;
|
|
26
|
+
}
|
|
27
|
+
export declare class CETMenuItem extends Disposable implements IMenuItem {
|
|
28
|
+
private _item;
|
|
29
|
+
private menuIcons;
|
|
30
|
+
private parentOptions;
|
|
31
|
+
private options;
|
|
32
|
+
private menuItems?;
|
|
33
|
+
private closeSubMenu;
|
|
34
|
+
private _mnemonic?;
|
|
35
|
+
private _currentElement?;
|
|
36
|
+
private labelElement?;
|
|
37
|
+
private iconElement?;
|
|
38
|
+
protected itemElement?: HTMLElement;
|
|
39
|
+
protected menuStyle?: IMenuStyle;
|
|
40
|
+
private radioGroup?;
|
|
41
|
+
constructor(_item: MenuItem, menuIcons: IMenuIcons, parentOptions: MenuBarOptions, options: IMenuOptions, menuItems?: IMenuItem[] | undefined, closeSubMenu?: () => void);
|
|
42
|
+
render(el: HTMLElement): void;
|
|
43
|
+
onClick(event: EventLike): void;
|
|
44
|
+
protected applyStyle(): void;
|
|
45
|
+
updateStyle(style: IMenuStyle): void;
|
|
46
|
+
focus(): void;
|
|
47
|
+
blur(): void;
|
|
48
|
+
setAccelerator(): void;
|
|
49
|
+
updateLabel(): void;
|
|
50
|
+
updateIcon(): void;
|
|
51
|
+
updateTooltip(): void;
|
|
52
|
+
updateEnabled(): void;
|
|
53
|
+
updateVisibility(): void;
|
|
54
|
+
updateChecked(): void;
|
|
55
|
+
updateRadioGroup(): void;
|
|
56
|
+
/** radioGroup index's starts with (previous separator +1 OR menuItems[0]) and ends with (next separator OR menuItems[length]) */
|
|
57
|
+
getRadioGroup(): {
|
|
58
|
+
start: number;
|
|
59
|
+
end: number;
|
|
60
|
+
};
|
|
61
|
+
get element(): HTMLElement | undefined;
|
|
62
|
+
get item(): MenuItem;
|
|
63
|
+
isEnabled(): boolean;
|
|
64
|
+
isSeparator(): boolean;
|
|
65
|
+
get mnemonic(): KeyCode | undefined;
|
|
66
|
+
dispose(): void;
|
|
67
|
+
}
|