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

6
import * as nls from 'vs/nls';
7
import { Registry } from 'vs/platform/registry/common/platform';
R
rebornix 已提交
8
import { ToggleAutoSaveAction, GlobalNewUntitledFileAction, FocusFilesExplorer, GlobalCompareResourcesAction, SaveAllAction, ShowActiveFileInExplorer, CollapseExplorerView, RefreshExplorerView, CompareWithClipboardAction, NEW_FILE_COMMAND_ID, NEW_FILE_LABEL, NEW_FOLDER_COMMAND_ID, NEW_FOLDER_LABEL, TRIGGER_RENAME_LABEL, MOVE_FILE_TO_TRASH_LABEL, COPY_FILE_LABEL, PASTE_FILE_LABEL, FileCopiedContext, renameHandler, moveFileToTrashHandler, copyFileHandler, pasteFileHandler, deleteFileHandler, cutFileHandler, DOWNLOAD_COMMAND_ID, openFilePreserveFocusHandler, DOWNLOAD_LABEL, ShowOpenedFileInNewWindow, ReopenResourcesAction } from 'vs/workbench/contrib/files/browser/fileActions';
9
import { revertLocalChangesCommand, acceptLocalChangesCommand, CONFLICT_RESOLUTION_CONTEXT } from 'vs/workbench/contrib/files/browser/editors/textFileSaveErrorHandler';
B
Benjamin Pasero 已提交
10
import { SyncActionDescriptor, MenuId, MenuRegistry, ILocalizedString } from 'vs/platform/actions/common/actions';
B
Benjamin Pasero 已提交
11
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
J
Johannes Rieken 已提交
12
import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes';
13
import { openWindowCommand, COPY_PATH_COMMAND_ID, REVEAL_IN_EXPLORER_COMMAND_ID, OPEN_TO_SIDE_COMMAND_ID, REVERT_FILE_COMMAND_ID, SAVE_FILE_COMMAND_ID, SAVE_FILE_LABEL, SAVE_FILE_AS_COMMAND_ID, SAVE_FILE_AS_LABEL, SAVE_ALL_IN_GROUP_COMMAND_ID, OpenEditorsGroupContext, COMPARE_WITH_SAVED_COMMAND_ID, COMPARE_RESOURCE_COMMAND_ID, SELECT_FOR_COMPARE_COMMAND_ID, ResourceSelectedForCompareContext, DirtyEditorContext, COMPARE_SELECTED_COMMAND_ID, REMOVE_ROOT_FOLDER_COMMAND_ID, REMOVE_ROOT_FOLDER_LABEL, SAVE_FILES_COMMAND_ID, COPY_RELATIVE_PATH_COMMAND_ID, SAVE_FILE_WITHOUT_FORMATTING_COMMAND_ID, SAVE_FILE_WITHOUT_FORMATTING_LABEL, newWindowCommand, ReadonlyEditorContext, OPEN_WITH_EXPLORER_COMMAND_ID } from 'vs/workbench/contrib/files/browser/fileCommands';
14
import { CommandsRegistry, ICommandHandler } from 'vs/platform/commands/common/commands';
15
import { ContextKeyExpr, ContextKeyExpression } from 'vs/platform/contextkey/common/contextkey';
16
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
I
isidor 已提交
17
import { isMacintosh } from 'vs/base/common/platform';
18
import { FilesExplorerFocusCondition, ExplorerRootContext, ExplorerFolderContext, ExplorerResourceNotReadonlyContext, ExplorerResourceCut, IExplorerService, ExplorerResourceMoveableToTrash, ExplorerViewletVisibleContext, ExplorerResourceAvailableEditorIdsContext } from 'vs/workbench/contrib/files/common/files';
19
import { ADD_ROOT_FOLDER_COMMAND_ID, ADD_ROOT_FOLDER_LABEL } from 'vs/workbench/browser/actions/workspaceCommands';
20
import { CLOSE_SAVED_EDITORS_COMMAND_ID, CLOSE_EDITORS_IN_GROUP_COMMAND_ID, CLOSE_EDITOR_COMMAND_ID, CLOSE_OTHER_EDITORS_IN_GROUP_COMMAND_ID } from 'vs/workbench/browser/parts/editor/editorCommands';
21
import { AutoSaveAfterShortDelayContext } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
22
import { ResourceContextKey } from 'vs/workbench/common/resources';
I
isidor 已提交
23
import { WorkbenchListDoubleSelection } from 'vs/platform/list/browser/listService';
24
import { Schemas } from 'vs/base/common/network';
25 26
import { WorkspaceFolderCountContext } from 'vs/workbench/browser/contextkeys';
import { IsWebContext } from 'vs/platform/contextkey/common/contextkeys';
27
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
28
import { OpenFileFolderAction, OpenFileAction, OpenFolderAction, OpenWorkspaceAction } from 'vs/workbench/browser/actions/workspaceActions';
29
import { ActiveEditorIsReadonlyContext, DirtyWorkingCopiesContext, ActiveEditorContext, ActiveEditorAvailableEditorIdsContext } from 'vs/workbench/common/editor';
S
SteVen Batten 已提交
30
import { SidebarFocusContext } from 'vs/workbench/common/viewlet';
31
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
E
Erich Gamma 已提交
32 33

// Contribute Global Actions
34
const category = { value: nls.localize('filesCategory', "File"), original: 'File' };
E
Erich Gamma 已提交
35

36
const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
37 38
registry.registerWorkbenchAction(SyncActionDescriptor.from(SaveAllAction, { primary: undefined, mac: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KEY_S }, win: { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_S) } }), 'File: Save All', category.value);
registry.registerWorkbenchAction(SyncActionDescriptor.from(GlobalCompareResourcesAction), 'File: Compare Active File With...', category.value);
39
registry.registerWorkbenchAction(SyncActionDescriptor.from(ReopenResourcesAction), 'File: Reopen With...', category.value, ActiveEditorAvailableEditorIdsContext);
40 41 42 43 44 45 46 47
registry.registerWorkbenchAction(SyncActionDescriptor.from(FocusFilesExplorer), 'File: Focus on Files Explorer', category.value);
registry.registerWorkbenchAction(SyncActionDescriptor.from(ShowActiveFileInExplorer), 'File: Reveal Active File in Side Bar', category.value);
registry.registerWorkbenchAction(SyncActionDescriptor.from(CollapseExplorerView), 'File: Collapse Folders in Explorer', category.value);
registry.registerWorkbenchAction(SyncActionDescriptor.from(RefreshExplorerView), 'File: Refresh Explorer', category.value);
registry.registerWorkbenchAction(SyncActionDescriptor.from(GlobalNewUntitledFileAction, { primary: KeyMod.CtrlCmd | KeyCode.KEY_N }), 'File: New Untitled File', category.value);
registry.registerWorkbenchAction(SyncActionDescriptor.from(CompareWithClipboardAction, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_C) }), 'File: Compare Active File with Clipboard', category.value);
registry.registerWorkbenchAction(SyncActionDescriptor.from(ToggleAutoSaveAction), 'File: Toggle Auto Save', category.value);
registry.registerWorkbenchAction(SyncActionDescriptor.from(ShowOpenedFileInNewWindow, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_O) }), 'File: Open Active File in New Window', category.value);
48

49
const workspacesCategory = nls.localize('workspaces', "Workspaces");
50
registry.registerWorkbenchAction(SyncActionDescriptor.from(OpenWorkspaceAction), 'Workspaces: Open Workspace...', workspacesCategory);
51

I
isidor 已提交
52 53
const fileCategory = nls.localize('file', "File");
if (isMacintosh) {
54
	registry.registerWorkbenchAction(SyncActionDescriptor.from(OpenFileFolderAction, { primary: KeyMod.CtrlCmd | KeyCode.KEY_O }), 'File: Open...', fileCategory);
I
isidor 已提交
55
} else {
56 57
	registry.registerWorkbenchAction(SyncActionDescriptor.from(OpenFileAction, { primary: KeyMod.CtrlCmd | KeyCode.KEY_O }), 'File: Open File...', fileCategory);
	registry.registerWorkbenchAction(SyncActionDescriptor.from(OpenFolderAction, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_O) }), 'File: Open Folder...', fileCategory);
I
isidor 已提交
58 59
}

60 61
// Commands
CommandsRegistry.registerCommand('_files.windowOpen', openWindowCommand);
62
CommandsRegistry.registerCommand('_files.newWindow', newWindowCommand);
63

64 65
const explorerCommandsWeightBonus = 10; // give our commands a little bit more weight over other default list/tree commands

I
isidor 已提交
66
const RENAME_ID = 'renameFile';
67
KeybindingsRegistry.registerCommandAndKeybindingRule({
I
isidor 已提交
68
	id: RENAME_ID,
69
	weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
70
	when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerRootContext.toNegated(), ExplorerResourceNotReadonlyContext),
71 72 73 74
	primary: KeyCode.F2,
	mac: {
		primary: KeyCode.Enter
	},
I
isidor 已提交
75
	handler: renameHandler
76 77
});

I
isidor 已提交
78
const MOVE_FILE_TO_TRASH_ID = 'moveFileToTrash';
79
KeybindingsRegistry.registerCommandAndKeybindingRule({
I
isidor 已提交
80
	id: MOVE_FILE_TO_TRASH_ID,
81
	weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
82
	when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerResourceNotReadonlyContext, ExplorerResourceMoveableToTrash),
83 84 85 86
	primary: KeyCode.Delete,
	mac: {
		primary: KeyMod.CtrlCmd | KeyCode.Backspace
	},
I
isidor 已提交
87
	handler: moveFileToTrashHandler
88 89
});

90
const DELETE_FILE_ID = 'deleteFile';
91
KeybindingsRegistry.registerCommandAndKeybindingRule({
92
	id: DELETE_FILE_ID,
93
	weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
94
	when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerResourceNotReadonlyContext),
95 96 97 98
	primary: KeyMod.Shift | KeyCode.Delete,
	mac: {
		primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.Backspace
	},
I
isidor 已提交
99
	handler: deleteFileHandler
100 101
});

B
Benjamin Pasero 已提交
102 103 104
KeybindingsRegistry.registerCommandAndKeybindingRule({
	id: DELETE_FILE_ID,
	weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
105
	when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerResourceNotReadonlyContext, ExplorerResourceMoveableToTrash.toNegated()),
B
Benjamin Pasero 已提交
106 107 108 109 110 111 112
	primary: KeyCode.Delete,
	mac: {
		primary: KeyMod.CtrlCmd | KeyCode.Backspace
	},
	handler: deleteFileHandler
});

I
isidor 已提交
113 114 115 116 117 118 119 120 121
const CUT_FILE_ID = 'filesExplorer.cut';
KeybindingsRegistry.registerCommandAndKeybindingRule({
	id: CUT_FILE_ID,
	weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
	when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerRootContext.toNegated()),
	primary: KeyMod.CtrlCmd | KeyCode.KEY_X,
	handler: cutFileHandler,
});

I
isidor 已提交
122
const COPY_FILE_ID = 'filesExplorer.copy';
B
Benjamin Pasero 已提交
123
KeybindingsRegistry.registerCommandAndKeybindingRule({
I
isidor 已提交
124
	id: COPY_FILE_ID,
125
	weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
I
isidor 已提交
126
	when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerRootContext.toNegated()),
B
Benjamin Pasero 已提交
127
	primary: KeyMod.CtrlCmd | KeyCode.KEY_C,
I
isidor 已提交
128
	handler: copyFileHandler,
129 130
});

I
isidor 已提交
131 132
const PASTE_FILE_ID = 'filesExplorer.paste';

133
KeybindingsRegistry.registerCommandAndKeybindingRule({
I
isidor 已提交
134
	id: PASTE_FILE_ID,
135
	weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
136
	when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerResourceNotReadonlyContext),
137
	primary: KeyMod.CtrlCmd | KeyCode.KEY_V,
I
isidor 已提交
138
	handler: pasteFileHandler
B
Benjamin Pasero 已提交
139 140
});

141 142 143 144 145 146 147 148 149 150 151
KeybindingsRegistry.registerCommandAndKeybindingRule({
	id: 'filesExplorer.cancelCut',
	weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
	when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerResourceCut),
	primary: KeyCode.Escape,
	handler: (accessor: ServicesAccessor) => {
		const explorerService = accessor.get(IExplorerService);
		explorerService.setToCopy([], true);
	}
});

I
isidor 已提交
152 153 154 155 156 157 158 159
KeybindingsRegistry.registerCommandAndKeybindingRule({
	id: 'filesExplorer.openFilePreserveFocus',
	weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
	when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerFolderContext.toNegated()),
	primary: KeyCode.Space,
	handler: openFilePreserveFocusHandler
});

160 161 162 163 164 165 166 167 168 169
const copyPathCommand = {
	id: COPY_PATH_COMMAND_ID,
	title: nls.localize('copyPath', "Copy Path")
};

const copyRelativePathCommand = {
	id: COPY_RELATIVE_PATH_COMMAND_ID,
	title: nls.localize('copyRelativePath', "Copy Relative Path")
};

170
// Editor Title Context Menu
171 172
appendEditorTitleContextMenuItem(COPY_PATH_COMMAND_ID, copyPathCommand.title, ResourceContextKey.IsFileSystemResource, '1_cutcopypaste');
appendEditorTitleContextMenuItem(COPY_RELATIVE_PATH_COMMAND_ID, copyRelativePathCommand.title, ResourceContextKey.IsFileSystemResource, '1_cutcopypaste');
173
appendEditorTitleContextMenuItem(REVEAL_IN_EXPLORER_COMMAND_ID, nls.localize('revealInSideBar', "Reveal in Side Bar"), ResourceContextKey.IsFileSystemResource);
174

175
export function appendEditorTitleContextMenuItem(id: string, title: string, when: ContextKeyExpression | undefined, group?: string): void {
176 177 178 179

	// Menu
	MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, {
		command: { id, title },
B
Benjamin Pasero 已提交
180
		when,
181
		group: group || '2_files'
182
	});
183 184
}

185 186 187 188 189 190 191 192 193 194
// Reopen with editor title

MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
	command: {
		id: ReopenResourcesAction.ID,
		title: ReopenResourcesAction.LABEL,
		category: fileCategory,
	},
	group: '6_reopen',
	order: 20,
195
	when: ActiveEditorAvailableEditorIdsContext,
196 197
});

198
// Editor Title Menu for Conflict Resolution
199 200
appendSaveConflictEditorTitleAction('workbench.files.action.acceptLocalChanges', nls.localize('acceptLocalChanges', "Use your changes and overwrite file contents"), { id: 'codicon/check' }, -10, acceptLocalChangesCommand);
appendSaveConflictEditorTitleAction('workbench.files.action.revertLocalChanges', nls.localize('revertLocalChanges', "Discard your changes and revert to file contents"), { id: 'codicon/discard' }, -9, revertLocalChangesCommand);
201

202
function appendSaveConflictEditorTitleAction(id: string, title: string, icon: ThemeIcon, order: number, command: ICommandHandler): void {
203 204 205 206 207 208

	// Command
	CommandsRegistry.registerCommand(id, command);

	// Action
	MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
209
		command: { id, title, icon },
210
		when: ContextKeyExpr.equals(CONFLICT_RESOLUTION_CONTEXT, true),
I
isidor 已提交
211
		group: 'navigation',
212 213
		order
	});
214
}
I
isidor 已提交
215

216 217
// Menu registration - command palette

218
export function appendToCommandPalette(id: string, title: ILocalizedString, category: ILocalizedString, when?: ContextKeyExpression): void {
I
polish  
isidor 已提交
219 220 221 222 223
	MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
		command: {
			id,
			title,
			category
224 225
		},
		when
I
polish  
isidor 已提交
226 227
	});
}
I
isidor 已提交
228

229 230 231 232 233 234 235 236 237 238
appendToCommandPalette(COPY_PATH_COMMAND_ID, { value: nls.localize('copyPathOfActive', "Copy Path of Active File"), original: 'Copy Path of Active File' }, category);
appendToCommandPalette(COPY_RELATIVE_PATH_COMMAND_ID, { value: nls.localize('copyRelativePathOfActive', "Copy Relative Path of Active File"), original: 'Copy Relative Path of Active File' }, category);
appendToCommandPalette(SAVE_FILE_COMMAND_ID, { value: SAVE_FILE_LABEL, original: 'Save' }, category);
appendToCommandPalette(SAVE_FILE_WITHOUT_FORMATTING_COMMAND_ID, { value: SAVE_FILE_WITHOUT_FORMATTING_LABEL, original: 'Save without Formatting' }, category);
appendToCommandPalette(SAVE_ALL_IN_GROUP_COMMAND_ID, { value: nls.localize('saveAllInGroup', "Save All in Group"), original: 'Save All in Group' }, category);
appendToCommandPalette(SAVE_FILES_COMMAND_ID, { value: nls.localize('saveFiles', "Save All Files"), original: 'Save All Files' }, category);
appendToCommandPalette(REVERT_FILE_COMMAND_ID, { value: nls.localize('revert', "Revert File"), original: 'Revert File' }, category);
appendToCommandPalette(COMPARE_WITH_SAVED_COMMAND_ID, { value: nls.localize('compareActiveWithSaved', "Compare Active File with Saved"), original: 'Compare Active File with Saved' }, category);
appendToCommandPalette(SAVE_FILE_AS_COMMAND_ID, { value: SAVE_FILE_AS_LABEL, original: 'Save As...' }, category);
appendToCommandPalette(CLOSE_EDITOR_COMMAND_ID, { value: nls.localize('closeEditor', "Close Editor"), original: 'Close Editor' }, { value: nls.localize('view', "View"), original: 'View' });
I
isidor 已提交
239 240
appendToCommandPalette(NEW_FILE_COMMAND_ID, { value: NEW_FILE_LABEL, original: 'New File' }, category, WorkspaceFolderCountContext.notEqualsTo('0'));
appendToCommandPalette(NEW_FOLDER_COMMAND_ID, { value: NEW_FOLDER_LABEL, original: 'New Folder' }, category, WorkspaceFolderCountContext.notEqualsTo('0'));
241
appendToCommandPalette(DOWNLOAD_COMMAND_ID, { value: DOWNLOAD_LABEL, original: 'Download' }, category, ContextKeyExpr.and(ResourceContextKey.Scheme.notEqualsTo(Schemas.file)));
I
isidor 已提交
242

243 244 245 246 247 248 249
// Menu registration - open editors

const openToSideCommand = {
	id: OPEN_TO_SIDE_COMMAND_ID,
	title: nls.localize('openToSide', "Open to the Side")
};
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
I
isidor 已提交
250
	group: 'navigation',
251 252
	order: 10,
	command: openToSideCommand,
253
	when: ContextKeyExpr.or(ResourceContextKey.IsFileSystemResource, ResourceContextKey.Scheme.isEqualTo(Schemas.untitled))
254 255 256
});

MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
257 258
	group: '1_cutcopypaste',
	order: 10,
259
	command: copyPathCommand,
260 261 262 263 264 265 266
	when: ResourceContextKey.IsFileSystemResource
});

MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
	group: '1_cutcopypaste',
	order: 20,
	command: copyRelativePathCommand,
267
	when: ResourceContextKey.IsFileSystemResource
268 269 270 271 272 273 274
});

MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
	group: '2_save',
	order: 10,
	command: {
		id: SAVE_FILE_COMMAND_ID,
275 276
		title: SAVE_FILE_LABEL,
		precondition: DirtyEditorContext
277
	},
278 279 280 281 282 283 284 285
	when: ContextKeyExpr.or(
		// Untitled Editors
		ResourceContextKey.Scheme.isEqualTo(Schemas.untitled),
		// Or:
		ContextKeyExpr.and(
			// Not: editor groups
			OpenEditorsGroupContext.toNegated(),
			// Not: readonly editors
286
			ReadonlyEditorContext.toNegated(),
287 288 289 290
			// Not: auto save after short delay
			AutoSaveAfterShortDelayContext.toNegated()
		)
	)
291 292 293 294 295 296 297
});

MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
	group: '2_save',
	order: 20,
	command: {
		id: REVERT_FILE_COMMAND_ID,
298 299
		title: nls.localize('revert', "Revert File"),
		precondition: DirtyEditorContext
300
	},
301 302 303 304
	when: ContextKeyExpr.and(
		// Not: editor groups
		OpenEditorsGroupContext.toNegated(),
		// Not: readonly editors
305
		ReadonlyEditorContext.toNegated(),
306 307 308 309 310
		// Not: untitled editors (revert closes them)
		ResourceContextKey.Scheme.notEqualsTo(Schemas.untitled),
		// Not: auto save after short delay
		AutoSaveAfterShortDelayContext.toNegated()
	)
311 312 313 314
});

MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
	group: '2_save',
315
	order: 30,
316 317
	command: {
		id: SAVE_ALL_IN_GROUP_COMMAND_ID,
318 319
		title: nls.localize('saveAll', "Save All"),
		precondition: DirtyWorkingCopiesContext
320
	},
321 322
	// Editor Group
	when: OpenEditorsGroupContext
323 324 325 326 327 328 329
});

MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
	group: '3_compare',
	order: 10,
	command: {
		id: COMPARE_WITH_SAVED_COMMAND_ID,
330 331
		title: nls.localize('compareWithSaved', "Compare with Saved"),
		precondition: DirtyEditorContext
332
	},
333
	when: ContextKeyExpr.and(ResourceContextKey.IsFileSystemResource, AutoSaveAfterShortDelayContext.toNegated(), WorkbenchListDoubleSelection.toNegated())
334 335 336 337
});

const compareResourceCommand = {
	id: COMPARE_RESOURCE_COMMAND_ID,
I
isidor 已提交
338
	title: nls.localize('compareWithSelected', "Compare with Selected")
339 340 341 342 343
};
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
	group: '3_compare',
	order: 20,
	command: compareResourceCommand,
I
isidor 已提交
344
	when: ContextKeyExpr.and(ResourceContextKey.HasResource, ResourceSelectedForCompareContext, WorkbenchListDoubleSelection.toNegated())
345 346 347 348 349 350 351 352 353 354
});

const selectForCompareCommand = {
	id: SELECT_FOR_COMPARE_COMMAND_ID,
	title: nls.localize('compareSource', "Select for Compare")
};
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
	group: '3_compare',
	order: 30,
	command: selectForCompareCommand,
I
isidor 已提交
355
	when: ContextKeyExpr.and(ResourceContextKey.HasResource, WorkbenchListDoubleSelection.toNegated())
I
isidor 已提交
356 357 358 359 360 361 362 363 364 365
});

const compareSelectedCommand = {
	id: COMPARE_SELECTED_COMMAND_ID,
	title: nls.localize('compareSelected', "Compare Selected")
};
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
	group: '3_compare',
	order: 30,
	command: compareSelectedCommand,
I
isidor 已提交
366
	when: ContextKeyExpr.and(ResourceContextKey.HasResource, WorkbenchListDoubleSelection)
367 368 369 370 371 372 373 374 375
});

MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
	group: '4_close',
	order: 10,
	command: {
		id: CLOSE_EDITOR_COMMAND_ID,
		title: nls.localize('close', "Close")
	},
B
Benjamin Pasero 已提交
376
	when: OpenEditorsGroupContext.toNegated()
377 378 379 380 381 382 383 384 385
});

MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
	group: '4_close',
	order: 20,
	command: {
		id: CLOSE_OTHER_EDITORS_IN_GROUP_COMMAND_ID,
		title: nls.localize('closeOthers', "Close Others")
	},
B
Benjamin Pasero 已提交
386
	when: OpenEditorsGroupContext.toNegated()
387 388 389 390 391 392
});

MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
	group: '4_close',
	order: 30,
	command: {
393
		id: CLOSE_SAVED_EDITORS_COMMAND_ID,
394
		title: nls.localize('closeSaved', "Close Saved")
395 396 397 398 399 400 401 402 403 404 405 406 407 408
	}
});

MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
	group: '4_close',
	order: 40,
	command: {
		id: CLOSE_EDITORS_IN_GROUP_COMMAND_ID,
		title: nls.localize('closeAll', "Close All")
	}
});

// Menu registration - explorer

I
isidor 已提交
409
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
I
isidor 已提交
410
	group: 'navigation',
I
isidor 已提交
411 412 413
	order: 4,
	command: {
		id: NEW_FILE_COMMAND_ID,
414
		title: NEW_FILE_LABEL,
415
		precondition: ExplorerResourceNotReadonlyContext
I
isidor 已提交
416
	},
I
isidor 已提交
417
	when: ExplorerFolderContext
I
isidor 已提交
418 419 420
});

MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
I
isidor 已提交
421
	group: 'navigation',
I
isidor 已提交
422 423 424
	order: 6,
	command: {
		id: NEW_FOLDER_COMMAND_ID,
425
		title: NEW_FOLDER_LABEL,
426
		precondition: ExplorerResourceNotReadonlyContext
I
isidor 已提交
427
	},
I
isidor 已提交
428
	when: ExplorerFolderContext
I
isidor 已提交
429 430
});

431
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
I
isidor 已提交
432
	group: 'navigation',
433 434
	order: 10,
	command: openToSideCommand,
435
	when: ContextKeyExpr.and(ExplorerFolderContext.toNegated(), ResourceContextKey.HasResource)
436 437
});

438 439 440 441 442 443 444 445 446 447
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
	group: 'navigation',
	order: 20,
	command: {
		id: OPEN_WITH_EXPLORER_COMMAND_ID,
		title: nls.localize('explorerOpenWith', "Open With..."),
	},
	when: ContextKeyExpr.and(ExplorerRootContext.toNegated(), ExplorerResourceAvailableEditorIdsContext),
});

448 449 450 451
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
	group: '3_compare',
	order: 20,
	command: compareResourceCommand,
452
	when: ContextKeyExpr.and(ExplorerFolderContext.toNegated(), ResourceContextKey.HasResource, ResourceSelectedForCompareContext, WorkbenchListDoubleSelection.toNegated())
453 454 455 456 457 458
});

MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
	group: '3_compare',
	order: 30,
	command: selectForCompareCommand,
459
	when: ContextKeyExpr.and(ExplorerFolderContext.toNegated(), ResourceContextKey.HasResource, WorkbenchListDoubleSelection.toNegated())
I
isidor 已提交
460 461 462 463 464
});

MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
	group: '3_compare',
	order: 30,
I
isidor 已提交
465
	command: compareSelectedCommand,
466
	when: ContextKeyExpr.and(ExplorerFolderContext.toNegated(), ResourceContextKey.HasResource, WorkbenchListDoubleSelection)
467
});
I
isidor 已提交
468

I
isidor 已提交
469 470 471 472 473 474 475 476 477 478
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
	group: '5_cutcopypaste',
	order: 8,
	command: {
		id: CUT_FILE_ID,
		title: nls.localize('cut', "Cut")
	},
	when: ExplorerRootContext.toNegated()
});

I
isidor 已提交
479
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
I
isidor 已提交
480
	group: '5_cutcopypaste',
I
isidor 已提交
481 482 483 484 485 486 487 488 489
	order: 10,
	command: {
		id: COPY_FILE_ID,
		title: COPY_FILE_LABEL
	},
	when: ExplorerRootContext.toNegated()
});

MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
I
isidor 已提交
490
	group: '5_cutcopypaste',
I
isidor 已提交
491 492 493
	order: 20,
	command: {
		id: PASTE_FILE_ID,
494
		title: PASTE_FILE_LABEL,
495
		precondition: ContextKeyExpr.and(ExplorerResourceNotReadonlyContext, FileCopiedContext)
I
isidor 已提交
496
	},
497
	when: ExplorerFolderContext
I
isidor 已提交
498 499
});

I
isidor 已提交
500 501 502 503 504 505 506
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, ({
	group: '5_cutcopypaste',
	order: 30,
	command: {
		id: DOWNLOAD_COMMAND_ID,
		title: DOWNLOAD_LABEL,
	},
I
isidor 已提交
507
	when: ContextKeyExpr.or(ContextKeyExpr.and(ResourceContextKey.Scheme.notEqualsTo(Schemas.file), IsWebContext.toNegated()), ContextKeyExpr.and(ResourceContextKey.Scheme.notEqualsTo(Schemas.file), ExplorerFolderContext.toNegated(), ExplorerRootContext.toNegated()))
I
isidor 已提交
508
}));
I
isidor 已提交
509

I
isidor 已提交
510
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
511
	group: '6_copypath',
I
isidor 已提交
512 513
	order: 30,
	command: copyPathCommand,
514 515 516 517
	when: ResourceContextKey.IsFileSystemResource
});

MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
518
	group: '6_copypath',
519 520
	order: 30,
	command: copyRelativePathCommand,
521
	when: ResourceContextKey.IsFileSystemResource
I
isidor 已提交
522 523
});

I
isidor 已提交
524 525 526 527 528 529 530
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
	group: '2_workspace',
	order: 10,
	command: {
		id: ADD_ROOT_FOLDER_COMMAND_ID,
		title: ADD_ROOT_FOLDER_LABEL
	},
I
isidor 已提交
531
	when: ExplorerRootContext
I
isidor 已提交
532
});
I
isidor 已提交
533

I
isidor 已提交
534 535 536 537 538 539 540
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
	group: '2_workspace',
	order: 30,
	command: {
		id: REMOVE_ROOT_FOLDER_COMMAND_ID,
		title: REMOVE_ROOT_FOLDER_LABEL
	},
541
	when: ContextKeyExpr.and(ExplorerRootContext, ExplorerFolderContext)
I
isidor 已提交
542
});
I
isidor 已提交
543 544

MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
I
isidor 已提交
545
	group: '7_modification',
I
isidor 已提交
546 547
	order: 10,
	command: {
I
isidor 已提交
548
		id: RENAME_ID,
549
		title: TRIGGER_RENAME_LABEL,
550
		precondition: ExplorerResourceNotReadonlyContext
I
isidor 已提交
551 552 553
	},
	when: ExplorerRootContext.toNegated()
});
I
isidor 已提交
554 555

MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
I
isidor 已提交
556
	group: '7_modification',
I
isidor 已提交
557 558 559
	order: 20,
	command: {
		id: MOVE_FILE_TO_TRASH_ID,
560
		title: MOVE_FILE_TO_TRASH_LABEL,
561
		precondition: ExplorerResourceNotReadonlyContext
I
isidor 已提交
562
	},
563 564
	alt: {
		id: DELETE_FILE_ID,
565
		title: nls.localize('deleteFile', "Delete Permanently"),
566
		precondition: ExplorerResourceNotReadonlyContext
567
	},
568
	when: ContextKeyExpr.and(ExplorerRootContext.toNegated(), ExplorerResourceMoveableToTrash)
B
Benjamin Pasero 已提交
569 570 571 572 573 574 575 576 577 578
});

MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
	group: '7_modification',
	order: 20,
	command: {
		id: DELETE_FILE_ID,
		title: nls.localize('deleteFile', "Delete Permanently"),
		precondition: ExplorerResourceNotReadonlyContext
	},
579
	when: ContextKeyExpr.and(ExplorerRootContext.toNegated(), ExplorerResourceMoveableToTrash.toNegated())
I
isidor 已提交
580
});
581 582

// Empty Editor Group Context Menu
I
isidor 已提交
583
MenuRegistry.appendMenuItem(MenuId.EmptyEditorGroupContext, { command: { id: GlobalNewUntitledFileAction.ID, title: nls.localize('newFile', "New File") }, group: '1_file', order: 10 });
584
MenuRegistry.appendMenuItem(MenuId.EmptyEditorGroupContext, { command: { id: 'workbench.action.quickOpen', title: nls.localize('openFile', "Open File...") }, group: '1_file', order: 20 });
I
isidor 已提交
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600

// File menu

MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
	group: '1_new',
	command: {
		id: GlobalNewUntitledFileAction.ID,
		title: nls.localize({ key: 'miNewFile', comment: ['&& denotes a mnemonic'] }, "&&New File")
	},
	order: 1
});

MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
	group: '4_save',
	command: {
		id: SAVE_FILE_COMMAND_ID,
S
SteVen Batten 已提交
601
		title: nls.localize({ key: 'miSave', comment: ['&& denotes a mnemonic'] }, "&&Save"),
602
		precondition: ContextKeyExpr.or(ActiveEditorIsReadonlyContext.toNegated(), ContextKeyExpr.and(ExplorerViewletVisibleContext, SidebarFocusContext))
I
isidor 已提交
603 604 605 606 607 608 609 610
	},
	order: 1
});

MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
	group: '4_save',
	command: {
		id: SAVE_FILE_AS_COMMAND_ID,
S
SteVen Batten 已提交
611
		title: nls.localize({ key: 'miSaveAs', comment: ['&& denotes a mnemonic'] }, "Save &&As..."),
B
Benjamin Pasero 已提交
612 613
		// ActiveEditorContext is not 100% correct, but we lack a context for indicating "Save As..." support
		precondition: ContextKeyExpr.or(ActiveEditorContext, ContextKeyExpr.and(ExplorerViewletVisibleContext, SidebarFocusContext))
I
isidor 已提交
614
	},
M
Martin Aeschlimann 已提交
615
	order: 2
I
isidor 已提交
616 617 618 619 620 621
});

MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
	group: '4_save',
	command: {
		id: SaveAllAction.ID,
622 623
		title: nls.localize({ key: 'miSaveAll', comment: ['&& denotes a mnemonic'] }, "Save A&&ll"),
		precondition: DirtyWorkingCopiesContext
I
isidor 已提交
624 625 626 627
	},
	order: 3
});

628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
if (isMacintosh) {
	MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
		group: '2_open',
		command: {
			id: OpenFileFolderAction.ID,
			title: nls.localize({ key: 'miOpen', comment: ['&& denotes a mnemonic'] }, "&&Open...")
		},
		order: 1
	});
} else {
	MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
		group: '2_open',
		command: {
			id: OpenFileAction.ID,
			title: nls.localize({ key: 'miOpenFile', comment: ['&& denotes a mnemonic'] }, "&&Open File...")
		},
		order: 1
	});

	MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
		group: '2_open',
		command: {
			id: OpenFolderAction.ID,
			title: nls.localize({ key: 'miOpenFolder', comment: ['&& denotes a mnemonic'] }, "Open &&Folder...")
		},
		order: 2
	});
}

657 658 659 660 661 662
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
	group: '2_open',
	command: {
		id: OpenWorkspaceAction.ID,
		title: nls.localize({ key: 'miOpenWorkspace', comment: ['&& denotes a mnemonic'] }, "Open Wor&&kspace...")
	},
B
Benjamin Pasero 已提交
663
	order: 3
664 665
});

I
isidor 已提交
666 667 668 669
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
	group: '5_autosave',
	command: {
		id: ToggleAutoSaveAction.ID,
670 671
		title: nls.localize({ key: 'miAutoSave', comment: ['&& denotes a mnemonic'] }, "A&&uto Save"),
		toggled: ContextKeyExpr.notEquals('config.files.autoSave', 'off')
I
isidor 已提交
672 673 674 675 676 677 678 679
	},
	order: 1
});

MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
	group: '6_close',
	command: {
		id: REVERT_FILE_COMMAND_ID,
680
		title: nls.localize({ key: 'miRevert', comment: ['&& denotes a mnemonic'] }, "Re&&vert File"),
681
		precondition: ContextKeyExpr.or(ActiveEditorIsReadonlyContext.toNegated(), ContextKeyExpr.and(ExplorerViewletVisibleContext, SidebarFocusContext))
I
isidor 已提交
682 683 684 685 686 687 688 689 690 691 692 693
	},
	order: 1
});

MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
	group: '6_close',
	command: {
		id: CLOSE_EDITOR_COMMAND_ID,
		title: nls.localize({ key: 'miCloseEditor', comment: ['&& denotes a mnemonic'] }, "&&Close Editor")
	},
	order: 2
});
694 695 696 697

// Go to menu

MenuRegistry.appendMenuItem(MenuId.MenubarGoMenu, {
698
	group: '3_global_nav',
699 700 701 702 703
	command: {
		id: 'workbench.action.quickOpen',
		title: nls.localize({ key: 'miGotoFile', comment: ['&& denotes a mnemonic'] }, "Go to &&File...")
	},
	order: 1
704
});