files.contribution.ts 11.2 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6 7 8 9 10
/*---------------------------------------------------------------------------------------------
 *  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 'vs/css!./media/files.contribution';

import URI from 'vs/base/common/uri';
I
isidor 已提交
11
import {ViewletRegistry, Extensions as ViewletExtensions, ViewletDescriptor, ToggleViewletAction} from 'vs/workbench/browser/viewlet';
E
Erich Gamma 已提交
12 13 14 15
import nls = require('vs/nls');
import {SyncActionDescriptor} from 'vs/platform/actions/common/actions';
import {Registry} from 'vs/platform/platform';
import {IConfigurationRegistry, Extensions as ConfigurationExtensions} from 'vs/platform/configuration/common/configurationRegistry';
16
import {IWorkbenchActionRegistry, Extensions as ActionExtensions} from 'vs/workbench/common/actionRegistry';
E
Erich Gamma 已提交
17
import {IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions} from 'vs/workbench/common/contributions';
B
Benjamin Pasero 已提交
18
import {IEditorRegistry, Extensions as EditorExtensions, IEditorInputFactory, EditorInput, IFileEditorInput} from 'vs/workbench/common/editor';
E
Erich Gamma 已提交
19
import {FileEditorDescriptor} from 'vs/workbench/parts/files/browser/files';
20
import {AutoSaveConfiguration, SUPPORTED_ENCODINGS} from 'vs/platform/files/common/files';
E
Erich Gamma 已提交
21
import {FILE_EDITOR_INPUT_ID, VIEWLET_ID} from 'vs/workbench/parts/files/common/files';
22
import {FileEditorTracker} from 'vs/workbench/parts/files/common/editors/fileEditorTracker';
23
import {SaveParticipant} from 'vs/workbench/parts/files/common/editors/saveParticipant';
24
import {FileEditorInput} from 'vs/workbench/parts/files/common/editors/fileEditorInput';
E
Erich Gamma 已提交
25 26
import {TextFileEditor} from 'vs/workbench/parts/files/browser/editors/textFileEditor';
import {BinaryFileEditor} from 'vs/workbench/parts/files/browser/editors/binaryFileEditor';
27
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
E
Erich Gamma 已提交
28
import {SyncDescriptor, AsyncDescriptor} from 'vs/platform/instantiation/common/descriptors';
29
import {IKeybindings} from 'vs/platform/keybinding/common/keybinding';
E
Erich Gamma 已提交
30 31 32
import {IViewletService} from 'vs/workbench/services/viewlet/common/viewletService';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {KeyMod, KeyCode} from 'vs/base/common/keyCodes';
33
import * as platform from 'vs/base/common/platform';
E
Erich Gamma 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

// Viewlet Action
export class OpenExplorerViewletAction extends ToggleViewletAction {
	public static ID = VIEWLET_ID;
	public static LABEL = nls.localize('showExplorerViewlet', "Show Explorer");

	constructor(
		id: string,
		label: string,
		@IViewletService viewletService: IViewletService,
		@IWorkbenchEditorService editorService: IWorkbenchEditorService
	) {
		super(id, label, VIEWLET_ID, viewletService, editorService);
	}
}

// Register Viewlet
I
isidor 已提交
51
(<ViewletRegistry>Registry.as(ViewletExtensions.Viewlets)).registerViewlet(new ViewletDescriptor(
E
Erich Gamma 已提交
52 53 54
	'vs/workbench/parts/files/browser/explorerViewlet',
	'ExplorerViewlet',
	VIEWLET_ID,
B
Benjamin Pasero 已提交
55
	nls.localize('explore', "Explorer"),
E
Erich Gamma 已提交
56 57 58 59
	'explore',
	0
));

I
isidor 已提交
60
(<ViewletRegistry>Registry.as(ViewletExtensions.Viewlets)).setDefaultViewletId(VIEWLET_ID);
E
Erich Gamma 已提交
61 62 63 64 65 66

let openViewletKb: IKeybindings = {
	primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_E
};

// Register Action to Open Viewlet
67 68
const registry = <IWorkbenchActionRegistry>Registry.as(ActionExtensions.WorkbenchActions);
registry.registerWorkbenchAction(
E
Erich Gamma 已提交
69
	new SyncActionDescriptor(OpenExplorerViewletAction, OpenExplorerViewletAction.ID, OpenExplorerViewletAction.LABEL, openViewletKb),
70
	'View: Show Explorer',
71
	nls.localize('view', "View")
E
Erich Gamma 已提交
72 73 74 75 76
);

// Register file editors
(<IEditorRegistry>Registry.as(EditorExtensions.Editors)).registerEditor(
	new FileEditorDescriptor(
77
		TextFileEditor.ID, // explicit dependency because we don't want these editors lazy loaded
E
Erich Gamma 已提交
78 79 80 81 82 83
		nls.localize('textFileEditor', "Text File Editor"),
		'vs/workbench/parts/files/browser/editors/textFileEditor',
		'TextFileEditor',
		[
			'text/*',

84 85 86
			// In case the mime type is unknown, we prefer the text file editor over the binary editor to leave a chance
			// of opening a potential text file properly. The resolution of the file in the text file editor will fail
			// early on in case the file is actually binary, to prevent downloading a potential large binary file.
E
Erich Gamma 已提交
87 88 89 90 91 92 93 94 95 96
			'application/unknown'
		]
	),
	[
		new SyncDescriptor<EditorInput>(FileEditorInput)
	]
);

(<IEditorRegistry>Registry.as(EditorExtensions.Editors)).registerEditor(
	new FileEditorDescriptor(
97
		BinaryFileEditor.ID, // explicit dependency because we don't want these editors lazy loaded
E
Erich Gamma 已提交
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
		nls.localize('binaryFileEditor', "Binary File Editor"),
		'vs/workbench/parts/files/browser/editors/binaryFileEditor',
		'BinaryFileEditor',
		[
			'image/*',
			'application/pdf',
			'audio/*',
			'video/*',
			'application/octet-stream'
		]
	),
	[
		new SyncDescriptor<EditorInput>(FileEditorInput)
	]
);

// Register default file input handler
// Note: because of service injection, the descriptor needs to have the exact count
// of arguments as the FileEditorInput constructor. Otherwise when creating an
// instance through the instantiation service he will inject the services wrong!
118
let descriptor = new AsyncDescriptor<IFileEditorInput>('vs/workbench/parts/files/common/editors/fileEditorInput', 'FileEditorInput', /* DO NOT REMOVE */ void 0, /* DO NOT REMOVE */ void 0, /* DO NOT REMOVE */ void 0);
E
Erich Gamma 已提交
119 120 121 122 123 124 125 126 127
(<IEditorRegistry>Registry.as(EditorExtensions.Editors)).registerDefaultFileInput(descriptor);

interface ISerializedFileInput {
	resource: string;
}

// Register Editor Input Factory
class FileEditorInputFactory implements IEditorInputFactory {

128
	constructor() { }
E
Erich Gamma 已提交
129 130 131 132

	public serialize(editorInput: EditorInput): string {
		let fileEditorInput = <FileEditorInput>editorInput;
		let fileInput: ISerializedFileInput = {
133
			resource: fileEditorInput.getResource().toString()
E
Erich Gamma 已提交
134 135 136 137 138 139 140 141
		};

		return JSON.stringify(fileInput);
	}

	public deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): EditorInput {
		let fileInput: ISerializedFileInput = JSON.parse(serializedEditorInput);

142
		return instantiationService.createInstance(FileEditorInput, URI.parse(fileInput.resource), void 0, void 0);
E
Erich Gamma 已提交
143 144 145 146 147
	}
}

(<IEditorRegistry>Registry.as(EditorExtensions.Editors)).registerEditorInputFactory(FILE_EDITOR_INPUT_ID, FileEditorInputFactory);

148
// Register File Editor Tracker
E
Erich Gamma 已提交
149
(<IWorkbenchContributionsRegistry>Registry.as(WorkbenchExtensions.Workbench)).registerWorkbenchContribution(
150
	FileEditorTracker
E
Erich Gamma 已提交
151 152 153 154 155 156 157 158 159 160 161 162
);

// Register Save Participant
(<IWorkbenchContributionsRegistry>Registry.as(WorkbenchExtensions.Workbench)).registerWorkbenchContribution(
	SaveParticipant
);

// Configuration
let configurationRegistry = <IConfigurationRegistry>Registry.as(ConfigurationExtensions.Configuration);

configurationRegistry.registerConfiguration({
	'id': 'files',
163
	'order': 9,
164
	'title': nls.localize('filesConfigurationTitle', "Files"),
E
Erich Gamma 已提交
165 166 167 168 169
	'type': 'object',
	'properties': {
		'files.exclude': {
			'type': 'object',
			'description': nls.localize('exclude', "Configure glob patterns for excluding files and folders."),
170
			'default': { '**/.git': true, '**/.svn': true, '**/.hg': true, '**/.DS_Store': true },
E
Erich Gamma 已提交
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
			'additionalProperties': {
				'anyOf': [
					{
						'type': 'boolean',
						'description': nls.localize('files.exclude.boolean', "The glob pattern to match file paths against. Set to true or false to enable or disable the pattern."),
					},
					{
						'type': 'object',
						'properties': {
							'when': {
								'type': 'string', // expression ({ "**/*.js": { "when": "$(basename).js" } })
								'pattern': '\\w*\\$\\(basename\\)\\w*',
								'default': '$(basename).ext',
								'description': nls.localize('files.exclude.when', 'Additional check on the siblings of a matching file. Use $(basename) as variable for the matching file name.')
							}
						}
					}
				]
			}
		},
B
Benjamin Pasero 已提交
191
		'files.associations': {
192
			'type': 'object',
B
Benjamin Pasero 已提交
193
			'description': nls.localize('associations', "Configure file associations to languages (e.g. \"*.extension\": \"html\"). These have precedence over the default associations of the languages installed."),
194
		},
E
Erich Gamma 已提交
195 196 197 198 199 200
		'files.encoding': {
			'type': 'string',
			'enum': Object.keys(SUPPORTED_ENCODINGS),
			'default': 'utf8',
			'description': nls.localize('encoding', "The default character set encoding to use when reading and writing files."),
		},
201 202 203 204 205 206 207 208 209
		'files.eol': {
			'type': 'string',
			'enum': [
				'\n',
				'\r\n'
			],
			'default': (platform.isLinux || platform.isMacintosh) ? '\n' : '\r\n',
			'description': nls.localize('eol', "The default end of line character."),
		},
E
Erich Gamma 已提交
210 211 212 213
		'files.trimTrailingWhitespace': {
			'type': 'boolean',
			'default': false,
			'description': nls.localize('trimTrailingWhitespace', "When enabled, will trim trailing whitespace when you save a file.")
214
		},
215 216
		'files.autoSave': {
			'type': 'string',
217
			'enum': [AutoSaveConfiguration.OFF, AutoSaveConfiguration.AFTER_DELAY, AutoSaveConfiguration.ON_FOCUS_CHANGE, , AutoSaveConfiguration.ON_WINDOW_CHANGE],
218
			'default': AutoSaveConfiguration.OFF,
219
			'description': nls.localize('autoSave', "Controls auto save of dirty files. Accepted values:  \"{0}\", \"{1}\", \"{2}\" (editor loses focus), \"{3}\" (window loses focus). If set to \"{4}\", you can configure the delay in \"files.autoSaveDelay\".", AutoSaveConfiguration.OFF, AutoSaveConfiguration.AFTER_DELAY, AutoSaveConfiguration.ON_FOCUS_CHANGE, AutoSaveConfiguration.ON_WINDOW_CHANGE, AutoSaveConfiguration.AFTER_DELAY)
220
		},
221
		'files.autoSaveDelay': {
222
			'type': 'number',
223
			'default': 1000,
224
			'description': nls.localize('autoSaveDelay', "Controls the delay in ms after which a dirty file is saved automatically. Only applies when \"files.autoSave\" is set to \"{0}\"", AutoSaveConfiguration.AFTER_DELAY)
225 226
		},
		'files.watcherExclude': {
227
			'type': 'object',
228
			'default': (platform.isLinux || platform.isMacintosh) ? { '**/.git/objects/**': true, '**/node_modules/**': true } : { '**/.git/objects/**': true },
229
			'description': nls.localize('watcherExclude', "Configure glob patterns of file paths to exclude from file watching. Changing this setting requires a restart. When you experience Code consuming lots of cpu time on startup, you can exclude large folders to reduce the initial load.")
E
Erich Gamma 已提交
230 231 232 233 234 235
		}
	}
});

configurationRegistry.registerConfiguration({
	'id': 'explorer',
236
	'order': 10,
237
	'title': nls.localize('explorerConfigurationTitle', "File Explorer"),
E
Erich Gamma 已提交
238 239
	'type': 'object',
	'properties': {
240
		'explorer.openEditors.visible': {
E
Erich Gamma 已提交
241
			'type': 'number',
242
			'description': nls.localize('openEditorsVisible', "Number of editors shown in the Open Editors pane. Set it to 0 to hide the pane."),
E
Erich Gamma 已提交
243 244
			'default': 9
		},
245
		'explorer.openEditors.dynamicHeight': {
E
Erich Gamma 已提交
246
			'type': 'boolean',
247
			'description': nls.localize('dynamicHeight', "Controls if the height of the open editors section should adapt dynamically to the number of elements or not."),
E
Erich Gamma 已提交
248
			'default': true
249 250 251 252 253
		},
		'explorer.autoReveal': {
			'type': 'boolean',
			'description': nls.localize('autoReveal', "Controls if the explorer should automatically reveal files when opening them."),
			'default': true
254 255 256 257 258
		},
		'explorer.enableDragAndDrop': {
			'type': 'boolean',
			'description': nls.localize('enableDragAndDrop', "Controls if the explorer should allow to move files and folders via drag and drop."),
			'default': true
E
Erich Gamma 已提交
259 260
		}
	}
B
Benjamin Pasero 已提交
261
});