main.contribution.ts 12.2 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 platform = require('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, ReportIssueAction, 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 40
if (!!product.reportIssueUrl) {
	workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ReportIssueAction, ReportIssueAction.ID, ReportIssueAction.LABEL), 'Help: Report Issues', helpCategory);
}
41
if (KeybindingsReferenceAction.AVAILABLE) {
C
Christof Marti 已提交
42
	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);
43
}
44 45 46 47 48
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);
49 50 51
workbenchActionsRegistry.registerWorkbenchAction(
	new SyncActionDescriptor(ZoomOutAction, ZoomOutAction.ID, ZoomOutAction.LABEL, {
		primary: KeyMod.CtrlCmd | KeyCode.US_MINUS,
52 53
		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] }
54 55
	}), 'View: Zoom Out', viewCategory
);
56 57 58 59 60
workbenchActionsRegistry.registerWorkbenchAction(
	new SyncActionDescriptor(ZoomResetAction, ZoomResetAction.ID, ZoomResetAction.LABEL, {
		primary: KeyMod.CtrlCmd | KeyCode.NUMPAD_0
	}), 'View: Reset Zoom', viewCategory
);
A
Alex Dima 已提交
61
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(CloseMessagesAction, CloseMessagesAction.ID, CloseMessagesAction.LABEL, { primary: KeyCode.Escape, secondary: [KeyMod.Shift | KeyCode.Escape] }, MessagesVisibleContext), 'Close Notification Messages');
62
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(CloseEditorAction, CloseEditorAction.ID, CloseEditorAction.LABEL, closeEditorOrWindowKeybindings), 'View: Close Editor', viewCategory);
63
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);
64
if (platform.isWindows || platform.isLinux) {
65
	workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleMenuBarAction, ToggleMenuBarAction.ID, ToggleMenuBarAction.LABEL), 'View: Toggle Menu Bar', viewCategory);
66
}
E
Erich Gamma 已提交
67

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

80
KeybindingsRegistry.registerCommandAndKeybindingRule({
I
isidor 已提交
81
	id: 'workbench.action.exitZenMode',
82
	weight: CommonEditorRegistry.commandWeight(-1000),
83 84
	handler(accessor: ServicesAccessor, configurationOrName: any) {
		const partService = accessor.get(IPartService);
I
isidor 已提交
85
		partService.toggleZenMode();
86
	},
I
isidor 已提交
87
	when: InZenModeContext,
I
isidor 已提交
88
	primary: KeyChord(KeyCode.Escape, KeyCode.Escape)
89 90
});

91 92 93 94 95 96 97 98 99
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 已提交
100
	win: { primary: void 0 }
101 102
});

103
// Configuration: Workbench
B
Benjamin Pasero 已提交
104
const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
105 106 107 108 109 110 111 112 113 114 115
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
		},
116 117 118 119 120
		'workbench.editor.showTabCloseButton': {
			'type': 'boolean',
			'description': nls.localize('showEditorTabCloseButton', "Controls if editor tabs should have a visible close button or not."),
			'default': true
		},
121 122 123 124 125
		'workbench.editor.tabCloseButtonOnLeft': {
			'type': 'boolean',
			'default': false,
			'description': nls.localize('editorTabCloseButtonOnLeft', "Controls the position of the editor's tabs close buttons.")
		},
126 127
		'workbench.editor.showIcons': {
			'type': 'boolean',
B
Benjamin Pasero 已提交
128
			'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."),
129 130
			'default': true
		},
131 132 133 134 135 136 137
		'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',
138
			'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)."),
139 140 141 142 143 144 145 146
			'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.")
		},
147 148
		'workbench.quickOpen.closeOnFocusLost': {
			'type': 'boolean',
149
			'description': nls.localize('closeOnFocusLost', "Controls if Quick Open should close automatically once it loses focus."),
150 151
			'default': true
		},
152 153 154 155
		'workbench.settings.openDefaultSettings': {
			'type': 'boolean',
			'description': nls.localize('openDefaultSettings', "Controls if opening settings also opens an editor showing all default settings."),
			'default': true
156 157 158 159 160 161 162
		},
		'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.")
		},
163 164 165 166
		'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 已提交
167
		},
S
Sanders Lauture 已提交
168
		'workbench.activityBar.visible': {
S
Sanders Lauture 已提交
169 170
			'type': 'boolean',
			'default': true,
B
Benjamin Pasero 已提交
171
			'description': nls.localize('activityBarVisibility', "Controls the visibility of the activity bar in the workbench.")
172
		}
173 174 175 176
	}
});

// Configuration: Window
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
let properties: { [path: string]: IJSONSchema; } = {
	'window.openFilesInNewWindow': {
		'type': 'boolean',
		'default': true,
		'description': nls.localize('openFilesInNewWindow', "When enabled, will open files in a new window instead of reusing an existing instance.")
	},
	'window.reopenFolders': {
		'type': 'string',
		'enum': ['none', 'one', 'all'],
		'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.")
	},
	'window.showFullPath': {
		'type': 'boolean',
		'default': false,
		'description': nls.localize('showFullPath', "If enabled, will show the full path of opened files in the window title.")
	}
};

206 207 208 209
if (platform.isWindows) {
	properties['window.autoDetectHighContrast'] = {
		'type': 'boolean',
		'default': true,
210 211
		'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."),
	};
212 213
}

214 215 216 217 218 219 220 221 222
if (platform.isMacintosh) {
	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 已提交
223 224
configurationRegistry.registerConfiguration({
	'id': 'window',
225
	'order': 8,
226
	'title': nls.localize('windowConfigurationTitle', "Window"),
E
Erich Gamma 已提交
227
	'type': 'object',
228
	'properties': properties
B
Benjamin Pasero 已提交
229
});