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

'use strict';

import {Registry} from 'vs/platform/platform';
import nls = require('vs/nls');
import {SyncActionDescriptor} from 'vs/platform/actions/common/actions';
import {IConfigurationRegistry, Extensions as ConfigurationExtensions} from 'vs/platform/configuration/common/configurationRegistry';
12
import {IWorkbenchActionRegistry, Extensions} from 'vs/workbench/common/actionRegistry';
E
Erich Gamma 已提交
13
import {KeyMod, KeyCode} from 'vs/base/common/keyCodes';
14
import platform = require('vs/base/common/platform');
A
Alex Dima 已提交
15
import {IKeybindings} from 'vs/platform/keybinding/common/keybinding';
16 17
import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry';
import {IWindowService} from 'vs/workbench/services/window/electron-browser/windowService';
18
import {CloseEditorAction, ReloadWindowAction, ShowStartupPerformance, ZoomResetAction, ZoomOutAction, ZoomInAction, ToggleDevToolsAction, ToggleFullScreenAction, ToggleMenuBarAction, OpenRecentAction, CloseFolderAction, CloseWindowAction, SwitchWindow, NewWindowAction, CloseMessagesAction} from 'vs/workbench/electron-browser/actions';
A
Alex Dima 已提交
19
import {MessagesVisibleContext, NoEditorsVisibleContext} from 'vs/workbench/electron-browser/workbench';
E
Erich Gamma 已提交
20

21 22
const closeEditorOrWindowKeybindings: IKeybindings = { primary: KeyMod.CtrlCmd | KeyCode.KEY_W, win: { primary: KeyMod.CtrlCmd | KeyCode.F4, secondary: [KeyMod.CtrlCmd | KeyCode.KEY_W] }};

E
Erich Gamma 已提交
23 24
// Contribute Global Actions
const viewCategory = nls.localize('view', "View");
B
cleanup  
Benjamin Pasero 已提交
25 26
const developerCategory = nls.localize('developer', "Developer");
const fileCategory = nls.localize('file', "File");
E
Erich Gamma 已提交
27
const workbenchActionsRegistry = <IWorkbenchActionRegistry>Registry.as(Extensions.WorkbenchActions);
28 29
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');
30
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(SwitchWindow, SwitchWindow.ID, SwitchWindow.LABEL), 'Switch Window');
31
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(CloseFolderAction, CloseFolderAction.ID, CloseFolderAction.LABEL, { primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_F) }), 'File: Close Folder', fileCategory);
J
Joao Moreno 已提交
32
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(OpenRecentAction, OpenRecentAction.ID, OpenRecentAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_R, mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_R } }), 'File: Open Recent', fileCategory);
33
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleDevToolsAction, ToggleDevToolsAction.ID, ToggleDevToolsAction.LABEL), 'Developer: Toggle Developer Tools', developerCategory);
34
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ZoomInAction, ZoomInAction.ID, ZoomInAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.US_EQUAL, secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_EQUAL] }), 'View: Zoom In', viewCategory);
35 36 37 38 39 40 41
workbenchActionsRegistry.registerWorkbenchAction(
	new SyncActionDescriptor(ZoomOutAction, ZoomOutAction.ID, ZoomOutAction.LABEL, {
		primary: KeyMod.CtrlCmd | KeyCode.US_MINUS,
		secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_MINUS],
		linux: { primary: KeyMod.CtrlCmd | KeyCode.US_MINUS, secondary: []}
	}), 'View: Zoom Out', viewCategory
);
42 43
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ZoomResetAction, ZoomResetAction.ID, ZoomResetAction.LABEL), 'View: Reset Zoom', viewCategory);
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ShowStartupPerformance, ShowStartupPerformance.ID, ShowStartupPerformance.LABEL), 'Developer: Startup Performance', developerCategory);
44
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ReloadWindowAction, ReloadWindowAction.ID, ReloadWindowAction.LABEL), 'Reload Window');
A
Alex Dima 已提交
45
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(CloseMessagesAction, CloseMessagesAction.ID, CloseMessagesAction.LABEL, { primary: KeyCode.Escape, secondary: [KeyMod.Shift | KeyCode.Escape] }, MessagesVisibleContext), 'Close Notification Messages');
46
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(CloseEditorAction, CloseEditorAction.ID, CloseEditorAction.LABEL, closeEditorOrWindowKeybindings), 'View: Close Editor', viewCategory);
47
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);
48
if (platform.isWindows || platform.isLinux) {
49
	workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleMenuBarAction, ToggleMenuBarAction.ID, ToggleMenuBarAction.LABEL), 'View: Toggle Menu Bar', viewCategory);
50
}
E
Erich Gamma 已提交
51

52
// close the window when the last editor is closed by reusing the same keybinding
A
Alex Dima 已提交
53
KeybindingsRegistry.registerCommandAndKeybindingRule({
54 55
	id: 'workbench.action.closeWindow',
	weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
A
Alex Dima 已提交
56
	when: NoEditorsVisibleContext,
57 58 59 60 61 62 63
	primary: closeEditorOrWindowKeybindings.primary,
	handler: accessor => {
		const windowService = accessor.get(IWindowService);
		windowService.getWindow().close();
	}
});

64
// Configuration: Workbench
E
Erich Gamma 已提交
65
const configurationRegistry = <IConfigurationRegistry>Registry.as(ConfigurationExtensions.Configuration);
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
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
		},
		'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',
84
			'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)."),
85 86 87 88 89 90 91 92
			'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.")
		},
93 94
		'workbench.quickOpen.closeOnFocusLost': {
			'type': 'boolean',
95
			'description': nls.localize('closeOnFocusLost', "Controls if Quick Open should close automatically once it loses focus."),
96 97
			'default': true
		},
98 99 100 101 102 103 104 105 106
		'workbench.settings.openDefaultSettings': {
			'type': 'boolean',
			'description': nls.localize('openDefaultSettings', "Controls if opening settings also opens an editor showing all default settings."),
			'default': true
		}
	}
});

// Configuration: Window
E
Erich Gamma 已提交
107 108
configurationRegistry.registerConfiguration({
	'id': 'window',
109
	'order': 8,
110
	'title': nls.localize('windowConfigurationTitle', "Window"),
E
Erich Gamma 已提交
111 112
	'type': 'object',
	'properties': {
113
		'window.openFilesInNewWindow': {
E
Erich Gamma 已提交
114 115
			'type': 'boolean',
			'default': true,
116
			'description': nls.localize('openFilesInNewWindow', "When enabled, will open files in a new window instead of reusing an existing instance.")
E
Erich Gamma 已提交
117 118 119 120 121 122
		},
		'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.")
B
Benjamin Pasero 已提交
123
		},
124 125 126 127 128
		'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.")
		},
B
Benjamin Pasero 已提交
129 130
		'window.zoomLevel': {
			'type': 'number',
B
Benjamin Pasero 已提交
131
			'default': 0,
B
Benjamin Pasero 已提交
132
			'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.")
E
Erich Gamma 已提交
133 134
		}
	}
135 136 137 138 139
});

// Configuration: Update
configurationRegistry.registerConfiguration({
	'id': 'update',
140
	'order': 15,
141
	'title': nls.localize('updateConfigurationTitle', "Update"),
142 143 144 145 146 147
	'type': 'object',
	'properties': {
		'update.channel': {
			'type': 'string',
			'enum': ['none', 'default'],
			'default': 'default',
J
Joao Moreno 已提交
148
			'description': nls.localize('updateChannel', "Configure whether you receive automatic updates from an update channel. Requires a restart after change.")
149 150
		}
	}
151
});