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

6
import { Registry } from 'vs/platform/registry/common/platform';
7 8 9
import { localize } from 'vs/nls';
import product from 'vs/platform/product/common/product';
import { SyncActionDescriptor, MenuRegistry, MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
10
import { IConfigurationRegistry, Extensions as ConfigurationExtensions, ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
11
import { IWorkbenchActionRegistry, Extensions, CATEGORIES } from 'vs/workbench/common/actions';
12
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
13
import { isLinux, isMacintosh } from 'vs/base/common/platform';
14
import { ConfigureRuntimeArgumentsAction, ToggleDevToolsAction, ToggleSharedProcessAction } from 'vs/workbench/electron-sandbox/actions/developerActions';
15
import { ZoomResetAction, ZoomOutAction, ZoomInAction, CloseCurrentWindowAction, SwitchWindow, QuickSwitchWindow, ReloadWindowWithExtensionsDisabledAction, NewWindowTabHandler, ShowPreviousWindowTabHandler, ShowNextWindowTabHandler, MoveWindowTabToNewWindowHandler, MergeWindowTabsHandlerHandler, ToggleWindowTabsBarHandler } from 'vs/workbench/electron-sandbox/actions/windowActions';
16
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
17
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
S
Sandeep Somavarapu 已提交
18
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
19
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
20
import { IsMacContext } from 'vs/platform/contextkey/common/contextkeys';
21
import { EditorsVisibleContext, SingleEditorGroupsContext } from 'vs/workbench/common/editor';
22
import { INativeHostService } from 'vs/platform/native/electron-sandbox/native';
23
import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
24
import { IJSONSchema } from 'vs/base/common/jsonSchema';
E
Erich Gamma 已提交
25

B
Benjamin Pasero 已提交
26 27 28 29
// Actions
(function registerActions(): void {
	const registry = Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions);

B
Benjamin Pasero 已提交
30 31
	// Actions: Zoom
	(function registerZoomActions(): void {
32 33 34
		registry.registerWorkbenchAction(SyncActionDescriptor.from(ZoomInAction, { primary: KeyMod.CtrlCmd | KeyCode.US_EQUAL, secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_EQUAL, KeyMod.CtrlCmd | KeyCode.NUMPAD_ADD] }), 'View: Zoom In', CATEGORIES.View.value);
		registry.registerWorkbenchAction(SyncActionDescriptor.from(ZoomOutAction, { primary: KeyMod.CtrlCmd | KeyCode.US_MINUS, secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_MINUS, KeyMod.CtrlCmd | KeyCode.NUMPAD_SUBTRACT], linux: { primary: KeyMod.CtrlCmd | KeyCode.US_MINUS, secondary: [KeyMod.CtrlCmd | KeyCode.NUMPAD_SUBTRACT] } }), 'View: Zoom Out', CATEGORIES.View.value);
		registry.registerWorkbenchAction(SyncActionDescriptor.from(ZoomResetAction, { primary: KeyMod.CtrlCmd | KeyCode.NUMPAD_0 }), 'View: Reset Zoom', CATEGORIES.View.value);
B
Benjamin Pasero 已提交
35 36 37 38
	})();

	// Actions: Window
	(function registerWindowActions(): void {
39 40 41
		registry.registerWorkbenchAction(SyncActionDescriptor.from(CloseCurrentWindowAction, { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_W }), 'Close Window');
		registry.registerWorkbenchAction(SyncActionDescriptor.from(SwitchWindow, { primary: 0, mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_W } }), 'Switch Window...');
		registry.registerWorkbenchAction(SyncActionDescriptor.from(QuickSwitchWindow), 'Quick Switch Window...');
B
Benjamin Pasero 已提交
42 43

		KeybindingsRegistry.registerCommandAndKeybindingRule({
44
			id: CloseCurrentWindowAction.ID, // close the window when the last editor is closed by reusing the same keybinding
B
Benjamin Pasero 已提交
45
			weight: KeybindingWeight.WorkbenchContrib,
46
			when: ContextKeyExpr.and(EditorsVisibleContext.toNegated(), SingleEditorGroupsContext),
B
Benjamin Pasero 已提交
47 48
			primary: KeyMod.CtrlCmd | KeyCode.KEY_W,
			handler: accessor => {
49 50
				const nativeHostService = accessor.get(INativeHostService);
				nativeHostService.closeWindow();
B
Benjamin Pasero 已提交
51 52 53 54 55 56 57
			}
		});

		KeybindingsRegistry.registerCommandAndKeybindingRule({
			id: 'workbench.action.quit',
			weight: KeybindingWeight.WorkbenchContrib,
			handler(accessor: ServicesAccessor) {
58 59
				const nativeHostService = accessor.get(INativeHostService);
				nativeHostService.quit();
B
Benjamin Pasero 已提交
60 61
			},
			when: undefined,
62 63
			mac: { primary: KeyMod.CtrlCmd | KeyCode.KEY_Q },
			linux: { primary: KeyMod.CtrlCmd | KeyCode.KEY_Q }
B
Benjamin Pasero 已提交
64 65 66 67 68 69 70
		});
	})();

	// Actions: macOS Native Tabs
	(function registerMacOSNativeTabsActions(): void {
		if (isMacintosh) {
			[
71 72 73 74 75 76
				{ handler: NewWindowTabHandler, id: 'workbench.action.newWindowTab', title: { value: localize('newTab', "New Window Tab"), original: 'New Window Tab' } },
				{ handler: ShowPreviousWindowTabHandler, id: 'workbench.action.showPreviousWindowTab', title: { value: localize('showPreviousTab', "Show Previous Window Tab"), original: 'Show Previous Window Tab' } },
				{ handler: ShowNextWindowTabHandler, id: 'workbench.action.showNextWindowTab', title: { value: localize('showNextWindowTab', "Show Next Window Tab"), original: 'Show Next Window Tab' } },
				{ handler: MoveWindowTabToNewWindowHandler, id: 'workbench.action.moveWindowTabToNewWindow', title: { value: localize('moveWindowTabToNewWindow', "Move Window Tab to New Window"), original: 'Move Window Tab to New Window' } },
				{ handler: MergeWindowTabsHandlerHandler, id: 'workbench.action.mergeAllWindowTabs', title: { value: localize('mergeAllWindowTabs', "Merge All Windows"), original: 'Merge All Windows' } },
				{ handler: ToggleWindowTabsBarHandler, id: 'workbench.action.toggleWindowTabsBar', title: { value: localize('toggleWindowTabsBar', "Toggle Window Tabs Bar"), original: 'Toggle Window Tabs Bar' } }
B
Benjamin Pasero 已提交
77 78 79 80 81
			].forEach(command => {
				CommandsRegistry.registerCommand(command.id, command.handler);

				MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
					command,
82
					when: ContextKeyExpr.equals('config.window.nativeTabs', true)
B
Benjamin Pasero 已提交
83 84
				});
			});
85
		}
B
Benjamin Pasero 已提交
86 87 88 89
	})();

	// Actions: Developer
	(function registerDeveloperActions(): void {
90
		registry.registerWorkbenchAction(SyncActionDescriptor.from(ReloadWindowWithExtensionsDisabledAction), 'Developer: Reload With Extensions Disabled', CATEGORIES.Developer.value);
B
Benjamin Pasero 已提交
91

92 93 94
		registerAction2(ConfigureRuntimeArgumentsAction);
		registerAction2(ToggleSharedProcessAction);
		registerAction2(ToggleDevToolsAction);
B
Benjamin Pasero 已提交
95
	})();
B
Benjamin Pasero 已提交
96 97 98 99 100 101 102 103
})();

// Menu
(function registerMenu(): void {
	MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
		group: '6_close',
		command: {
			id: CloseCurrentWindowAction.ID,
104
			title: localize({ key: 'miCloseWindow', comment: ['&& denotes a mnemonic'] }, "Clos&&e Window")
B
Benjamin Pasero 已提交
105 106 107 108 109 110 111 112
		},
		order: 4
	});

	MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
		group: 'z_Exit',
		command: {
			id: 'workbench.action.quit',
113
			title: localize({ key: 'miExit', comment: ['&& denotes a mnemonic'] }, "E&&xit")
B
Benjamin Pasero 已提交
114 115 116
		},
		order: 1,
		when: IsMacContext.toNegated()
A
Alex Ross 已提交
117
	});
B
Benjamin Pasero 已提交
118 119 120 121 122 123 124

	// Zoom

	MenuRegistry.appendMenuItem(MenuId.MenubarAppearanceMenu, {
		group: '3_zoom',
		command: {
			id: ZoomInAction.ID,
125
			title: localize({ key: 'miZoomIn', comment: ['&& denotes a mnemonic'] }, "&&Zoom In")
126
		},
B
Benjamin Pasero 已提交
127 128 129 130 131 132 133
		order: 1
	});

	MenuRegistry.appendMenuItem(MenuId.MenubarAppearanceMenu, {
		group: '3_zoom',
		command: {
			id: ZoomOutAction.ID,
134
			title: localize({ key: 'miZoomOut', comment: ['&& denotes a mnemonic'] }, "&&Zoom Out")
135
		},
B
Benjamin Pasero 已提交
136 137 138 139 140 141 142
		order: 2
	});

	MenuRegistry.appendMenuItem(MenuId.MenubarAppearanceMenu, {
		group: '3_zoom',
		command: {
			id: ZoomResetAction.ID,
143
			title: localize({ key: 'miZoomReset', comment: ['&& denotes a mnemonic'] }, "&&Reset Zoom")
144
		},
B
Benjamin Pasero 已提交
145 146 147
		order: 3
	});

148 149 150 151 152
	if (!!product.reportIssueUrl) {
		MenuRegistry.appendMenuItem(MenuId.MenubarHelpMenu, {
			group: '3_feedback',
			command: {
				id: 'workbench.action.openIssueReporter',
153
				title: localize({ key: 'miReportIssue', comment: ['&& denotes a mnemonic', 'Translate this to "Report Issue in English" in all languages please!'] }, "Report &&Issue")
154 155 156 157
			},
			order: 3
		});
	}
B
Benjamin Pasero 已提交
158 159 160 161 162 163

	// Tools
	MenuRegistry.appendMenuItem(MenuId.MenubarHelpMenu, {
		group: '5_tools',
		command: {
			id: 'workbench.action.openProcessExplorer',
164
			title: localize({ key: 'miOpenProcessExplorerer', comment: ['&& denotes a mnemonic'] }, "Open &&Process Explorer")
165
		},
B
Benjamin Pasero 已提交
166 167 168 169 170 171 172 173 174 175 176 177
		order: 2
	});
})();

// Configuration
(function registerConfiguration(): void {
	const registry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);

	// Window
	registry.registerConfiguration({
		'id': 'window',
		'order': 8,
178
		'title': localize('windowConfigurationTitle', "Window"),
B
Benjamin Pasero 已提交
179 180 181 182 183 184
		'type': 'object',
		'properties': {
			'window.openWithoutArgumentsInNewWindow': {
				'type': 'string',
				'enum': ['on', 'off'],
				'enumDescriptions': [
185 186
					localize('window.openWithoutArgumentsInNewWindow.on', "Open a new empty window."),
					localize('window.openWithoutArgumentsInNewWindow.off', "Focus the last active running instance.")
B
Benjamin Pasero 已提交
187 188 189
				],
				'default': isMacintosh ? 'off' : 'on',
				'scope': ConfigurationScope.APPLICATION,
190
				'markdownDescription': localize('openWithoutArgumentsInNewWindow', "Controls whether a new empty window should open when starting a second instance without arguments or if the last running instance should get focus.\nNote that there can still be cases where this setting is ignored (e.g. when using the `--new-window` or `--reuse-window` command line option).")
B
Benjamin Pasero 已提交
191 192 193
			},
			'window.restoreWindows': {
				'type': 'string',
194
				'enum': ['preserve', 'all', 'folders', 'one', 'none'],
B
Benjamin Pasero 已提交
195
				'enumDescriptions': [
196 197 198 199 200
					localize('window.reopenFolders.preserve', "Always reopen all windows. If a folder or workspace is opened (e.g. from the command line) it opens as a new window unless it was opened before. If files are opened they will open in one of the restored windows."),
					localize('window.reopenFolders.all', "Reopen all windows unless a folder, workspace or file is opened (e.g. from the command line)."),
					localize('window.reopenFolders.folders', "Reopen all windows that had folders or workspaces opened unless a folder, workspace or file is opened (e.g. from the command line)."),
					localize('window.reopenFolders.one', "Reopen the last active window unless a folder, workspace or file is opened (e.g. from the command line)."),
					localize('window.reopenFolders.none', "Never reopen a window. Unless a folder or workspace is opened (e.g. from the command line), an empty window will appear.")
B
Benjamin Pasero 已提交
201
				],
202
				'default': 'all',
B
Benjamin Pasero 已提交
203
				'scope': ConfigurationScope.APPLICATION,
204
				'description': localize('restoreWindows', "Controls how windows are being reopened after starting for the first time. This setting has no effect when the application is already running.")
B
Benjamin Pasero 已提交
205 206 207 208 209
			},
			'window.restoreFullscreen': {
				'type': 'boolean',
				'default': false,
				'scope': ConfigurationScope.APPLICATION,
210
				'description': localize('restoreFullscreen', "Controls whether a window should restore to full screen mode if it was exited in full screen mode.")
B
Benjamin Pasero 已提交
211 212 213 214
			},
			'window.zoomLevel': {
				'type': 'number',
				'default': 0,
215
				'description': localize('zoomLevel', "Adjust the zoom level of the window. The original size is 0 and each increment above (e.g. 1) or below (e.g. -1) represents zooming 20% larger or smaller. You can also enter decimals to adjust the zoom level with a finer granularity."),
S
Sandeep Somavarapu 已提交
216
				ignoreSync: true
B
Benjamin Pasero 已提交
217 218 219
			},
			'window.newWindowDimensions': {
				'type': 'string',
S
SteVen Batten 已提交
220
				'enum': ['default', 'inherit', 'offset', 'maximized', 'fullscreen'],
B
Benjamin Pasero 已提交
221
				'enumDescriptions': [
222 223 224 225 226
					localize('window.newWindowDimensions.default', "Open new windows in the center of the screen."),
					localize('window.newWindowDimensions.inherit', "Open new windows with same dimension as last active one."),
					localize('window.newWindowDimensions.offset', "Open new windows with same dimension as last active one with an offset position."),
					localize('window.newWindowDimensions.maximized', "Open new windows maximized."),
					localize('window.newWindowDimensions.fullscreen', "Open new windows in full screen mode.")
B
Benjamin Pasero 已提交
227 228 229
				],
				'default': 'default',
				'scope': ConfigurationScope.APPLICATION,
230
				'description': localize('newWindowDimensions', "Controls the dimensions of opening a new window when at least one window is already opened. Note that this setting does not have an impact on the first window that is opened. The first window will always restore the size and location as you left it before closing.")
B
Benjamin Pasero 已提交
231 232 233 234
			},
			'window.closeWhenEmpty': {
				'type': 'boolean',
				'default': false,
235
				'description': localize('closeWhenEmpty', "Controls whether closing the last editor should also close the window. This setting only applies for windows that do not show folders.")
B
Benjamin Pasero 已提交
236 237 238 239 240
			},
			'window.doubleClickIconToClose': {
				'type': 'boolean',
				'default': false,
				'scope': ConfigurationScope.APPLICATION,
241
				'markdownDescription': localize('window.doubleClickIconToClose', "If enabled, double clicking the application icon in the title bar will close the window and the window cannot be dragged by the icon. This setting only has an effect when `#window.titleBarStyle#` is set to `custom`.")
B
Benjamin Pasero 已提交
242 243 244 245 246 247
			},
			'window.titleBarStyle': {
				'type': 'string',
				'enum': ['native', 'custom'],
				'default': isLinux ? 'native' : 'custom',
				'scope': ConfigurationScope.APPLICATION,
248
				'description': localize('titleBarStyle', "Adjust the appearance of the window title bar. On Linux and Windows, this setting also affects the application and context menu appearances. Changes require a full restart to apply.")
B
Benjamin Pasero 已提交
249
			},
250 251 252 253 254
			'window.dialogStyle': {
				'type': 'string',
				'enum': ['native', 'custom'],
				'default': 'native',
				'scope': ConfigurationScope.APPLICATION,
255
				'description': localize('dialogStyle', "Adjust the appearance of dialog windows.")
256
			},
B
Benjamin Pasero 已提交
257 258 259 260
			'window.nativeTabs': {
				'type': 'boolean',
				'default': false,
				'scope': ConfigurationScope.APPLICATION,
261
				'description': localize('window.nativeTabs', "Enables macOS Sierra window tabs. Note that changes require a full restart to apply and that native tabs will disable a custom title bar style if configured."),
262
				'included': isMacintosh
B
Benjamin Pasero 已提交
263 264 265 266
			},
			'window.nativeFullScreen': {
				'type': 'boolean',
				'default': true,
267
				'description': localize('window.nativeFullScreen', "Controls if native full-screen should be used on macOS. Disable this option to prevent macOS from creating a new space when going full-screen."),
268
				'scope': ConfigurationScope.APPLICATION,
269
				'included': isMacintosh
B
Benjamin Pasero 已提交
270 271 272 273 274
			},
			'window.clickThroughInactive': {
				'type': 'boolean',
				'default': true,
				'scope': ConfigurationScope.APPLICATION,
275
				'description': localize('window.clickThroughInactive', "If enabled, clicking on an inactive window will both activate the window and trigger the element under the mouse if it is clickable. If disabled, clicking anywhere on an inactive window will activate it only and a second click is required on the element."),
B
Benjamin Pasero 已提交
276 277
				'included': isMacintosh
			}
278
		}
B
Benjamin Pasero 已提交
279 280 281 282 283 284
	});

	// Telemetry
	registry.registerConfiguration({
		'id': 'telemetry',
		'order': 110,
285
		title: localize('telemetryConfigurationTitle', "Telemetry"),
B
Benjamin Pasero 已提交
286 287 288 289
		'type': 'object',
		'properties': {
			'telemetry.enableCrashReporter': {
				'type': 'boolean',
290
				'description': localize('telemetry.enableCrashReporting', "Enable crash reports to be sent to a Microsoft online service. \nThis option requires restart to take effect."),
B
Benjamin Pasero 已提交
291 292 293
				'default': true,
				'tags': ['usesOnlineServices']
			}
294
		}
B
Benjamin Pasero 已提交
295
	});
296 297 298 299 300 301

	// Keybinding
	registry.registerConfiguration({
		'id': 'keyboard',
		'order': 15,
		'type': 'object',
302
		'title': localize('keyboardConfigurationTitle', "Keyboard"),
303 304 305 306
		'properties': {
			'keyboard.touchbar.enabled': {
				'type': 'boolean',
				'default': true,
307
				'description': localize('touchbar.enabled', "Enables the macOS touchbar buttons on the keyboard if available."),
308 309 310 311 312 313 314 315
				'included': isMacintosh
			},
			'keyboard.touchbar.ignored': {
				'type': 'array',
				'items': {
					'type': 'string'
				},
				'default': [],
316
				'markdownDescription': localize('touchbar.ignored', 'A set of identifiers for entries in the touchbar that should not show up (for example `workbench.action.navigateBack`.'),
317 318 319 320
				'included': isMacintosh
			}
		}
	});
321
})();
322 323 324 325 326

// JSON Schemas
(function registerJSONSchemas(): void {
	const argvDefinitionFileSchemaId = 'vscode://schemas/argv';
	const jsonRegistry = Registry.as<IJSONContributionRegistry>(JSONExtensions.JSONContribution);
327
	const schema: IJSONSchema = {
328 329 330 331 332 333 334 335 336
		id: argvDefinitionFileSchemaId,
		allowComments: true,
		allowTrailingCommas: true,
		description: 'VSCode static command line definition file',
		type: 'object',
		additionalProperties: false,
		properties: {
			locale: {
				type: 'string',
337
				description: localize('argv.locale', 'The display Language to use. Picking a different language requires the associated language pack to be installed.')
338 339 340
			},
			'disable-hardware-acceleration': {
				type: 'boolean',
341
				description: localize('argv.disableHardwareAcceleration', 'Disables hardware acceleration. ONLY change this option if you encounter graphic issues.')
342 343 344
			},
			'disable-color-correct-rendering': {
				type: 'boolean',
345
				description: localize('argv.disableColorCorrectRendering', 'Resolves issues around color profile selection. ONLY change this option if you encounter graphic issues.')
346 347 348
			},
			'force-color-profile': {
				type: 'string',
349
				markdownDescription: localize('argv.forceColorProfile', 'Allows to override the color profile to use. If you experience colors appear badly, try to set this to `srgb` and restart.')
350
			},
R
Robo 已提交
351 352
			'enable-crash-reporter': {
				type: 'boolean',
353
				markdownDescription: localize('argv.enableCrashReporter', 'Allows to disable crash reporting, should restart the app if the value is changed.')
R
Robo 已提交
354 355 356
			},
			'crash-reporter-id': {
				type: 'string',
357
				markdownDescription: localize('argv.crashReporterId', 'Unique id used for correlating crash reports sent from this app instance.')
R
Robo 已提交
358
			},
359 360
			'enable-proposed-api': {
				type: 'array',
361
				description: localize('argv.enebleProposedApi', "Enable proposed APIs for a list of extension ids (such as \`vscode.git\`). Proposed APIs are unstable and subject to breaking without warning at any time. This should only be set for extension development and testing purposes."),
362 363 364
				items: {
					type: 'string'
				}
365 366
			}
		}
367 368 369 370
	};
	if (isLinux) {
		schema.properties!['force-renderer-accessibility'] = {
			type: 'boolean',
371
			description: localize('argv.force-renderer-accessibility', 'Forces the renderer to be accessible. ONLY change this if you are using a screen reader on Linux. On other platforms the renderer will automatically be accessible. This flag is automatically set if you have editor.accessibilitySupport: on.'),
372 373 374 375
		};
	}

	jsonRegistry.registerSchema(argvDefinitionFileSchemaId, schema);
376
})();