menus.ts 49.8 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6 7
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

J
Joao Moreno 已提交
8 9 10
import * as nls from 'vs/nls';
import * as platform from 'vs/base/common/platform';
import * as arrays from 'vs/base/common/arrays';
11
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
J
Joao Moreno 已提交
12
import { ipcMain as ipc, app, shell, dialog, Menu, MenuItem } from 'electron';
J
Joao Moreno 已提交
13
import { IWindowsMainService } from 'vs/code/electron-main/windows';
14
import { VSCodeWindow } from 'vs/code/electron-main/window';
B
Benjamin Pasero 已提交
15
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
16
import { IStorageService } from 'vs/code/electron-main/storage';
B
Benjamin Pasero 已提交
17
import { IFilesConfiguration, AutoSaveConfiguration } from 'vs/platform/files/common/files';
J
Joao Moreno 已提交
18
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
J
Joao Moreno 已提交
19
import { IUpdateService, State as UpdateState } from 'vs/platform/update/common/update';
20 21
import { Keybinding } from 'vs/base/common/keyCodes';
import { KeybindingLabels } from 'vs/base/common/keybinding';
22
import product from 'vs/platform/node/product';
23
import { RunOnceScheduler } from 'vs/base/common/async';
E
Erich Gamma 已提交
24 25

interface IResolvedKeybinding {
B
Benjamin Pasero 已提交
26 27
	id: string;
	binding: number;
E
Erich Gamma 已提交
28 29
}

30 31 32 33 34
interface IExtensionViewlet {
	id: string;
	label: string;
}

B
Benjamin Pasero 已提交
35 36 37 38 39 40 41
interface IConfiguration extends IFilesConfiguration {
	workbench: {
		sideBar: {
			location: 'left' | 'right';
		},
		statusBar: {
			visible: boolean;
S
Sanders Lauture 已提交
42 43 44
		},
		activityBar: {
			visible: boolean;
B
Benjamin Pasero 已提交
45 46 47 48
		}
	};
}

E
Erich Gamma 已提交
49 50 51 52
export class VSCodeMenu {

	private static lastKnownKeybindingsMapStorageKey = 'lastKnownKeybindings';

53
	private static MAX_MENU_RECENT_ENTRIES = 10;
54

B
Benjamin Pasero 已提交
55
	private currentAutoSaveSetting: string;
B
Benjamin Pasero 已提交
56 57
	private currentSidebarLocation: 'left' | 'right';
	private currentStatusbarVisible: boolean;
S
Sanders Lauture 已提交
58
	private currentActivityBarVisible: boolean;
B
Benjamin Pasero 已提交
59

B
Benjamin Pasero 已提交
60
	private isQuitting: boolean;
E
Erich Gamma 已提交
61 62
	private appMenuInstalled: boolean;

63 64
	private menuUpdater: RunOnceScheduler;

E
Erich Gamma 已提交
65 66 67 68 69
	private actionIdKeybindingRequests: string[];
	private mapLastKnownKeybindingToActionId: { [id: string]: string; };
	private mapResolvedKeybindingToActionId: { [id: string]: string; };
	private keybindingsResolved: boolean;

70 71
	private extensionViewlets: IExtensionViewlet[];

J
Joao Moreno 已提交
72 73
	constructor(
		@IStorageService private storageService: IStorageService,
B
Benjamin Pasero 已提交
74
		@IUpdateService private updateService: IUpdateService,
B
Benjamin Pasero 已提交
75
		@IConfigurationService private configurationService: IConfigurationService,
J
Joao Moreno 已提交
76
		@IWindowsMainService private windowsService: IWindowsMainService,
J
Joao Moreno 已提交
77 78
		@IEnvironmentService private environmentService: IEnvironmentService,
		@ITelemetryService private telemetryService: ITelemetryService
J
Joao Moreno 已提交
79
	) {
E
Erich Gamma 已提交
80
		this.actionIdKeybindingRequests = [];
81
		this.extensionViewlets = [];
E
Erich Gamma 已提交
82 83

		this.mapResolvedKeybindingToActionId = Object.create(null);
J
Joao Moreno 已提交
84
		this.mapLastKnownKeybindingToActionId = this.storageService.getItem<{ [id: string]: string; }>(VSCodeMenu.lastKnownKeybindingsMapStorageKey) || Object.create(null);
B
Benjamin Pasero 已提交
85

86 87
		this.menuUpdater = new RunOnceScheduler(() => this.doUpdateMenu(), 0);

B
Benjamin Pasero 已提交
88
		this.onConfigurationUpdated(this.configurationService.getConfiguration<IConfiguration>());
E
Erich Gamma 已提交
89 90 91 92 93 94 95 96 97 98 99
	}

	public ready(): void {
		this.registerListeners();
		this.install();
	}

	private registerListeners(): void {

		// Keep flag when app quits
		app.on('will-quit', () => {
B
Benjamin Pasero 已提交
100
			this.isQuitting = true;
E
Erich Gamma 已提交
101 102
		});

103
		// Listen to some events from window service
B
Benjamin Pasero 已提交
104
		this.windowsService.onPathsOpen(paths => this.updateMenu());
105 106
		this.windowsService.onRecentPathsChange(paths => this.updateMenu());
		this.windowsService.onWindowClose(_ => this.onClose(this.windowsService.getWindowCount()));
E
Erich Gamma 已提交
107 108

		// Resolve keybindings when any first workbench is loaded
109
		this.windowsService.onWindowReady(win => this.resolveKeybindings(win));
E
Erich Gamma 已提交
110 111 112

		// Listen to resolved keybindings
		ipc.on('vscode:keybindingsResolved', (event, rawKeybindings) => {
B
Benjamin Pasero 已提交
113
			let keybindings: IResolvedKeybinding[] = [];
E
Erich Gamma 已提交
114 115 116 117 118 119
			try {
				keybindings = JSON.parse(rawKeybindings);
			} catch (error) {
				// Should not happen
			}

120
			// Fill hash map of resolved keybindings
E
Erich Gamma 已提交
121
			let needsMenuUpdate = false;
B
Benjamin Pasero 已提交
122
			keybindings.forEach(keybinding => {
123
				const accelerator = KeybindingLabels._toElectronAccelerator(new Keybinding(keybinding.binding));
E
Erich Gamma 已提交
124 125 126 127 128 129 130 131
				if (accelerator) {
					this.mapResolvedKeybindingToActionId[keybinding.id] = accelerator;
					if (this.mapLastKnownKeybindingToActionId[keybinding.id] !== accelerator) {
						needsMenuUpdate = true; // we only need to update when something changed!
					}
				}
			});

132 133 134 135 136
			// A keybinding might have been unassigned, so we have to account for that too
			if (Object.keys(this.mapLastKnownKeybindingToActionId).length !== Object.keys(this.mapResolvedKeybindingToActionId).length) {
				needsMenuUpdate = true;
			}

E
Erich Gamma 已提交
137
			if (needsMenuUpdate) {
J
Joao Moreno 已提交
138
				this.storageService.setItem(VSCodeMenu.lastKnownKeybindingsMapStorageKey, this.mapResolvedKeybindingToActionId); // keep to restore instantly after restart
139 140
				this.mapLastKnownKeybindingToActionId = this.mapResolvedKeybindingToActionId; // update our last known map

E
Erich Gamma 已提交
141 142 143 144
				this.updateMenu();
			}
		});

145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
		// Listen to extension viewlets
		ipc.on('vscode:extensionViewlets', (event, rawExtensionViewlets) => {
			let extensionViewlets: IExtensionViewlet[] = [];
			try {
				extensionViewlets = JSON.parse(rawExtensionViewlets);
			} catch (error) {
				// Should not happen
			}

			if (extensionViewlets.length) {
				this.extensionViewlets = extensionViewlets;
				this.updateMenu();
			}
		});

B
Benjamin Pasero 已提交
160
		// Update when auto save config changes
B
Benjamin Pasero 已提交
161
		this.configurationService.onDidUpdateConfiguration(e => this.onConfigurationUpdated(e.config, true /* update menu if changed */));
B
Benjamin Pasero 已提交
162

B
Benjamin Pasero 已提交
163
		// Listen to update service
164
		this.updateService.onStateChange(() => this.updateMenu());
E
Erich Gamma 已提交
165 166
	}

B
Benjamin Pasero 已提交
167
	private onConfigurationUpdated(config: IConfiguration, handleMenu?: boolean): void {
B
Benjamin Pasero 已提交
168
		let updateMenu = false;
B
Benjamin Pasero 已提交
169 170 171
		const newAutoSaveSetting = config && config.files && config.files.autoSave;
		if (newAutoSaveSetting !== this.currentAutoSaveSetting) {
			this.currentAutoSaveSetting = newAutoSaveSetting;
B
Benjamin Pasero 已提交
172 173 174
			updateMenu = true;
		}

175 176 177 178 179
		const newSidebarLocation = config && config.workbench && config.workbench.sideBar && config.workbench.sideBar.location || 'left';
		if (newSidebarLocation !== this.currentSidebarLocation) {
			this.currentSidebarLocation = newSidebarLocation;
			updateMenu = true;
		}
B
Benjamin Pasero 已提交
180

181 182 183 184 185 186 187 188
		let newStatusbarVisible = config && config.workbench && config.workbench.statusBar && config.workbench.statusBar.visible;
		if (typeof newStatusbarVisible !== 'boolean') {
			newStatusbarVisible = true;
		}
		if (newStatusbarVisible !== this.currentStatusbarVisible) {
			this.currentStatusbarVisible = newStatusbarVisible;
			updateMenu = true;
		}
S
Sanders Lauture 已提交
189

190 191 192 193 194 195 196
		let newActivityBarVisible = config && config.workbench && config.workbench.activityBar && config.workbench.activityBar.visible;
		if (typeof newActivityBarVisible !== 'boolean') {
			newActivityBarVisible = true;
		}
		if (newActivityBarVisible !== this.currentActivityBarVisible) {
			this.currentActivityBarVisible = newActivityBarVisible;
			updateMenu = true;
B
Benjamin Pasero 已提交
197 198 199
		}

		if (handleMenu && updateMenu) {
B
Benjamin Pasero 已提交
200 201 202 203
			this.updateMenu();
		}
	}

J
Joao Moreno 已提交
204
	private resolveKeybindings(win: VSCodeWindow): void {
E
Erich Gamma 已提交
205 206 207 208 209 210 211 212
		if (this.keybindingsResolved) {
			return; // only resolve once
		}

		this.keybindingsResolved = true;

		// Resolve keybindings when workbench window is up
		if (this.actionIdKeybindingRequests.length) {
213
			win.send('vscode:resolveKeybindings', JSON.stringify(this.actionIdKeybindingRequests));
E
Erich Gamma 已提交
214 215 216 217
		}
	}

	private updateMenu(): void {
218 219 220 221
		this.menuUpdater.schedule(); // buffer multiple attempts to update the menu
	}

	private doUpdateMenu(): void {
E
Erich Gamma 已提交
222 223 224

		// Due to limitations in Electron, it is not possible to update menu items dynamically. The suggested
		// workaround from Electron is to set the application menu again.
M
Martin Aeschlimann 已提交
225
		// See also https://github.com/electron/electron/issues/846
E
Erich Gamma 已提交
226 227 228 229 230 231 232 233 234 235 236
		//
		// Run delayed to prevent updating menu while it is open
		if (!this.isQuitting) {
			setTimeout(() => {
				if (!this.isQuitting) {
					this.install();
				}
			}, 10 /* delay this because there is an issue with updating a menu when it is open */);
		}
	}

B
Benjamin Pasero 已提交
237
	private onClose(remainingWindowCount: number): void {
E
Erich Gamma 已提交
238 239 240 241 242 243 244 245
		if (remainingWindowCount === 0 && platform.isMacintosh) {
			this.updateMenu();
		}
	}

	private install(): void {

		// Menus
B
Benjamin Pasero 已提交
246
		const menubar = new Menu();
E
Erich Gamma 已提交
247 248

		// Mac: Application
B
Benjamin Pasero 已提交
249
		let macApplicationMenuItem: Electron.MenuItem;
E
Erich Gamma 已提交
250
		if (platform.isMacintosh) {
B
Benjamin Pasero 已提交
251
			const applicationMenu = new Menu();
B
Benjamin Pasero 已提交
252
			macApplicationMenuItem = new MenuItem({ label: product.nameShort, submenu: applicationMenu });
E
Erich Gamma 已提交
253 254 255 256
			this.setMacApplicationMenu(applicationMenu);
		}

		// File
B
Benjamin Pasero 已提交
257 258
		const fileMenu = new Menu();
		const fileMenuItem = new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'mFile', comment: ['&& denotes a mnemonic'] }, "&&File")), submenu: fileMenu });
E
Erich Gamma 已提交
259 260 261
		this.setFileMenu(fileMenu);

		// Edit
B
Benjamin Pasero 已提交
262 263
		const editMenu = new Menu();
		const editMenuItem = new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'mEdit', comment: ['&& denotes a mnemonic'] }, "&&Edit")), submenu: editMenu });
E
Erich Gamma 已提交
264 265
		this.setEditMenu(editMenu);

C
Christof Marti 已提交
266 267 268 269 270
		// Selection
		const selectionMenu = new Menu();
		const selectionMenuItem = new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'mSelection', comment: ['&& denotes a mnemonic'] }, "&&Selection")), submenu: selectionMenu });
		this.setSelectionMenu(selectionMenu);

E
Erich Gamma 已提交
271
		// View
B
Benjamin Pasero 已提交
272 273
		const viewMenu = new Menu();
		const viewMenuItem = new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'mView', comment: ['&& denotes a mnemonic'] }, "&&View")), submenu: viewMenu });
E
Erich Gamma 已提交
274 275 276
		this.setViewMenu(viewMenu);

		// Goto
B
Benjamin Pasero 已提交
277 278
		const gotoMenu = new Menu();
		const gotoMenuItem = new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'mGoto', comment: ['&& denotes a mnemonic'] }, "&&Go")), submenu: gotoMenu });
E
Erich Gamma 已提交
279 280 281
		this.setGotoMenu(gotoMenu);

		// Mac: Window
B
Benjamin Pasero 已提交
282
		let macWindowMenuItem: Electron.MenuItem;
E
Erich Gamma 已提交
283
		if (platform.isMacintosh) {
B
Benjamin Pasero 已提交
284
			const windowMenu = new Menu();
E
Erich Gamma 已提交
285 286 287 288 289
			macWindowMenuItem = new MenuItem({ label: mnemonicLabel(nls.localize('mWindow', "Window")), submenu: windowMenu, role: 'window' });
			this.setMacWindowMenu(windowMenu);
		}

		// Help
B
Benjamin Pasero 已提交
290 291
		const helpMenu = new Menu();
		const helpMenuItem = new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'mHelp', comment: ['&& denotes a mnemonic'] }, "&&Help")), submenu: helpMenu, role: 'help' });
E
Erich Gamma 已提交
292 293 294 295 296 297 298 299 300
		this.setHelpMenu(helpMenu);

		// Menu Structure
		if (macApplicationMenuItem) {
			menubar.append(macApplicationMenuItem);
		}

		menubar.append(fileMenuItem);
		menubar.append(editMenuItem);
C
Christof Marti 已提交
301
		menubar.append(selectionMenuItem);
E
Erich Gamma 已提交
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
		menubar.append(viewMenuItem);
		menubar.append(gotoMenuItem);

		if (macWindowMenuItem) {
			menubar.append(macWindowMenuItem);
		}

		menubar.append(helpMenuItem);

		Menu.setApplicationMenu(menubar);

		// Dock Menu
		if (platform.isMacintosh && !this.appMenuInstalled) {
			this.appMenuInstalled = true;

B
Benjamin Pasero 已提交
317
			const dockMenu = new Menu();
B
Benjamin Pasero 已提交
318
			dockMenu.append(new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'miNewWindow', comment: ['&& denotes a mnemonic'] }, "New &&Window")), click: () => this.windowsService.openNewWindow() }));
E
Erich Gamma 已提交
319

320
			app.dock.setMenu(dockMenu);
E
Erich Gamma 已提交
321 322 323
		}
	}

B
Benjamin Pasero 已提交
324
	private setMacApplicationMenu(macApplicationMenu: Electron.Menu): void {
B
Benjamin Pasero 已提交
325
		const about = new MenuItem({ label: nls.localize('mAbout', "About {0}", product.nameLong), role: 'about' });
B
Benjamin Pasero 已提交
326 327
		const checkForUpdates = this.getUpdateMenuItems();
		const preferences = this.getPreferencesMenu();
B
Benjamin Pasero 已提交
328
		const hide = new MenuItem({ label: nls.localize('mHide', "Hide {0}", product.nameLong), role: 'hide', accelerator: 'Command+H' });
B
Benjamin Pasero 已提交
329 330
		const hideOthers = new MenuItem({ label: nls.localize('mHideOthers', "Hide Others"), role: 'hideothers', accelerator: 'Command+Alt+H' });
		const showAll = new MenuItem({ label: nls.localize('mShowAll', "Show All"), role: 'unhide' });
331
		const quit = new MenuItem(this.likeAction('workbench.action.quit', { label: nls.localize('miQuit', "Quit {0}", product.nameLong), click: () => this.windowsService.quit(), accelerator: this.getAccelerator('workbench.action.quit', 'Command+Q') }));
B
Benjamin Pasero 已提交
332 333

		const actions = [about];
E
Erich Gamma 已提交
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
		actions.push(...checkForUpdates);
		actions.push(...[
			__separator__(),
			preferences,
			__separator__(),
			hide,
			hideOthers,
			showAll,
			__separator__(),
			quit
		]);

		actions.forEach(i => macApplicationMenu.append(i));
	}

B
Benjamin Pasero 已提交
349
	private setFileMenu(fileMenu: Electron.Menu): void {
B
Benjamin Pasero 已提交
350
		const hasNoWindows = (this.windowsService.getWindowCount() === 0);
E
Erich Gamma 已提交
351

B
Benjamin Pasero 已提交
352
		let newFile: Electron.MenuItem;
E
Erich Gamma 已提交
353
		if (hasNoWindows) {
354
			newFile = new MenuItem(this.likeAction('workbench.action.files.newUntitledFile', { label: mnemonicLabel(nls.localize({ key: 'miNewFile', comment: ['&& denotes a mnemonic'] }, "&&New File")), click: () => this.windowsService.openNewWindow() }));
E
Erich Gamma 已提交
355
		} else {
B
Benjamin Pasero 已提交
356
			newFile = this.createMenuItem(nls.localize({ key: 'miNewFile', comment: ['&& denotes a mnemonic'] }, "&&New File"), 'workbench.action.files.newUntitledFile');
E
Erich Gamma 已提交
357 358
		}

359 360
		const open = new MenuItem(this.likeAction('workbench.action.files.openFileFolder', { label: mnemonicLabel(nls.localize({ key: 'miOpen', comment: ['&& denotes a mnemonic'] }, "&&Open...")), click: () => this.windowsService.openFileFolderPicker() }));
		const openFolder = new MenuItem(this.likeAction('workbench.action.files.openFolder', { label: mnemonicLabel(nls.localize({ key: 'miOpenFolder', comment: ['&& denotes a mnemonic'] }, "Open &&Folder...")), click: () => this.windowsService.openFolderPicker() }));
E
Erich Gamma 已提交
361

362 363
		let openFile: Electron.MenuItem;
		if (hasNoWindows) {
364
			openFile = new MenuItem(this.likeAction('workbench.action.files.openFile', { label: mnemonicLabel(nls.localize({ key: 'miOpenFile', comment: ['&& denotes a mnemonic'] }, "&&Open File...")), click: () => this.windowsService.openFilePicker() }));
365 366 367 368
		} else {
			openFile = this.createMenuItem(nls.localize({ key: 'miOpenFile', comment: ['&& denotes a mnemonic'] }, "&&Open File..."), 'workbench.action.files.openFile');
		}

B
Benjamin Pasero 已提交
369
		const openRecentMenu = new Menu();
E
Erich Gamma 已提交
370
		this.setOpenRecentMenu(openRecentMenu);
B
Benjamin Pasero 已提交
371
		const openRecent = new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'miOpenRecent', comment: ['&& denotes a mnemonic'] }, "Open &&Recent")), submenu: openRecentMenu, enabled: openRecentMenu.items.length > 0 });
E
Erich Gamma 已提交
372

B
Benjamin Pasero 已提交
373 374 375
		const saveFile = this.createMenuItem(nls.localize({ key: 'miSave', comment: ['&& denotes a mnemonic'] }, "&&Save"), 'workbench.action.files.save', this.windowsService.getWindowCount() > 0);
		const saveFileAs = this.createMenuItem(nls.localize({ key: 'miSaveAs', comment: ['&& denotes a mnemonic'] }, "Save &&As..."), 'workbench.action.files.saveAs', this.windowsService.getWindowCount() > 0);
		const saveAllFiles = this.createMenuItem(nls.localize({ key: 'miSaveAll', comment: ['&& denotes a mnemonic'] }, "Save A&&ll"), 'workbench.action.files.saveAll', this.windowsService.getWindowCount() > 0);
E
Erich Gamma 已提交
376

B
Benjamin Pasero 已提交
377
		const autoSaveEnabled = [AutoSaveConfiguration.AFTER_DELAY, AutoSaveConfiguration.ON_FOCUS_CHANGE, AutoSaveConfiguration.ON_WINDOW_CHANGE].some(s => this.currentAutoSaveSetting === s);
378
		const autoSave = new MenuItem(this.likeAction('vscode.toggleAutoSave', { label: mnemonicLabel(nls.localize('miAutoSave', "Auto Save")), type: 'checkbox', checked: autoSaveEnabled, enabled: this.windowsService.getWindowCount() > 0, click: () => this.windowsService.sendToFocused('vscode.toggleAutoSave') }, false));
B
Benjamin Pasero 已提交
379

B
Benjamin Pasero 已提交
380
		const preferences = this.getPreferencesMenu();
E
Erich Gamma 已提交
381

B
Benjamin Pasero 已提交
382 383 384
		const newWindow = new MenuItem(this.likeAction('workbench.action.newWindow', { label: mnemonicLabel(nls.localize({ key: 'miNewWindow', comment: ['&& denotes a mnemonic'] }, "New &&Window")), click: () => this.windowsService.openNewWindow() }));
		const revertFile = this.createMenuItem(nls.localize({ key: 'miRevert', comment: ['&& denotes a mnemonic'] }, "Re&&vert File"), 'workbench.action.files.revert', this.windowsService.getWindowCount() > 0);
		const closeWindow = new MenuItem(this.likeAction('workbench.action.closeWindow', { label: mnemonicLabel(nls.localize({ key: 'miCloseWindow', comment: ['&& denotes a mnemonic'] }, "Clos&&e Window")), click: () => this.windowsService.getLastActiveWindow().win.close(), enabled: this.windowsService.getWindowCount() > 0 }));
E
Erich Gamma 已提交
385

B
Benjamin Pasero 已提交
386
		const closeFolder = this.createMenuItem(nls.localize({ key: 'miCloseFolder', comment: ['&& denotes a mnemonic'] }, "Close &&Folder"), 'workbench.action.closeFolder');
387
		const closeEditor = this.createMenuItem(nls.localize({ key: 'miCloseEditor', comment: ['&& denotes a mnemonic'] }, "&&Close Editor"), 'workbench.action.closeActiveEditor');
E
Erich Gamma 已提交
388

389
		const exit = new MenuItem(this.likeAction('workbench.action.quit', { label: mnemonicLabel(nls.localize({ key: 'miExit', comment: ['&& denotes a mnemonic'] }, "E&&xit")), click: () => this.windowsService.quit() }));
E
Erich Gamma 已提交
390 391 392 393 394 395 396 397 398 399 400 401 402 403

		arrays.coalesce([
			newFile,
			newWindow,
			__separator__(),
			platform.isMacintosh ? open : null,
			!platform.isMacintosh ? openFile : null,
			!platform.isMacintosh ? openFolder : null,
			openRecent,
			__separator__(),
			saveFile,
			saveFileAs,
			saveAllFiles,
			__separator__(),
B
Benjamin Pasero 已提交
404 405
			autoSave,
			__separator__(),
E
Erich Gamma 已提交
406 407 408 409 410 411 412 413
			!platform.isMacintosh ? preferences : null,
			!platform.isMacintosh ? __separator__() : null,
			revertFile,
			closeEditor,
			closeFolder,
			!platform.isMacintosh ? closeWindow : null,
			!platform.isMacintosh ? __separator__() : null,
			!platform.isMacintosh ? exit : null
B
Benjamin Pasero 已提交
414
		]).forEach(item => fileMenu.append(item));
E
Erich Gamma 已提交
415 416
	}

B
Benjamin Pasero 已提交
417
	private getPreferencesMenu(): Electron.MenuItem {
B
Benjamin Pasero 已提交
418 419 420
		const userSettings = this.createMenuItem(nls.localize({ key: 'miOpenSettings', comment: ['&& denotes a mnemonic'] }, "&&User Settings"), 'workbench.action.openGlobalSettings');
		const workspaceSettings = this.createMenuItem(nls.localize({ key: 'miOpenWorkspaceSettings', comment: ['&& denotes a mnemonic'] }, "&&Workspace Settings"), 'workbench.action.openWorkspaceSettings');
		const kebindingSettings = this.createMenuItem(nls.localize({ key: 'miOpenKeymap', comment: ['&& denotes a mnemonic'] }, "&&Keyboard Shortcuts"), 'workbench.action.openGlobalKeybindings');
421
		const keymapExtensions = this.createMenuItem(nls.localize({ key: 'miOpenKeymapExtensions', comment: ['&& denotes a mnemonic'] }, "&&Keymap Extensions"), 'workbench.extensions.action.showRecommendedKeymapExtensions');
B
Benjamin Pasero 已提交
422 423 424 425 426
		const snippetsSettings = this.createMenuItem(nls.localize({ key: 'miOpenSnippets', comment: ['&& denotes a mnemonic'] }, "User &&Snippets"), 'workbench.action.openSnippets');
		const colorThemeSelection = this.createMenuItem(nls.localize({ key: 'miSelectColorTheme', comment: ['&& denotes a mnemonic'] }, "&&Color Theme"), 'workbench.action.selectTheme');
		const iconThemeSelection = this.createMenuItem(nls.localize({ key: 'miSelectIconTheme', comment: ['&& denotes a mnemonic'] }, "File &&Icon Theme"), 'workbench.action.selectIconTheme');

		const preferencesMenu = new Menu();
E
Erich Gamma 已提交
427 428 429 430
		preferencesMenu.append(userSettings);
		preferencesMenu.append(workspaceSettings);
		preferencesMenu.append(__separator__());
		preferencesMenu.append(kebindingSettings);
431
		preferencesMenu.append(keymapExtensions);
E
Erich Gamma 已提交
432 433 434
		preferencesMenu.append(__separator__());
		preferencesMenu.append(snippetsSettings);
		preferencesMenu.append(__separator__());
435 436
		preferencesMenu.append(colorThemeSelection);
		preferencesMenu.append(iconThemeSelection);
E
Erich Gamma 已提交
437

B
Benjamin Pasero 已提交
438
		return new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'miPreferences', comment: ['&& denotes a mnemonic'] }, "&&Preferences")), submenu: preferencesMenu });
E
Erich Gamma 已提交
439 440
	}

B
Benjamin Pasero 已提交
441
	private setOpenRecentMenu(openRecentMenu: Electron.Menu): void {
442
		openRecentMenu.append(this.createMenuItem(nls.localize({ key: 'miReopenClosedEditor', comment: ['&& denotes a mnemonic'] }, "&&Reopen Closed Editor"), 'workbench.action.reopenClosedEditor'));
D
Daniel Imms 已提交
443

444
		const {folders, files} = this.windowsService.getRecentPathsList();
E
Erich Gamma 已提交
445 446

		// Folders
447
		if (folders.length > 0) {
448
			openRecentMenu.append(__separator__());
449 450

			for (let i = 0; i < VSCodeMenu.MAX_MENU_RECENT_ENTRIES && i < folders.length; i++) {
451
				openRecentMenu.append(this.createOpenRecentMenuItem(folders[i], 'openRecentFolder'));
452
			}
453
		}
E
Erich Gamma 已提交
454 455

		// Files
456
		if (files.length > 0) {
457
			openRecentMenu.append(__separator__());
E
Erich Gamma 已提交
458

459
			for (let i = 0; i < VSCodeMenu.MAX_MENU_RECENT_ENTRIES && i < files.length; i++) {
460
				openRecentMenu.append(this.createOpenRecentMenuItem(files[i], 'openRecentFile'));
461
			}
E
Erich Gamma 已提交
462 463
		}

464
		if (folders.length || files.length) {
E
Erich Gamma 已提交
465
			openRecentMenu.append(__separator__());
466
			openRecentMenu.append(new MenuItem(this.likeAction('clearRecentlyOpened', { label: mnemonicLabel(nls.localize({ key: 'miClearItems', comment: ['&& denotes a mnemonic'] }, "&&Clear Items")), click: () => this.windowsService.clearRecentPathsList() }, false)));
E
Erich Gamma 已提交
467 468 469
		}
	}

470 471
	private createOpenRecentMenuItem(path: string, actionId: string): Electron.MenuItem {
		return new MenuItem(this.likeAction(actionId, {
472 473
			label: unMnemonicLabel(path), click: (menuItem, win, event) => {
				const openInNewWindow = event && ((!platform.isMacintosh && event.ctrlKey) || (platform.isMacintosh && event.metaKey));
474
				const success = !!this.windowsService.open({ cli: this.environmentService.args, pathsToOpen: [path], forceNewWindow: openInNewWindow });
B
Benjamin Pasero 已提交
475
				if (!success) {
476
					this.windowsService.removeFromRecentPathsList(path);
B
Benjamin Pasero 已提交
477
				}
E
Erich Gamma 已提交
478
			}
479
		}, false));
E
Erich Gamma 已提交
480 481
	}

B
Benjamin Pasero 已提交
482
	private createRoleMenuItem(label: string, actionId: string, role: Electron.MenuItemRole): Electron.MenuItem {
B
Benjamin Pasero 已提交
483
		const options: Electron.MenuItemOptions = {
484 485
			label: mnemonicLabel(label),
			accelerator: this.getAccelerator(actionId),
B
Benjamin Pasero 已提交
486
			role,
487 488 489 490 491 492
			enabled: true
		};

		return new MenuItem(options);
	}

B
Benjamin Pasero 已提交
493 494 495 496 497 498
	private setEditMenu(winLinuxEditMenu: Electron.Menu): void {
		let undo: Electron.MenuItem;
		let redo: Electron.MenuItem;
		let cut: Electron.MenuItem;
		let copy: Electron.MenuItem;
		let paste: Electron.MenuItem;
E
Erich Gamma 已提交
499 500

		if (platform.isMacintosh) {
B
Benjamin Pasero 已提交
501 502
			undo = this.createDevToolsAwareMenuItem(nls.localize({ key: 'miUndo', comment: ['&& denotes a mnemonic'] }, "&&Undo"), 'undo', devTools => devTools.undo());
			redo = this.createDevToolsAwareMenuItem(nls.localize({ key: 'miRedo', comment: ['&& denotes a mnemonic'] }, "&&Redo"), 'redo', devTools => devTools.redo());
B
Benjamin Pasero 已提交
503 504
			cut = this.createRoleMenuItem(nls.localize({ key: 'miCut', comment: ['&& denotes a mnemonic'] }, "Cu&&t"), 'editor.action.clipboardCutAction', 'cut');
			copy = this.createRoleMenuItem(nls.localize({ key: 'miCopy', comment: ['&& denotes a mnemonic'] }, "&&Copy"), 'editor.action.clipboardCopyAction', 'copy');
505
			paste = this.createRoleMenuItem(nls.localize({ key: 'miPaste', comment: ['&& denotes a mnemonic'] }, "&&Paste"), 'editor.action.clipboardPasteAction', 'paste');
E
Erich Gamma 已提交
506
		} else {
B
Benjamin Pasero 已提交
507 508
			undo = this.createMenuItem(nls.localize({ key: 'miUndo', comment: ['&& denotes a mnemonic'] }, "&&Undo"), 'undo');
			redo = this.createMenuItem(nls.localize({ key: 'miRedo', comment: ['&& denotes a mnemonic'] }, "&&Redo"), 'redo');
B
Benjamin Pasero 已提交
509 510
			cut = this.createMenuItem(nls.localize({ key: 'miCut', comment: ['&& denotes a mnemonic'] }, "Cu&&t"), 'editor.action.clipboardCutAction');
			copy = this.createMenuItem(nls.localize({ key: 'miCopy', comment: ['&& denotes a mnemonic'] }, "&&Copy"), 'editor.action.clipboardCopyAction');
B
Benjamin Pasero 已提交
511
			paste = this.createMenuItem(nls.localize({ key: 'miPaste', comment: ['&& denotes a mnemonic'] }, "&&Paste"), 'editor.action.clipboardPasteAction');
E
Erich Gamma 已提交
512 513
		}

B
Benjamin Pasero 已提交
514 515
		const find = this.createMenuItem(nls.localize({ key: 'miFind', comment: ['&& denotes a mnemonic'] }, "&&Find"), 'actions.find');
		const replace = this.createMenuItem(nls.localize({ key: 'miReplace', comment: ['&& denotes a mnemonic'] }, "&&Replace"), 'editor.action.startFindReplaceAction');
S
Sandeep Somavarapu 已提交
516
		const findInFiles = this.createMenuItem(nls.localize({ key: 'miFindInFiles', comment: ['&& denotes a mnemonic'] }, "Find &&in Files"), 'workbench.action.findInFiles');
B
Benjamin Pasero 已提交
517
		const replaceInFiles = this.createMenuItem(nls.localize({ key: 'miReplaceInFiles', comment: ['&& denotes a mnemonic'] }, "Replace &&in Files"), 'workbench.action.replaceInFiles');
E
Erich Gamma 已提交
518

519 520
		const emmetExpandAbbreviation = this.createMenuItem(nls.localize({ key: 'miEmmetExpandAbbreviation', comment: ['&& denotes a mnemonic'] }, "Emmet: E&&xpand Abbreviation"), 'editor.emmet.action.expandAbbreviation');
		const showEmmetCommands = this.createMenuItem(nls.localize({ key: 'miShowEmmetCommands', comment: ['&& denotes a mnemonic'] }, "E&&mmet..."), 'workbench.action.showEmmetCommands');
521 522
		const toggleLineComment = this.createMenuItem(nls.localize({ key: 'miToggleLineComment', comment: ['&& denotes a mnemonic'] }, "&&Toggle Line Comment"), 'editor.action.commentLine');
		const toggleBlockComment = this.createMenuItem(nls.localize({ key: 'miToggleBlockComment', comment: ['&& denotes a mnemonic'] }, "Toggle &&Block Comment"), 'editor.action.blockComment');
523

E
Erich Gamma 已提交
524 525 526 527 528 529 530 531 532 533 534
		[
			undo,
			redo,
			__separator__(),
			cut,
			copy,
			paste,
			__separator__(),
			find,
			replace,
			__separator__(),
S
Sandeep Somavarapu 已提交
535
			findInFiles,
536 537
			replaceInFiles,
			__separator__(),
538 539
			toggleLineComment,
			toggleBlockComment,
540 541
			emmetExpandAbbreviation,
			showEmmetCommands
B
Benjamin Pasero 已提交
542
		].forEach(item => winLinuxEditMenu.append(item));
E
Erich Gamma 已提交
543 544
	}

C
Christof Marti 已提交
545 546 547
	private setSelectionMenu(winLinuxEditMenu: Electron.Menu): void {
		const insertCursorAbove = this.createMenuItem(nls.localize({ key: 'miInsertCursorAbove', comment: ['&& denotes a mnemonic'] }, "&&Add Cursor Above"), 'editor.action.insertCursorAbove');
		const insertCursorBelow = this.createMenuItem(nls.localize({ key: 'miInsertCursorBelow', comment: ['&& denotes a mnemonic'] }, "A&&dd Cursor Below"), 'editor.action.insertCursorBelow');
548
		const insertCursorAtEndOfEachLineSelected = this.createMenuItem(nls.localize({ key: 'miInsertCursorAtEndOfEachLineSelected', comment: ['&& denotes a mnemonic'] }, "Add C&&ursors to Line Ends"), 'editor.action.insertCursorAtEndOfEachLineSelected');
C
Christof Marti 已提交
549 550 551
		const addSelectionToNextFindMatch = this.createMenuItem(nls.localize({ key: 'miAddSelectionToNextFindMatch', comment: ['&& denotes a mnemonic'] }, "Add &&Next Occurrence"), 'editor.action.addSelectionToNextFindMatch');
		const addSelectionToPreviousFindMatch = this.createMenuItem(nls.localize({ key: 'miAddSelectionToPreviousFindMatch', comment: ['&& denotes a mnemonic'] }, "Add P&&revious Occurrence"), 'editor.action.addSelectionToPreviousFindMatch');
		const selectHighlights = this.createMenuItem(nls.localize({ key: 'miSelectHighlights', comment: ['&& denotes a mnemonic'] }, "Select All &&Occurrences"), 'editor.action.selectHighlights');
C
Christof Marti 已提交
552 553 554 555 556 557

		const copyLinesUp = this.createMenuItem(nls.localize({ key: 'miCopyLinesUp', comment: ['&& denotes a mnemonic'] }, "&&Copy Line Up"), 'editor.action.copyLinesUpAction');
		const copyLinesDown = this.createMenuItem(nls.localize({ key: 'miCopyLinesDown', comment: ['&& denotes a mnemonic'] }, "Co&&py Line Down"), 'editor.action.copyLinesDownAction');
		const moveLinesUp = this.createMenuItem(nls.localize({ key: 'miMoveLinesUp', comment: ['&& denotes a mnemonic'] }, "Mo&&ve Line Up"), 'editor.action.moveLinesUpAction');
		const moveLinesDown = this.createMenuItem(nls.localize({ key: 'miMoveLinesDown', comment: ['&& denotes a mnemonic'] }, "Move &&Line Down"), 'editor.action.moveLinesDownAction');

558 559 560 561 562 563
		let selectAll: Electron.MenuItem;
		if (platform.isMacintosh) {
			selectAll = this.createDevToolsAwareMenuItem(nls.localize({ key: 'miSelectAll', comment: ['&& denotes a mnemonic'] }, "&&Select All"), 'editor.action.selectAll', (devTools) => devTools.selectAll());
		} else {
			selectAll = this.createMenuItem(nls.localize({ key: 'miSelectAll', comment: ['&& denotes a mnemonic'] }, "&&Select All"), 'editor.action.selectAll');
		}
C
Christof Marti 已提交
564 565 566 567
		const smartSelectGrow = this.createMenuItem(nls.localize({ key: 'miSmartSelectGrow', comment: ['&& denotes a mnemonic'] }, "&&Expand Selection"), 'editor.action.smartSelect.grow');
		const smartSelectshrink = this.createMenuItem(nls.localize({ key: 'miSmartSelectShrink', comment: ['&& denotes a mnemonic'] }, "&&Shrink Selection"), 'editor.action.smartSelect.shrink');

		[
568 569 570
			selectAll,
			smartSelectGrow,
			smartSelectshrink,
C
Christof Marti 已提交
571 572 573 574 575 576
			__separator__(),
			copyLinesUp,
			copyLinesDown,
			moveLinesUp,
			moveLinesDown,
			__separator__(),
577 578 579 580 581 582
			insertCursorAbove,
			insertCursorBelow,
			insertCursorAtEndOfEachLineSelected,
			addSelectionToNextFindMatch,
			addSelectionToPreviousFindMatch,
			selectHighlights,
C
Christof Marti 已提交
583 584 585
		].forEach(item => winLinuxEditMenu.append(item));
	}

B
Benjamin Pasero 已提交
586
	private setViewMenu(viewMenu: Electron.Menu): void {
B
Benjamin Pasero 已提交
587 588 589 590 591 592 593 594 595 596
		const explorer = this.createMenuItem(nls.localize({ key: 'miViewExplorer', comment: ['&& denotes a mnemonic'] }, "&&Explorer"), 'workbench.view.explorer');
		const search = this.createMenuItem(nls.localize({ key: 'miViewSearch', comment: ['&& denotes a mnemonic'] }, "&&Search"), 'workbench.view.search');
		const git = this.createMenuItem(nls.localize({ key: 'miViewGit', comment: ['&& denotes a mnemonic'] }, "&&Git"), 'workbench.view.git');
		const debug = this.createMenuItem(nls.localize({ key: 'miViewDebug', comment: ['&& denotes a mnemonic'] }, "&&Debug"), 'workbench.view.debug');
		const extensions = this.createMenuItem(nls.localize({ key: 'miViewExtensions', comment: ['&& denotes a mnemonic'] }, "E&&xtensions"), 'workbench.view.extensions');
		const output = this.createMenuItem(nls.localize({ key: 'miToggleOutput', comment: ['&& denotes a mnemonic'] }, "&&Output"), 'workbench.action.output.toggleOutput');
		const debugConsole = this.createMenuItem(nls.localize({ key: 'miToggleDebugConsole', comment: ['&& denotes a mnemonic'] }, "De&&bug Console"), 'workbench.debug.action.toggleRepl');
		const integratedTerminal = this.createMenuItem(nls.localize({ key: 'miToggleIntegratedTerminal', comment: ['&& denotes a mnemonic'] }, "&&Integrated Terminal"), 'workbench.action.terminal.toggleTerminal');
		const problems = this.createMenuItem(nls.localize({ key: 'miMarker', comment: ['&& denotes a mnemonic'] }, "&&Problems"), 'workbench.actions.view.problems');

597 598 599 600 601 602 603 604
		let additionalViewlets: Electron.MenuItem;
		if (this.extensionViewlets.length) {
			const additionalViewletsMenu = new Menu();

			this.extensionViewlets.forEach(viewlet => {
				additionalViewletsMenu.append(this.createMenuItem(viewlet.label, viewlet.id));
			});

605
			additionalViewlets = new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'miAdditionalViews', comment: ['&& denotes a mnemonic'] }, "Additional &&Views")), submenu: additionalViewletsMenu, enabled: true });
606 607
		}

B
Benjamin Pasero 已提交
608 609 610
		const commands = this.createMenuItem(nls.localize({ key: 'miCommandPalette', comment: ['&& denotes a mnemonic'] }, "&&Command Palette..."), 'workbench.action.showCommands');

		const fullscreen = new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'miToggleFullScreen', comment: ['&& denotes a mnemonic'] }, "Toggle &&Full Screen")), accelerator: this.getAccelerator('workbench.action.toggleFullScreen'), click: () => this.windowsService.getLastActiveWindow().toggleFullScreen(), enabled: this.windowsService.getWindowCount() > 0 });
I
isidor 已提交
611
		const toggleZenMode = this.createMenuItem(nls.localize('miToggleZenMode', "Toggle Zen Mode"), 'workbench.action.toggleZenMode', this.windowsService.getWindowCount() > 0);
B
Benjamin Pasero 已提交
612 613
		const toggleMenuBar = this.createMenuItem(nls.localize({ key: 'miToggleMenuBar', comment: ['&& denotes a mnemonic'] }, "Toggle Menu &&Bar"), 'workbench.action.toggleMenuBar');
		const splitEditor = this.createMenuItem(nls.localize({ key: 'miSplitEditor', comment: ['&& denotes a mnemonic'] }, "Split &&Editor"), 'workbench.action.splitEditor');
614
		const toggleEditorLayout = this.createMenuItem(nls.localize({ key: 'miToggleEditorLayout', comment: ['&& denotes a mnemonic'] }, "Toggle Editor Group &&Layout"), 'workbench.action.toggleEditorGroupLayout');
B
Benjamin Pasero 已提交
615
		const toggleSidebar = this.createMenuItem(nls.localize({ key: 'miToggleSidebar', comment: ['&& denotes a mnemonic'] }, "&&Toggle Side Bar"), 'workbench.action.toggleSidebarVisibility');
B
Benjamin Pasero 已提交
616 617 618 619 620 621 622 623 624 625

		let moveSideBarLabel: string;
		if (this.currentSidebarLocation !== 'right') {
			moveSideBarLabel = nls.localize({ key: 'miMoveSidebarRight', comment: ['&& denotes a mnemonic'] }, "&&Move Side Bar Right");
		} else {
			moveSideBarLabel = nls.localize({ key: 'miMoveSidebarLeft', comment: ['&& denotes a mnemonic'] }, "&&Move Side Bar Left");
		}

		const moveSidebar = this.createMenuItem(moveSideBarLabel, 'workbench.action.toggleSidebarPosition');

B
Benjamin Pasero 已提交
626
		const togglePanel = this.createMenuItem(nls.localize({ key: 'miTogglePanel', comment: ['&& denotes a mnemonic'] }, "Toggle &&Panel"), 'workbench.action.togglePanel');
B
Benjamin Pasero 已提交
627 628 629 630 631 632 633 634

		let statusBarLabel: string;
		if (this.currentStatusbarVisible) {
			statusBarLabel = nls.localize({ key: 'miHideStatusbar', comment: ['&& denotes a mnemonic'] }, "&&Hide Status Bar");
		} else {
			statusBarLabel = nls.localize({ key: 'miShowStatusbar', comment: ['&& denotes a mnemonic'] }, "&&Show Status Bar");
		}
		const toggleStatusbar = this.createMenuItem(statusBarLabel, 'workbench.action.toggleStatusbarVisibility');
E
Erich Gamma 已提交
635

S
Sanders Lauture 已提交
636 637
		let activityBarLabel: string;
		if (this.currentActivityBarVisible) {
B
Benjamin Pasero 已提交
638
			activityBarLabel = nls.localize({ key: 'miHideActivityBar', comment: ['&& denotes a mnemonic'] }, "Hide &&Activity Bar");
S
Sanders Lauture 已提交
639
		} else {
B
Benjamin Pasero 已提交
640
			activityBarLabel = nls.localize({ key: 'miShowActivityBar', comment: ['&& denotes a mnemonic'] }, "Show &&Activity Bar");
S
Sanders Lauture 已提交
641 642 643
		}
		const toggleActivtyBar = this.createMenuItem(activityBarLabel, 'workbench.action.toggleActivityBarVisibility');

B
Benjamin Pasero 已提交
644
		const toggleWordWrap = this.createMenuItem(nls.localize({ key: 'miToggleWordWrap', comment: ['&& denotes a mnemonic'] }, "Toggle &&Word Wrap"), 'editor.action.toggleWordWrap');
645
		const toggleRenderWhitespace = this.createMenuItem(nls.localize({ key: 'miToggleRenderWhitespace', comment: ['&& denotes a mnemonic'] }, "Toggle &&Render Whitespace"), 'editor.action.toggleRenderWhitespace');
A
Alex Dima 已提交
646
		const toggleRenderControlCharacters = this.createMenuItem(nls.localize({ key: 'miToggleRenderControlCharacters', comment: ['&& denotes a mnemonic'] }, "Toggle &&Control Characters"), 'editor.action.toggleRenderControlCharacter');
647

B
Benjamin Pasero 已提交
648 649 650
		const zoomIn = this.createMenuItem(nls.localize({ key: 'miZoomIn', comment: ['&& denotes a mnemonic'] }, "&&Zoom In"), 'workbench.action.zoomIn');
		const zoomOut = this.createMenuItem(nls.localize({ key: 'miZoomOut', comment: ['&& denotes a mnemonic'] }, "Zoom O&&ut"), 'workbench.action.zoomOut');
		const resetZoom = this.createMenuItem(nls.localize({ key: 'miZoomReset', comment: ['&& denotes a mnemonic'] }, "&&Reset Zoom"), 'workbench.action.zoomReset');
C
Chris Dias 已提交
651

B
Benjamin Pasero 已提交
652
		arrays.coalesce([
653 654
			commands,
			__separator__(),
655 656 657 658
			explorer,
			search,
			git,
			debug,
J
Joao Moreno 已提交
659
			extensions,
660
			additionalViewlets,
661 662 663 664 665
			__separator__(),
			output,
			problems,
			debugConsole,
			integratedTerminal,
C
Chris Dias 已提交
666
			__separator__(),
E
Erich Gamma 已提交
667
			fullscreen,
I
isidor 已提交
668
			toggleZenMode,
B
Benjamin Pasero 已提交
669
			platform.isWindows || platform.isLinux ? toggleMenuBar : void 0,
E
Erich Gamma 已提交
670 671
			__separator__(),
			splitEditor,
672
			toggleEditorLayout,
E
Erich Gamma 已提交
673
			moveSidebar,
B
Benjamin Pasero 已提交
674 675 676
			toggleSidebar,
			togglePanel,
			toggleStatusbar,
S
Sanders Lauture 已提交
677
			toggleActivtyBar,
E
Erich Gamma 已提交
678
			__separator__(),
J
Joao Moreno 已提交
679
			toggleWordWrap,
680
			toggleRenderWhitespace,
681
			toggleRenderControlCharacters,
J
Joao Moreno 已提交
682
			__separator__(),
E
Erich Gamma 已提交
683
			zoomIn,
684 685
			zoomOut,
			resetZoom
B
Benjamin Pasero 已提交
686
		]).forEach(item => viewMenu.append(item));
E
Erich Gamma 已提交
687 688
	}

B
Benjamin Pasero 已提交
689
	private setGotoMenu(gotoMenu: Electron.Menu): void {
B
Benjamin Pasero 已提交
690 691
		const back = this.createMenuItem(nls.localize({ key: 'miBack', comment: ['&& denotes a mnemonic'] }, "&&Back"), 'workbench.action.navigateBack');
		const forward = this.createMenuItem(nls.localize({ key: 'miForward', comment: ['&& denotes a mnemonic'] }, "&&Forward"), 'workbench.action.navigateForward');
B
Benjamin Pasero 已提交
692

B
Benjamin Pasero 已提交
693
		const switchEditorMenu = new Menu();
B
Benjamin Pasero 已提交
694

B
Benjamin Pasero 已提交
695 696 697 698
		const nextEditor = this.createMenuItem(nls.localize({ key: 'miNextEditor', comment: ['&& denotes a mnemonic'] }, "&&Next Editor"), 'workbench.action.nextEditor');
		const previousEditor = this.createMenuItem(nls.localize({ key: 'miPreviousEditor', comment: ['&& denotes a mnemonic'] }, "&&Previous Editor"), 'workbench.action.previousEditor');
		const nextEditorInGroup = this.createMenuItem(nls.localize({ key: 'miNextEditorInGroup', comment: ['&& denotes a mnemonic'] }, "&&Next Used Editor in Group"), 'workbench.action.openNextRecentlyUsedEditorInGroup');
		const previousEditorInGroup = this.createMenuItem(nls.localize({ key: 'miPreviousEditorInGroup', comment: ['&& denotes a mnemonic'] }, "&&Previous Used Editor in Group"), 'workbench.action.openPreviousRecentlyUsedEditorInGroup');
B
Benjamin Pasero 已提交
699 700 701 702 703

		[
			nextEditor,
			previousEditor,
			__separator__(),
704
			nextEditorInGroup,
B
Benjamin Pasero 已提交
705 706 707
			previousEditorInGroup
		].forEach(item => switchEditorMenu.append(item));

B
Benjamin Pasero 已提交
708
		const switchEditor = new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'miSwitchEditor', comment: ['&& denotes a mnemonic'] }, "Switch &&Editor")), submenu: switchEditorMenu, enabled: true });
B
Benjamin Pasero 已提交
709

B
Benjamin Pasero 已提交
710
		const switchGroupMenu = new Menu();
B
Benjamin Pasero 已提交
711

712 713 714
		const focusFirstGroup = this.createMenuItem(nls.localize({ key: 'miFocusFirstGroup', comment: ['&& denotes a mnemonic'] }, "&&First Group"), 'workbench.action.focusFirstEditorGroup');
		const focusSecondGroup = this.createMenuItem(nls.localize({ key: 'miFocusSecondGroup', comment: ['&& denotes a mnemonic'] }, "&&Second Group"), 'workbench.action.focusSecondEditorGroup');
		const focusThirdGroup = this.createMenuItem(nls.localize({ key: 'miFocusThirdGroup', comment: ['&& denotes a mnemonic'] }, "&&Third Group"), 'workbench.action.focusThirdEditorGroup');
B
Benjamin Pasero 已提交
715 716
		const nextGroup = this.createMenuItem(nls.localize({ key: 'miNextGroup', comment: ['&& denotes a mnemonic'] }, "&&Next Group"), 'workbench.action.focusNextGroup');
		const previousGroup = this.createMenuItem(nls.localize({ key: 'miPreviousGroup', comment: ['&& denotes a mnemonic'] }, "&&Previous Group"), 'workbench.action.focusPreviousGroup');
B
Benjamin Pasero 已提交
717 718 719 720 721 722 723 724 725 726

		[
			focusFirstGroup,
			focusSecondGroup,
			focusThirdGroup,
			__separator__(),
			nextGroup,
			previousGroup
		].forEach(item => switchGroupMenu.append(item));

B
Benjamin Pasero 已提交
727
		const switchGroup = new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'miSwitchGroup', comment: ['&& denotes a mnemonic'] }, "Switch &&Group")), submenu: switchGroupMenu, enabled: true });
B
Benjamin Pasero 已提交
728

B
Benjamin Pasero 已提交
729
		const gotoFile = this.createMenuItem(nls.localize({ key: 'miGotoFile', comment: ['&& denotes a mnemonic'] }, "Go to &&File..."), 'workbench.action.quickOpen');
730 731
		const gotoSymbolInFile = this.createMenuItem(nls.localize({ key: 'miGotoSymbolInFile', comment: ['&& denotes a mnemonic'] }, "Go to &&Symbol in File..."), 'workbench.action.gotoSymbol');
		const gotoSymbolInWorkspace = this.createMenuItem(nls.localize({ key: 'miGotoSymbolInWorkspace', comment: ['&& denotes a mnemonic'] }, "Go to Symbol in &&Workspace..."), 'workbench.action.showAllSymbols');
B
Benjamin Pasero 已提交
732 733
		const gotoDefinition = this.createMenuItem(nls.localize({ key: 'miGotoDefinition', comment: ['&& denotes a mnemonic'] }, "Go to &&Definition"), 'editor.action.goToDeclaration');
		const gotoLine = this.createMenuItem(nls.localize({ key: 'miGotoLine', comment: ['&& denotes a mnemonic'] }, "Go to &&Line..."), 'workbench.action.gotoLine');
E
Erich Gamma 已提交
734 735 736 737 738

		[
			back,
			forward,
			__separator__(),
B
Benjamin Pasero 已提交
739 740
			switchEditor,
			switchGroup,
E
Erich Gamma 已提交
741 742
			__separator__(),
			gotoFile,
743 744
			gotoSymbolInFile,
			gotoSymbolInWorkspace,
E
Erich Gamma 已提交
745 746
			gotoDefinition,
			gotoLine
B
Benjamin Pasero 已提交
747
		].forEach(item => gotoMenu.append(item));
E
Erich Gamma 已提交
748 749
	}

B
Benjamin Pasero 已提交
750
	private setMacWindowMenu(macWindowMenu: Electron.Menu): void {
B
Benjamin Pasero 已提交
751 752 753
		const minimize = new MenuItem({ label: nls.localize('mMinimize', "Minimize"), role: 'minimize', accelerator: 'Command+M', enabled: this.windowsService.getWindowCount() > 0 });
		const close = new MenuItem({ label: nls.localize('mClose', "Close"), role: 'close', accelerator: 'Command+W', enabled: this.windowsService.getWindowCount() > 0 });
		const bringAllToFront = new MenuItem({ label: nls.localize('mBringToFront', "Bring All to Front"), role: 'front', enabled: this.windowsService.getWindowCount() > 0 });
E
Erich Gamma 已提交
754 755 756 757 758 759

		[
			minimize,
			close,
			__separator__(),
			bringAllToFront
B
Benjamin Pasero 已提交
760
		].forEach(item => macWindowMenu.append(item));
E
Erich Gamma 已提交
761 762
	}

J
fix npe  
Joao Moreno 已提交
763
	private toggleDevTools(): void {
B
Benjamin Pasero 已提交
764
		const w = this.windowsService.getFocusedWindow();
J
fix npe  
Joao Moreno 已提交
765
		if (w && w.win) {
766 767 768 769 770 771
			const contents = w.win.webContents;
			if (w.hasHiddenTitleBarStyle() && !w.win.isFullScreen() && !contents.isDevToolsOpened()) {
				contents.openDevTools({ mode: 'undocked' }); // due to https://github.com/electron/electron/issues/3647
			} else {
				contents.toggleDevTools();
			}
J
fix npe  
Joao Moreno 已提交
772 773 774
		}
	}

B
Benjamin Pasero 已提交
775
	private setHelpMenu(helpMenu: Electron.Menu): void {
776
		const toggleDevToolsItem = new MenuItem(this.likeAction('workbench.action.toggleDevTools', {
B
Benjamin Pasero 已提交
777
			label: mnemonicLabel(nls.localize({ key: 'miToggleDevTools', comment: ['&& denotes a mnemonic'] }, "&&Toggle Developer Tools")),
J
fix npe  
Joao Moreno 已提交
778
			click: () => this.toggleDevTools(),
B
Benjamin Pasero 已提交
779
			enabled: (this.windowsService.getWindowCount() > 0)
780
		}));
E
Erich Gamma 已提交
781

782
		const showAccessibilityOptions = new MenuItem(this.likeAction('accessibilityOptions', {
783 784 785 786 787
			label: mnemonicLabel(nls.localize({ key: 'miAccessibilityOptions', comment: ['&& denotes a mnemonic'] }, "Accessibility &&Options")),
			accelerator: null,
			click: () => {
				this.windowsService.openAccessibilityOptions();
			}
788
		}, false));
789

B
Benjamin Pasero 已提交
790
		let reportIssuesItem: Electron.MenuItem = null;
B
Benjamin Pasero 已提交
791
		if (product.reportIssueUrl) {
B
Benjamin Pasero 已提交
792 793 794 795 796 797 798 799
			const label = nls.localize({ key: 'miReportIssues', comment: ['&& denotes a mnemonic'] }, "Report &&Issues");

			if (this.windowsService.getWindowCount() > 0) {
				reportIssuesItem = this.createMenuItem(label, 'workbench.action.reportIssues');
			} else {
				reportIssuesItem = new MenuItem({ label: mnemonicLabel(label), click: () => this.openUrl(product.reportIssueUrl, 'openReportIssues') });
			}
		}
J
Joao Moreno 已提交
800

I
isidor 已提交
801
		const keyboardShortcutsUrl = platform.isLinux ? product.keyboardShortcutsUrlLinux : platform.isMacintosh ? product.keyboardShortcutsUrlMac : product.keyboardShortcutsUrlWin;
E
Erich Gamma 已提交
802
		arrays.coalesce([
B
Benjamin Pasero 已提交
803 804 805
			product.documentationUrl ? new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'miDocumentation', comment: ['&& denotes a mnemonic'] }, "&&Documentation")), click: () => this.openUrl(product.documentationUrl, 'openDocumentationUrl') }) : null,
			product.releaseNotesUrl ? new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'miReleaseNotes', comment: ['&& denotes a mnemonic'] }, "&&Release Notes")), click: () => this.windowsService.sendToFocused('vscode:runAction', 'update.showCurrentReleaseNotes') }) : null,
			(product.documentationUrl || product.releaseNotesUrl) ? __separator__() : null,
806
			keyboardShortcutsUrl ? new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'miKeyboardShortcuts', comment: ['&& denotes a mnemonic'] }, "&&Keyboard Shortcuts Reference")), click: () => this.windowsService.sendToFocused('vscode:runAction', 'workbench.action.keybindingsReference') }) : null,
I
isidor 已提交
807
			product.introductoryVideosUrl ? new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'miIntroductoryVideos', comment: ['&& denotes a mnemonic'] }, "Introductory &&Videos")), click: () => this.openUrl(product.introductoryVideosUrl, 'openIntroductoryVideosUrl') }) : null,
I
isidor 已提交
808
			(product.introductoryVideosUrl || keyboardShortcutsUrl) ? __separator__() : null,
B
Benjamin Pasero 已提交
809 810
			product.twitterUrl ? new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'miTwitter', comment: ['&& denotes a mnemonic'] }, "&&Join us on Twitter")), click: () => this.openUrl(product.twitterUrl, 'openTwitterUrl') }) : null,
			product.requestFeatureUrl ? new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'miUserVoice', comment: ['&& denotes a mnemonic'] }, "&&Search Feature Requests")), click: () => this.openUrl(product.requestFeatureUrl, 'openUserVoiceUrl') }) : null,
B
Benjamin Pasero 已提交
811
			reportIssuesItem,
B
Benjamin Pasero 已提交
812 813
			(product.twitterUrl || product.requestFeatureUrl || product.reportIssueUrl) ? __separator__() : null,
			product.licenseUrl ? new MenuItem({
I
isidor 已提交
814
				label: mnemonicLabel(nls.localize({ key: 'miLicense', comment: ['&& denotes a mnemonic'] }, "View &&License")), click: () => {
B
Benjamin Pasero 已提交
815
					if (platform.language) {
B
Benjamin Pasero 已提交
816 817
						const queryArgChar = product.licenseUrl.indexOf('?') > 0 ? '&' : '?';
						this.openUrl(`${product.licenseUrl}${queryArgChar}lang=${platform.language}`, 'openLicenseUrl');
B
Benjamin Pasero 已提交
818
					} else {
B
Benjamin Pasero 已提交
819
						this.openUrl(product.licenseUrl, 'openLicenseUrl');
B
Benjamin Pasero 已提交
820
					}
821
				}
B
Benjamin Pasero 已提交
822
			}) : null,
B
Benjamin Pasero 已提交
823
			product.privacyStatementUrl ? new MenuItem({
824 825
				label: mnemonicLabel(nls.localize({ key: 'miPrivacyStatement', comment: ['&& denotes a mnemonic'] }, "&&Privacy Statement")), click: () => {
					if (platform.language) {
B
Benjamin Pasero 已提交
826 827
						const queryArgChar = product.licenseUrl.indexOf('?') > 0 ? '&' : '?';
						this.openUrl(`${product.privacyStatementUrl}${queryArgChar}lang=${platform.language}`, 'openPrivacyStatement');
828
					} else {
B
Benjamin Pasero 已提交
829
						this.openUrl(product.privacyStatementUrl, 'openPrivacyStatement');
830 831 832
					}
				}
			}) : null,
B
Benjamin Pasero 已提交
833
			(product.licenseUrl || product.privacyStatementUrl) ? __separator__() : null,
E
Erich Gamma 已提交
834
			toggleDevToolsItem,
B
Benjamin Pasero 已提交
835
			platform.isWindows && product.quality !== 'stable' ? showAccessibilityOptions : null
B
Benjamin Pasero 已提交
836
		]).forEach(item => helpMenu.append(item));
E
Erich Gamma 已提交
837 838 839 840 841 842 843 844 845

		if (!platform.isMacintosh) {
			const updateMenuItems = this.getUpdateMenuItems();
			if (updateMenuItems.length) {
				helpMenu.append(__separator__());
				updateMenuItems.forEach(i => helpMenu.append(i));
			}

			helpMenu.append(__separator__());
J
fix npe  
Joao Moreno 已提交
846
			helpMenu.append(new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'miAbout', comment: ['&& denotes a mnemonic'] }, "&&About")), click: () => this.openAboutDialog() }));
E
Erich Gamma 已提交
847 848 849
		}
	}

B
Benjamin Pasero 已提交
850
	private getUpdateMenuItems(): Electron.MenuItem[] {
B
Benjamin Pasero 已提交
851
		switch (this.updateService.state) {
J
Joao Moreno 已提交
852
			case UpdateState.Uninitialized:
E
Erich Gamma 已提交
853 854
				return [];

J
Joao Moreno 已提交
855
			case UpdateState.UpdateDownloaded:
B
Benjamin Pasero 已提交
856 857
				return [new MenuItem({
					label: nls.localize('miRestartToUpdate', "Restart To Update..."), click: () => {
J
fix npe  
Joao Moreno 已提交
858
						this.reportMenuActionTelemetry('RestartToUpdate');
J
Joao Moreno 已提交
859
						this.updateService.quitAndInstall();
B
Benjamin Pasero 已提交
860 861
					}
				})];
E
Erich Gamma 已提交
862

J
Joao Moreno 已提交
863
			case UpdateState.CheckingForUpdate:
E
Erich Gamma 已提交
864 865
				return [new MenuItem({ label: nls.localize('miCheckingForUpdates', "Checking For Updates..."), enabled: false })];

J
Joao Moreno 已提交
866
			case UpdateState.UpdateAvailable:
J
Joao Moreno 已提交
867 868
				if (platform.isLinux) {
					return [new MenuItem({
J
Joao Moreno 已提交
869
						label: nls.localize('miDownloadUpdate', "Download Available Update"), click: () => {
J
Joao Moreno 已提交
870
							this.updateService.quitAndInstall();
J
Joao Moreno 已提交
871 872 873 874
						}
					})];
				}

B
Benjamin Pasero 已提交
875
				const updateAvailableLabel = platform.isWindows
E
Erich Gamma 已提交
876 877 878 879 880 881
					? nls.localize('miDownloadingUpdate', "Downloading Update...")
					: nls.localize('miInstallingUpdate', "Installing Update...");

				return [new MenuItem({ label: updateAvailableLabel, enabled: false })];

			default:
B
Benjamin Pasero 已提交
882
				const result = [new MenuItem({
B
Benjamin Pasero 已提交
883
					label: nls.localize('miCheckForUpdates', "Check For Updates..."), click: () => setTimeout(() => {
J
fix npe  
Joao Moreno 已提交
884
						this.reportMenuActionTelemetry('CheckForUpdate');
J
Joao Moreno 已提交
885
						this.updateService.checkForUpdates(true);
B
Benjamin Pasero 已提交
886 887
					}, 0)
				})];
E
Erich Gamma 已提交
888 889 890 891 892

				return result;
		}
	}

B
Benjamin Pasero 已提交
893 894 895
	private createMenuItem(label: string, actionId: string, enabled?: boolean, checked?: boolean): Electron.MenuItem;
	private createMenuItem(label: string, click: () => void, enabled?: boolean, checked?: boolean): Electron.MenuItem;
	private createMenuItem(arg1: string, arg2: any, arg3?: boolean, arg4?: boolean): Electron.MenuItem {
B
Benjamin Pasero 已提交
896 897 898
		const label = mnemonicLabel(arg1);
		const click: () => void = (typeof arg2 === 'function') ? arg2 : () => this.windowsService.sendToFocused('vscode:runAction', arg2);
		const enabled = typeof arg3 === 'boolean' ? arg3 : this.windowsService.getWindowCount() > 0;
B
Benjamin Pasero 已提交
899
		const checked = typeof arg4 === 'boolean' ? arg4 : false;
E
Erich Gamma 已提交
900

B
Benjamin Pasero 已提交
901
		let actionId: string;
E
Erich Gamma 已提交
902 903 904 905
		if (typeof arg2 === 'string') {
			actionId = arg2;
		}

B
Benjamin Pasero 已提交
906
		const options: Electron.MenuItemOptions = {
B
Benjamin Pasero 已提交
907
			label,
E
Erich Gamma 已提交
908
			accelerator: this.getAccelerator(actionId),
B
Benjamin Pasero 已提交
909 910
			click,
			enabled
E
Erich Gamma 已提交
911 912
		};

B
Benjamin Pasero 已提交
913 914 915 916 917
		if (checked) {
			options['type'] = 'checkbox';
			options['checked'] = checked;
		}

E
Erich Gamma 已提交
918 919 920
		return new MenuItem(options);
	}

921 922 923 924
	private createDevToolsAwareMenuItem(label: string, actionId: string, devToolsFocusedFn: (contents: Electron.WebContents) => void): Electron.MenuItem {
		return new MenuItem({
			label: mnemonicLabel(label),
			accelerator: this.getAccelerator(actionId),
B
Benjamin Pasero 已提交
925
			enabled: this.windowsService.getWindowCount() > 0,
926
			click: () => {
B
Benjamin Pasero 已提交
927
				const windowInFocus = this.windowsService.getFocusedWindow();
928 929 930 931
				if (!windowInFocus) {
					return;
				}

B
Benjamin Pasero 已提交
932 933
				if (windowInFocus.win.webContents.isDevToolsFocused()) {
					devToolsFocusedFn(windowInFocus.win.webContents.devToolsWebContents);
934
				} else {
B
Benjamin Pasero 已提交
935
					this.windowsService.sendToFocused('vscode:runAction', actionId);
936 937 938 939 940
				}
			}
		});
	}

941 942 943 944 945 946 947 948 949 950 951 952 953 954
	private likeAction(actionId: string, options: Electron.MenuItemOptions, setAccelerator = !options.accelerator): Electron.MenuItemOptions {
		if (setAccelerator) {
			options.accelerator = this.getAccelerator(actionId);
		}
		const originalClick = options.click;
		options.click = (item, window, event) => {
			this.reportMenuActionTelemetry(actionId);
			if (originalClick) {
				originalClick(item, window, event);
			}
		};
		return options;
	}

955
	private getAccelerator(actionId: string, fallback?: string): string {
E
Erich Gamma 已提交
956
		if (actionId) {
B
Benjamin Pasero 已提交
957
			const resolvedKeybinding = this.mapResolvedKeybindingToActionId[actionId];
E
Erich Gamma 已提交
958 959 960 961 962 963 964 965
			if (resolvedKeybinding) {
				return resolvedKeybinding; // keybinding is fully resolved
			}

			if (!this.keybindingsResolved) {
				this.actionIdKeybindingRequests.push(actionId); // keybinding needs to be resolved
			}

B
Benjamin Pasero 已提交
966
			const lastKnownKeybinding = this.mapLastKnownKeybindingToActionId[actionId];
967 968 969
			if (lastKnownKeybinding) {
				return lastKnownKeybinding; // return the last known keybining (chance of mismatch is very low unless it changed)
			}
E
Erich Gamma 已提交
970 971
		}

972
		return fallback;
E
Erich Gamma 已提交
973 974
	}

J
fix npe  
Joao Moreno 已提交
975
	private openAboutDialog(): void {
B
Benjamin Pasero 已提交
976
		const lastActiveWindow = this.windowsService.getFocusedWindow() || this.windowsService.getLastActiveWindow();
J
fix npe  
Joao Moreno 已提交
977 978

		dialog.showMessageBox(lastActiveWindow && lastActiveWindow.win, {
B
Benjamin Pasero 已提交
979
			title: product.nameLong,
J
fix npe  
Joao Moreno 已提交
980
			type: 'info',
B
Benjamin Pasero 已提交
981
			message: product.nameLong,
J
fix npe  
Joao Moreno 已提交
982 983 984
			detail: nls.localize('aboutDetail',
				"\nVersion {0}\nCommit {1}\nDate {2}\nShell {3}\nRenderer {4}\nNode {5}",
				app.getVersion(),
B
Benjamin Pasero 已提交
985 986
				product.commit || 'Unknown',
				product.date || 'Unknown',
J
fix npe  
Joao Moreno 已提交
987 988 989 990 991 992
				process.versions['electron'],
				process.versions['chrome'],
				process.versions['node']
			),
			buttons: [nls.localize('okButton', "OK")],
			noLink: true
B
Benjamin Pasero 已提交
993
		}, result => null);
J
fix npe  
Joao Moreno 已提交
994 995 996

		this.reportMenuActionTelemetry('showAboutDialog');
	}
E
Erich Gamma 已提交
997

J
fix npe  
Joao Moreno 已提交
998 999 1000
	private openUrl(url: string, id: string): void {
		shell.openExternal(url);
		this.reportMenuActionTelemetry(id);
E
Erich Gamma 已提交
1001 1002
	}

J
fix npe  
Joao Moreno 已提交
1003
	private reportMenuActionTelemetry(id: string): void {
J
Joao Moreno 已提交
1004
		this.telemetryService.publicLog('workbenchActionExecuted', { id, from: 'menu' });
J
fix npe  
Joao Moreno 已提交
1005
	}
E
Erich Gamma 已提交
1006 1007
}

B
Benjamin Pasero 已提交
1008
function __separator__(): Electron.MenuItem {
E
Erich Gamma 已提交
1009 1010 1011 1012 1013
	return new MenuItem({ type: 'separator' });
}

function mnemonicLabel(label: string): string {
	if (platform.isMacintosh) {
1014
		return label.replace(/\(&&\w\)|&&/g, ''); // no mnemonic support on mac
E
Erich Gamma 已提交
1015 1016 1017 1018
	}

	return label.replace(/&&/g, '&');
}
1019 1020 1021 1022 1023 1024 1025

function unMnemonicLabel(label: string): string {
	if (platform.isMacintosh) {
		return label; // no mnemonic support on mac
	}

	return label.replace(/&/g, '&&');
1026
}