main.contribution.ts 18.5 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
Johannes Rieken 已提交
8
import { Registry } from 'vs/platform/platform';
E
Erich Gamma 已提交
9
import nls = require('vs/nls');
10
import product from 'vs/platform/node/product';
J
Johannes Rieken 已提交
11 12 13 14
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'vs/platform/configuration/common/configurationRegistry';
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actionRegistry';
import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes';
15
import { isWindows, isLinux, isMacintosh } from 'vs/base/common/platform';
16
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
J
Johannes Rieken 已提交
17 18
import { IKeybindings } from 'vs/platform/keybinding/common/keybinding';
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
19
import { IPartService } from 'vs/workbench/services/part/common/partService';
20
import { CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions';
J
Joao Moreno 已提交
21
import { IWindowIPCService } from 'vs/workbench/services/window/electron-browser/windowService';
22
import { CloseEditorAction, KeybindingsReferenceAction, OpenDocumentationUrlAction, OpenIntroductoryVideosUrlAction, ReportIssueAction, ReportPerformanceIssueAction, ZoomResetAction, ZoomOutAction, ZoomInAction, ToggleFullScreenAction, ToggleMenuBarAction, CloseFolderAction, CloseWindowAction, SwitchWindow, NewWindowAction, CloseMessagesAction } from 'vs/workbench/electron-browser/actions';
I
isidor 已提交
23
import { MessagesVisibleContext, NoEditorsVisibleContext, InZenModeContext } from 'vs/workbench/electron-browser/workbench';
24
import { IJSONSchema } from 'vs/base/common/jsonSchema';
25
import { IWindowsService } from 'vs/platform/windows/common/windows';
E
Erich Gamma 已提交
26

J
Johannes Rieken 已提交
27
const closeEditorOrWindowKeybindings: IKeybindings = { primary: KeyMod.CtrlCmd | KeyCode.KEY_W, win: { primary: KeyMod.CtrlCmd | KeyCode.F4, secondary: [KeyMod.CtrlCmd | KeyCode.KEY_W] } };
28

E
Erich Gamma 已提交
29 30
// Contribute Global Actions
const viewCategory = nls.localize('view', "View");
B
Benjamin Pasero 已提交
31
const helpCategory = nls.localize('help', "Help");
B
cleanup  
Benjamin Pasero 已提交
32
const fileCategory = nls.localize('file', "File");
B
Benjamin Pasero 已提交
33
const workbenchActionsRegistry = Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions);
34 35
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(NewWindowAction, NewWindowAction.ID, NewWindowAction.LABEL, { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_N }), 'New Window');
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(CloseWindowAction, CloseWindowAction.ID, CloseWindowAction.LABEL, { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_W }), 'Close Window');
36
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(SwitchWindow, SwitchWindow.ID, SwitchWindow.LABEL), 'Switch Window');
A
Alex Dima 已提交
37
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(CloseFolderAction, CloseFolderAction.ID, CloseFolderAction.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_F) }), 'File: Close Folder', fileCategory);
B
Benjamin Pasero 已提交
38 39
if (!!product.reportIssueUrl) {
	workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ReportIssueAction, ReportIssueAction.ID, ReportIssueAction.LABEL), 'Help: Report Issues', helpCategory);
40
	workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ReportPerformanceIssueAction, ReportPerformanceIssueAction.ID, ReportPerformanceIssueAction.LABEL), 'Help: Report Performance Issues', helpCategory);
B
Benjamin Pasero 已提交
41
}
42
if (KeybindingsReferenceAction.AVAILABLE) {
C
Christof Marti 已提交
43
	workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(KeybindingsReferenceAction, KeybindingsReferenceAction.ID, KeybindingsReferenceAction.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_R) }), 'Help: Keyboard Shortcuts Reference', helpCategory);
44
}
C
Christof Marti 已提交
45 46 47
if (OpenDocumentationUrlAction.AVAILABLE) {
	workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(OpenDocumentationUrlAction, OpenDocumentationUrlAction.ID, OpenDocumentationUrlAction.LABEL), 'Help: Documentation', helpCategory);
}
48 49 50
if (OpenIntroductoryVideosUrlAction.AVAILABLE) {
	workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(OpenIntroductoryVideosUrlAction, OpenIntroductoryVideosUrlAction.ID, OpenIntroductoryVideosUrlAction.LABEL), 'Help: Introductory Videos', helpCategory);
}
51 52 53 54 55
workbenchActionsRegistry.registerWorkbenchAction(
	new SyncActionDescriptor(ZoomInAction, ZoomInAction.ID, ZoomInAction.LABEL, {
		primary: KeyMod.CtrlCmd | KeyCode.US_EQUAL,
		secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_EQUAL, KeyMod.CtrlCmd | KeyCode.NUMPAD_ADD]
	}), 'View: Zoom In', viewCategory);
56 57 58
workbenchActionsRegistry.registerWorkbenchAction(
	new SyncActionDescriptor(ZoomOutAction, ZoomOutAction.ID, ZoomOutAction.LABEL, {
		primary: KeyMod.CtrlCmd | KeyCode.US_MINUS,
59 60
		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] }
61 62
	}), 'View: Zoom Out', viewCategory
);
63 64 65 66 67
workbenchActionsRegistry.registerWorkbenchAction(
	new SyncActionDescriptor(ZoomResetAction, ZoomResetAction.ID, ZoomResetAction.LABEL, {
		primary: KeyMod.CtrlCmd | KeyCode.NUMPAD_0
	}), 'View: Reset Zoom', viewCategory
);
A
Alex Dima 已提交
68
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(CloseMessagesAction, CloseMessagesAction.ID, CloseMessagesAction.LABEL, { primary: KeyCode.Escape, secondary: [KeyMod.Shift | KeyCode.Escape] }, MessagesVisibleContext), 'Close Notification Messages');
69
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(CloseEditorAction, CloseEditorAction.ID, CloseEditorAction.LABEL, closeEditorOrWindowKeybindings), 'View: Close Editor', viewCategory);
70
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleFullScreenAction, ToggleFullScreenAction.ID, ToggleFullScreenAction.LABEL, { primary: KeyCode.F11, mac: { primary: KeyMod.CtrlCmd | KeyMod.WinCtrl | KeyCode.KEY_F } }), 'View: Toggle Full Screen', viewCategory);
71
if (isWindows || isLinux) {
72
	workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleMenuBarAction, ToggleMenuBarAction.ID, ToggleMenuBarAction.LABEL), 'View: Toggle Menu Bar', viewCategory);
73
}
E
Erich Gamma 已提交
74

75
// close the window when the last editor is closed by reusing the same keybinding
A
Alex Dima 已提交
76
KeybindingsRegistry.registerCommandAndKeybindingRule({
77 78
	id: 'workbench.action.closeWindow',
	weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
A
Alex Dima 已提交
79
	when: NoEditorsVisibleContext,
80 81
	primary: closeEditorOrWindowKeybindings.primary,
	handler: accessor => {
J
Joao Moreno 已提交
82
		const windowService = accessor.get(IWindowIPCService);
83 84 85 86
		windowService.getWindow().close();
	}
});

87
KeybindingsRegistry.registerCommandAndKeybindingRule({
I
isidor 已提交
88
	id: 'workbench.action.exitZenMode',
89
	weight: CommonEditorRegistry.commandWeight(-1000),
90 91
	handler(accessor: ServicesAccessor, configurationOrName: any) {
		const partService = accessor.get(IPartService);
I
isidor 已提交
92
		partService.toggleZenMode();
93
	},
I
isidor 已提交
94
	when: InZenModeContext,
I
isidor 已提交
95
	primary: KeyChord(KeyCode.Escape, KeyCode.Escape)
96 97
});

98 99 100 101 102 103 104 105 106
KeybindingsRegistry.registerCommandAndKeybindingRule({
	id: 'workbench.action.quit',
	weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
	handler(accessor: ServicesAccessor) {
		const windowsService = accessor.get(IWindowsService);
		windowsService.quit();
	},
	when: void 0,
	primary: KeyMod.CtrlCmd | KeyCode.KEY_Q,
B
Benjamin Pasero 已提交
107
	win: { primary: void 0 }
108 109
});

110
// Configuration: Workbench
B
Benjamin Pasero 已提交
111
const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
112 113 114 115 116 117 118 119 120 121 122
configurationRegistry.registerConfiguration({
	'id': 'workbench',
	'order': 7,
	'title': nls.localize('workbenchConfigurationTitle', "Workbench"),
	'type': 'object',
	'properties': {
		'workbench.editor.showTabs': {
			'type': 'boolean',
			'description': nls.localize('showEditorTabs', "Controls if opened editors should show in tabs or not."),
			'default': true
		},
123 124 125 126
		'workbench.editor.tabCloseButton': {
			'type': 'string',
			'enum': ['left', 'right', 'off'],
			'default': 'right',
127
			'description': nls.localize('editorTabCloseButton', "Controls the position of the editor's tabs close buttons or disables them when set to 'off'.")
128
		},
129 130
		'workbench.editor.showIcons': {
			'type': 'boolean',
B
Benjamin Pasero 已提交
131
			'description': nls.localize('showIcons', "Controls if opened editors should show with an icon or not. This requires an icon theme to be enabled as well."),
132 133
			'default': true
		},
134 135 136 137 138 139 140
		'workbench.editor.enablePreview': {
			'type': 'boolean',
			'description': nls.localize('enablePreview', "Controls if opened editors show as preview. Preview editors are reused until they are kept (e.g. via double click or editing)."),
			'default': true
		},
		'workbench.editor.enablePreviewFromQuickOpen': {
			'type': 'boolean',
141
			'description': nls.localize('enablePreviewFromQuickOpen', "Controls if opened editors from Quick Open show as preview. Preview editors are reused until they are kept (e.g. via double click or editing)."),
142 143 144 145 146 147 148 149
			'default': true
		},
		'workbench.editor.openPositioning': {
			'type': 'string',
			'enum': ['left', 'right', 'first', 'last'],
			'default': 'right',
			'description': nls.localize('editorOpenPositioning', "Controls where editors open. Select 'left' or 'right' to open editors to the left or right of the current active one. Select 'first' or 'last' to open editors independently from the currently active one.")
		},
150 151
		'workbench.quickOpen.closeOnFocusLost': {
			'type': 'boolean',
152
			'description': nls.localize('closeOnFocusLost', "Controls if Quick Open should close automatically once it loses focus."),
153 154
			'default': true
		},
155 156 157 158
		'workbench.settings.openDefaultSettings': {
			'type': 'boolean',
			'description': nls.localize('openDefaultSettings', "Controls if opening settings also opens an editor showing all default settings."),
			'default': true
159 160 161 162 163 164 165
		},
		'workbench.sideBar.location': {
			'type': 'string',
			'enum': ['left', 'right'],
			'default': 'left',
			'description': nls.localize('sideBarLocation', "Controls the location of the sidebar. It can either show on the left or right of the workbench.")
		},
166 167 168 169
		'workbench.statusBar.visible': {
			'type': 'boolean',
			'default': true,
			'description': nls.localize('statusBarVisibility', "Controls the visibility of the status bar at the bottom of the workbench.")
S
Sanders Lauture 已提交
170
		},
S
Sanders Lauture 已提交
171
		'workbench.activityBar.visible': {
S
Sanders Lauture 已提交
172 173
			'type': 'boolean',
			'default': true,
B
Benjamin Pasero 已提交
174
			'description': nls.localize('activityBarVisibility', "Controls the visibility of the activity bar in the workbench.")
175
		}
176 177 178 179
	}
});

// Configuration: Window
180 181
let properties: { [path: string]: IJSONSchema; } = {
	'window.openFilesInNewWindow': {
182 183
		'type': 'string',
		'enum': ['on', 'off', 'default'],
184 185
		'enumDescriptions': [
			nls.localize('window.openFilesInNewWindow.on', "\"on\": files will open in a new window"),
C
chrmarti 已提交
186 187
			nls.localize('window.openFilesInNewWindow.off', "\"off\": files will open in the window with the files' folder open or the last active window"),
			nls.localize('window.openFilesInNewWindow.default', "\"default\": files will open in the window with the files' folder open or the last active window unless opened via the dock or from finder (macOS only)")
188
		],
189
		'default': 'default',
190 191
		'description':
		nls.localize('openFilesInNewWindow',
C
chrmarti 已提交
192 193
			`Controls if files should open in a new window.
- default: files will open in the window with the files' folder open or the last active window unless opened via the dock or from finder (macOS only)
194
- on: files will open in a new window
C
chrmarti 已提交
195
- off: files will open in the window with the files' folder open or the last active window
196
Note that there can still be cases where this setting is ignored (e.g. when using the -new-window or -reuse-window command line option).`
197
		)
198
	},
199
	'window.openFoldersInNewWindow': {
200 201
		'type': 'string',
		'enum': ['on', 'off', 'default'],
202 203 204 205 206
		'enumDescriptions': [
			nls.localize('window.openFoldersInNewWindow.on', "\"on\": folders will open in a new window"),
			nls.localize('window.openFoldersInNewWindow.off', "\"off\": folders will replace the last active window"),
			nls.localize('window.openFoldersInNewWindow.default', "\"default\": folders will open in a new window unless a folder is picked from within the application (e.g. via the File menu)")
		],
207 208
		'default': 'default',
		'description': nls.localize('openFoldersInNewWindow',
B
Benjamin Pasero 已提交
209
			`Controls if folders should open in a new window or replace the last active window.
210 211
- default: folders will open in a new window unless a folder is picked from within the application (e.g. via the File menu)
- on: folders will open in a new window
B
Benjamin Pasero 已提交
212
- off: folders will replace the last active window
213 214
Note that there can still be cases where this setting is ignored (e.g. when using the -new-window or -reuse-window command line option).`
		)
215 216 217 218
	},
	'window.reopenFolders': {
		'type': 'string',
		'enum': ['none', 'one', 'all'],
219 220 221 222 223
		'enumDescriptions': [
			nls.localize('window.reopenFolders.none', "\"none\": Never reopen a folder."),
			nls.localize('window.reopenFolders.one', "\"one\": Reopen the last active folder."),
			nls.localize('window.reopenFolders.all', "\"all\": Reopen all folders of the last session."),
		],
224 225 226 227 228 229 230 231 232 233 234 235 236
		'default': 'one',
		'description': nls.localize('reopenFolders', "Controls how folders are being reopened after a restart. Select 'none' to never reopen a folder, 'one' to reopen the last folder you worked on or 'all' to reopen all folders of your last session.")
	},
	'window.restoreFullscreen': {
		'type': 'boolean',
		'default': false,
		'description': nls.localize('restoreFullscreen', "Controls if a window should restore to full screen mode if it was exited in full screen mode.")
	},
	'window.zoomLevel': {
		'type': 'number',
		'default': 0,
		'description': nls.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.")
	},
237 238
	'window.title': {
		'type': 'string',
239
		'default': isMacintosh ? '${activeEditorName}${separator}${rootName}' : '${dirty}${activeEditorName}${separator}${rootName}${separator}${appName}',
240 241
		'description': nls.localize('title',
			`Controls the window title based on the active editor. Variables are substituted based on the context:
242 243 244 245 246 247 248
\${activeEditorName}: e.g. myFile.txt
\${activeFilePath}: e.g. /Users/Development/myProject/myFile.txt
\${rootName}: e.g. myProject
\${rootPath}: e.g. /Users/Development/myProject
\${appName}: e.g. VS Code
\${dirty}: a dirty indicator if the active editor is dirty
\${separator}: a conditional separator (" - ") that only shows when surrounded by variables with values`)
249 250 251 252
	},
	'window.newWindowDimensions': {
		'type': 'string',
		'enum': ['default', 'inherit', 'maximized', 'fullscreen'],
253 254 255 256 257 258
		'enumDescriptions': [
			nls.localize('window.newWindowDimensions.default', "\"default\": Open new windows in the center of the screen."),
			nls.localize('window.newWindowDimensions.inherit', "\"inherit\": Open new windows with same dimension as last active one."),
			nls.localize('window.newWindowDimensions.maximized', "\"maximized\": Open new windows maximized."),
			nls.localize('window.newWindowDimensions.fullscreen', "\"fullscreen\": Open new windows in full screen mode.")
		],
259 260 261
		'default': 'default',
		'description': nls.localize('newWindowDimensions', "Controls the dimensions of opening a new window. By default, a new window will open in the center of the screen with small dimensions. When set to  'inherit', the window will get the same dimensions as the last active one. When set to 'maximized', the window will open maximized and fullscreen if configured to 'fullscreen'.")
	},
262 263
};

264
if (isWindows || isLinux) {
265 266
	properties['window.menuBarVisibility'] = {
		'type': 'string',
267
		'enum': ['default', 'visible', 'toggle', 'hidden'],
268 269 270 271 272 273
		'enumDescriptions': [
			nls.localize('window.menuBarVisibility.default', "\"default\": Menu is only hidden in full screen mode."),
			nls.localize('window.menuBarVisibility.visible', "\"visible\": Menu is always visible even in full screen mode."),
			nls.localize('window.menuBarVisibility.toggle', "\"toggle\": Menu is hidden but can be displayed via Alt key."),
			nls.localize('window.menuBarVisibility.hidden', "\"hidden\": Menu is always hidden.")
		],
274 275
		'default': 'default',
		'description': nls.localize('menuBarVisibility', "Control the visibility of the menu bar. A setting of 'toggle' means that the menu bar is hidden and a single press of the Alt key will show it. By default, the menu bar will be visible, unless the window is full screen.")
276 277
	};
}
278

279
if (isWindows) {
280 281 282
	properties['window.autoDetectHighContrast'] = {
		'type': 'boolean',
		'default': true,
283 284
		'description': nls.localize('autoDetectHighContrast', "If enabled, will automatically change to high contrast theme if Windows is using a high contrast theme, and to dark theme when switching away from a Windows high contrast theme."),
	};
285 286
}

287
if (isMacintosh) {
288 289 290 291 292 293 294 295
	properties['window.titleBarStyle'] = {
		'type': 'string',
		'enum': ['native', 'custom'],
		'default': 'custom',
		'description': nls.localize('titleBarStyle', "Adjust the appearance of the window title bar. Changes require a full restart to apply.")
	};
}

E
Erich Gamma 已提交
296 297
configurationRegistry.registerConfiguration({
	'id': 'window',
298
	'order': 8,
299
	'title': nls.localize('windowConfigurationTitle', "Window"),
E
Erich Gamma 已提交
300
	'type': 'object',
301
	'properties': properties
302
});
I
isidor 已提交
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324

// Configuration: Zen Mode
configurationRegistry.registerConfiguration({
	'id': 'zenMode',
	'order': 9,
	'title': nls.localize('zenModeConfigurationTitle', "Zen Mode"),
	'type': 'object',
	'properties': {
		'zenMode.fullScreen': {
			'type': 'boolean',
			'default': true,
			'description': nls.localize('zenMode.fullScreen', "Controls if turning on Zen Mode also puts the workbench into full screen mode.")
		},
		'zenMode.hideTabs': {
			'type': 'boolean',
			'default': true,
			'description': nls.localize('zenMode.hideTabs', "Controls if turning on Zen Mode also hides workbench tabs.")
		},
		'zenMode.hideStatusBar': {
			'type': 'boolean',
			'default': true,
			'description': nls.localize('zenMode.hideStatusBar', "Controls if turning on Zen Mode also hides the status bar at the bottom of the workbench.")
I
isidor 已提交
325 326 327 328 329
		},
		'zenMode.restore': {
			'type': 'boolean',
			'default': false,
			'description': nls.localize('zenMode.restore', "Controls if a window should restore to zen mode if it was exited in zen mode.")
I
isidor 已提交
330 331
		}
	}
I
isidor 已提交
332
});