preferences.contribution.ts 4.7 KB
Newer Older
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';

import * as nls from 'vs/nls';
8
import URI from 'vs/base/common/uri';
9 10
import { Registry } from 'vs/platform/platform';
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actionRegistry';
11
import { EditorInput, IEditorRegistry, Extensions as EditorExtensions, IEditorInputFactory } from 'vs/workbench/common/editor';
12
import { EditorDescriptor } from 'vs/workbench/browser/parts/editor/baseEditor';
S
Sandeep Somavarapu 已提交
13
import { MenuId, MenuRegistry, SyncActionDescriptor } from 'vs/platform/actions/common/actions';
14
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
C
Christof Marti 已提交
15
import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes';
16
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
S
Sandeep Somavarapu 已提交
17
import { DefaultPreferencesEditor, DefaultPreferencesEditorInput } from 'vs/workbench/parts/preferences/browser/preferencesEditor';
18
import { OpenGlobalSettingsAction, OpenGlobalKeybindingsAction, OpenWorkspaceSettingsAction, StartSearchDefaultSettingsAction } from 'vs/workbench/parts/preferences/browser/preferencesActions';
S
Sandeep Somavarapu 已提交
19
import { IPreferencesService, CONTEXT_DEFAULT_SETTINGS_EDITOR, DEFAULT_EDITOR_COMMAND_COLLAPSE_ALL } from 'vs/workbench/parts/preferences/common/preferences';
20
import { PreferencesService } from 'vs/workbench/parts/preferences/browser/preferencesService';
S
Sandeep Somavarapu 已提交
21
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
22
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
23

24
registerSingleton(IPreferencesService, PreferencesService);
25

26
Registry.as<IEditorRegistry>(EditorExtensions.Editors).registerEditor(
27
	new EditorDescriptor(
S
Sandeep Somavarapu 已提交
28
		DefaultPreferencesEditor.ID,
S
Sandeep Somavarapu 已提交
29
		nls.localize('defaultPreferencesEditor', "Default Preferences Editor"),
30
		'vs/workbench/parts/preferences/browser/preferencesEditor',
S
Sandeep Somavarapu 已提交
31
		'DefaultPreferencesEditor'
32 33
	),
	[
S
Sandeep Somavarapu 已提交
34
		new SyncDescriptor(DefaultPreferencesEditorInput)
35 36 37
	]
);

38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
interface ISerializedDefaultPreferencesEditorInput {
	resource: string;
	isSettings: boolean;
}

// Register Editor Input Factory for Default Preferences Input
class DefaultPreferencesEditorInputFactory implements IEditorInputFactory {

	public serialize(editorInput: EditorInput): string {
		const input = <DefaultPreferencesEditorInput>editorInput;

		const serialized: ISerializedDefaultPreferencesEditorInput = { resource: input.getResource().toString(), isSettings: input.isSettings };

		return JSON.stringify(serialized);
	}

	public deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): EditorInput {
		const deserialized: ISerializedDefaultPreferencesEditorInput = JSON.parse(serializedEditorInput);

		return new DefaultPreferencesEditorInput(URI.parse(deserialized.resource), deserialized.isSettings);
	}
}

Registry.as<IEditorRegistry>(EditorExtensions.Editors).registerEditorInputFactory(DefaultPreferencesEditorInput.ID, DefaultPreferencesEditorInputFactory);

63 64 65 66 67 68 69
// Contribute Global Actions
const category = nls.localize('preferences', "Preferences");
const registry = Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions);
registry.registerWorkbenchAction(new SyncActionDescriptor(OpenGlobalSettingsAction, OpenGlobalSettingsAction.ID, OpenGlobalSettingsAction.LABEL, {
	primary: null,
	mac: { primary: KeyMod.CtrlCmd | KeyCode.US_COMMA }
}), 'Preferences: Open User Settings', category);
C
Christof Marti 已提交
70
registry.registerWorkbenchAction(new SyncActionDescriptor(OpenGlobalKeybindingsAction, OpenGlobalKeybindingsAction.ID, OpenGlobalKeybindingsAction.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_S) }), 'Preferences: Open Keyboard Shortcuts', category);
S
Sandeep Somavarapu 已提交
71
registry.registerWorkbenchAction(new SyncActionDescriptor(OpenWorkspaceSettingsAction, OpenWorkspaceSettingsAction.ID, OpenWorkspaceSettingsAction.LABEL), 'Preferences: Open Workspace Settings', category);
72
registry.registerWorkbenchAction(new SyncActionDescriptor(StartSearchDefaultSettingsAction, StartSearchDefaultSettingsAction.ID, StartSearchDefaultSettingsAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_F }, ContextKeyExpr.and(CONTEXT_DEFAULT_SETTINGS_EDITOR)), '');
S
Sandeep Somavarapu 已提交
73 74 75 76 77 78 79 80 81 82

MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
	command: {
		id: DEFAULT_EDITOR_COMMAND_COLLAPSE_ALL,
		iconClass: 'collapseAll',
		title: nls.localize('collapseAll', "Collapse All")
	},
	when: ContextKeyExpr.and(CONTEXT_DEFAULT_SETTINGS_EDITOR),
	group: 'navigation'
});