fileActions.contribution.ts 25.0 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';
8 9
import { ToggleAutoSaveAction, GlobalNewUntitledFileAction, ShowOpenedFileInNewWindow, 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 } from 'vs/workbench/contrib/files/electron-browser/fileActions';
import { revertLocalChangesCommand, acceptLocalChangesCommand, CONFLICT_RESOLUTION_CONTEXT } from 'vs/workbench/contrib/files/electron-browser/saveErrorHandler';
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, REVEAL_IN_OS_COMMAND_ID, 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, REVEAL_IN_OS_LABEL, 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 } from 'vs/workbench/contrib/files/electron-browser/fileCommands';
14
import { CommandsRegistry, ICommandHandler } from 'vs/platform/commands/common/commands';
15
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
16
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
17
import { isWindows, isMacintosh } from 'vs/base/common/platform';
18
import { FilesExplorerFocusCondition, ExplorerRootContext, ExplorerFolderContext, ExplorerResourceNotReadonlyContext, ExplorerResourceCut, IExplorerService } 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';
I
isidor 已提交
21
import { AutoSaveContext } from 'vs/workbench/services/textfile/common/textfiles';
22
import { ResourceContextKey } from 'vs/workbench/common/resources';
I
isidor 已提交
23
import { WorkbenchListDoubleSelection } from 'vs/platform/list/browser/listService';
24
import { URI } from 'vs/base/common/uri';
25
import { Schemas } from 'vs/base/common/network';
A
Alex Ross 已提交
26
import { SupportsWorkspacesContext } from 'vs/platform/contextkey/common/contextkeys';
27
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
E
Erich Gamma 已提交
28 29

// Contribute Global Actions
B
Benjamin Pasero 已提交
30
const category = nls.localize('filesCategory', "File");
E
Erich Gamma 已提交
31

32
const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
R
Rob Lourens 已提交
33
registry.registerWorkbenchAction(new SyncActionDescriptor(SaveAllAction, SaveAllAction.ID, SaveAllAction.LABEL, { 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);
B
Benjamin Pasero 已提交
34 35 36 37 38 39 40
registry.registerWorkbenchAction(new SyncActionDescriptor(GlobalCompareResourcesAction, GlobalCompareResourcesAction.ID, GlobalCompareResourcesAction.LABEL), 'File: Compare Active File With...', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(FocusFilesExplorer, FocusFilesExplorer.ID, FocusFilesExplorer.LABEL), 'File: Focus on Files Explorer', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(ShowActiveFileInExplorer, ShowActiveFileInExplorer.ID, ShowActiveFileInExplorer.LABEL), 'File: Reveal Active File in Side Bar', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(CollapseExplorerView, CollapseExplorerView.ID, CollapseExplorerView.LABEL), 'File: Collapse Folders in Explorer', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(RefreshExplorerView, RefreshExplorerView.ID, RefreshExplorerView.LABEL), 'File: Refresh Explorer', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(GlobalNewUntitledFileAction, GlobalNewUntitledFileAction.ID, GlobalNewUntitledFileAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_N }), 'File: New Untitled File', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(ShowOpenedFileInNewWindow, ShowOpenedFileInNewWindow.ID, ShowOpenedFileInNewWindow.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_O) }), 'File: Open Active File in New Window', category);
M
Max Furman 已提交
41
registry.registerWorkbenchAction(new SyncActionDescriptor(CompareWithClipboardAction, CompareWithClipboardAction.ID, CompareWithClipboardAction.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_C) }), 'File: Compare Active File with Clipboard', category);
B
Benjamin Pasero 已提交
42
registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleAutoSaveAction, ToggleAutoSaveAction.ID, ToggleAutoSaveAction.LABEL), 'File: Toggle Auto Save', category);
43

44 45 46
// Commands
CommandsRegistry.registerCommand('_files.windowOpen', openWindowCommand);

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

I
isidor 已提交
49
const RENAME_ID = 'renameFile';
50
KeybindingsRegistry.registerCommandAndKeybindingRule({
I
isidor 已提交
51
	id: RENAME_ID,
52
	weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
53
	when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerRootContext.toNegated(), ExplorerResourceNotReadonlyContext),
54 55 56 57
	primary: KeyCode.F2,
	mac: {
		primary: KeyCode.Enter
	},
I
isidor 已提交
58
	handler: renameHandler
59 60
});

I
isidor 已提交
61
const MOVE_FILE_TO_TRASH_ID = 'moveFileToTrash';
62
KeybindingsRegistry.registerCommandAndKeybindingRule({
I
isidor 已提交
63
	id: MOVE_FILE_TO_TRASH_ID,
64
	weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
B
Benjamin Pasero 已提交
65
	when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerRootContext.toNegated(), ExplorerResourceNotReadonlyContext, ContextKeyExpr.has('config.files.enableTrash')),
66 67 68 69
	primary: KeyCode.Delete,
	mac: {
		primary: KeyMod.CtrlCmd | KeyCode.Backspace
	},
I
isidor 已提交
70
	handler: moveFileToTrashHandler
71 72
});

73
const DELETE_FILE_ID = 'deleteFile';
74
KeybindingsRegistry.registerCommandAndKeybindingRule({
75
	id: DELETE_FILE_ID,
76
	weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
B
Benjamin Pasero 已提交
77
	when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerRootContext.toNegated(), ExplorerResourceNotReadonlyContext, ContextKeyExpr.has('config.files.enableTrash')),
78 79 80 81
	primary: KeyMod.Shift | KeyCode.Delete,
	mac: {
		primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.Backspace
	},
I
isidor 已提交
82
	handler: deleteFileHandler
83 84
});

B
Benjamin Pasero 已提交
85 86 87 88 89 90 91 92 93 94 95
KeybindingsRegistry.registerCommandAndKeybindingRule({
	id: DELETE_FILE_ID,
	weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
	when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerRootContext.toNegated(), ExplorerResourceNotReadonlyContext, ContextKeyExpr.not('config.files.enableTrash')),
	primary: KeyCode.Delete,
	mac: {
		primary: KeyMod.CtrlCmd | KeyCode.Backspace
	},
	handler: deleteFileHandler
});

I
isidor 已提交
96 97 98 99 100 101 102 103 104
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 已提交
105
const COPY_FILE_ID = 'filesExplorer.copy';
B
Benjamin Pasero 已提交
106
KeybindingsRegistry.registerCommandAndKeybindingRule({
I
isidor 已提交
107
	id: COPY_FILE_ID,
108
	weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
I
isidor 已提交
109
	when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerRootContext.toNegated()),
B
Benjamin Pasero 已提交
110
	primary: KeyMod.CtrlCmd | KeyCode.KEY_C,
I
isidor 已提交
111
	handler: copyFileHandler,
112 113
});

I
isidor 已提交
114 115
const PASTE_FILE_ID = 'filesExplorer.paste';

116
KeybindingsRegistry.registerCommandAndKeybindingRule({
I
isidor 已提交
117
	id: PASTE_FILE_ID,
118
	weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
119
	when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerResourceNotReadonlyContext),
120
	primary: KeyMod.CtrlCmd | KeyCode.KEY_V,
I
isidor 已提交
121
	handler: pasteFileHandler
B
Benjamin Pasero 已提交
122 123
});

124 125 126 127 128 129 130 131 132 133 134
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);
	}
});

135 136 137 138 139 140 141 142 143 144
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")
};

145
// Editor Title Context Menu
146 147
appendEditorTitleContextMenuItem(COPY_PATH_COMMAND_ID, copyPathCommand.title, ResourceContextKey.IsFileSystemResource, '1_cutcopypaste');
appendEditorTitleContextMenuItem(COPY_RELATIVE_PATH_COMMAND_ID, copyRelativePathCommand.title, ResourceContextKey.IsFileSystemResource, '1_cutcopypaste');
B
Benjamin Pasero 已提交
148
appendEditorTitleContextMenuItem(REVEAL_IN_OS_COMMAND_ID, REVEAL_IN_OS_LABEL, ResourceContextKey.Scheme.isEqualTo(Schemas.file));
149
appendEditorTitleContextMenuItem(REVEAL_IN_EXPLORER_COMMAND_ID, nls.localize('revealInSideBar', "Reveal in Side Bar"), ResourceContextKey.IsFileSystemResource);
150

151
function appendEditorTitleContextMenuItem(id: string, title: string, when: ContextKeyExpr, group?: string): void {
152 153 154 155

	// Menu
	MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, {
		command: { id, title },
B
Benjamin Pasero 已提交
156
		when,
157
		group: group || '2_files'
158
	});
159 160 161
}

// Editor Title Menu for Conflict Resolution
B
Benjamin Pasero 已提交
162
appendSaveConflictEditorTitleAction('workbench.files.action.acceptLocalChanges', nls.localize('acceptLocalChanges', "Use your changes and overwrite disk contents"), {
163 164
	light: URI.parse(require.toUrl(`vs/workbench/contrib/files/electron-browser/media/check.svg`)),
	dark: URI.parse(require.toUrl(`vs/workbench/contrib/files/electron-browser/media/check-inverse.svg`))
B
Benjamin Pasero 已提交
165 166
}, -10, acceptLocalChangesCommand);
appendSaveConflictEditorTitleAction('workbench.files.action.revertLocalChanges', nls.localize('revertLocalChanges', "Discard your changes and revert to content on disk"), {
167 168
	light: URI.parse(require.toUrl(`vs/workbench/contrib/files/electron-browser/media/undo.svg`)),
	dark: URI.parse(require.toUrl(`vs/workbench/contrib/files/electron-browser/media/undo-inverse.svg`))
B
Benjamin Pasero 已提交
169
}, -9, revertLocalChangesCommand);
170

171
function appendSaveConflictEditorTitleAction(id: string, title: string, iconLocation: { dark: URI; light?: URI; }, order: number, command: ICommandHandler): void {
172 173 174 175 176 177

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

	// Action
	MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
178
		command: { id, title, iconLocation },
179
		when: ContextKeyExpr.equals(CONFLICT_RESOLUTION_CONTEXT, true),
I
isidor 已提交
180
		group: 'navigation',
181 182
		order
	});
183
}
I
isidor 已提交
184

185 186
// Menu registration - command palette

B
Benjamin Pasero 已提交
187
function appendToCommandPalette(id: string, title: ILocalizedString, category: string, when?: ContextKeyExpr): void {
I
polish  
isidor 已提交
188 189 190 191 192
	MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
		command: {
			id,
			title,
			category
193 194
		},
		when
I
polish  
isidor 已提交
195 196
	});
}
B
Benjamin Pasero 已提交
197 198 199
appendToCommandPalette(COPY_PATH_COMMAND_ID, { value: nls.localize('copyPathOfActive', "Copy Path of Active File"), original: 'File: Copy Path of Active File' }, category);
appendToCommandPalette(COPY_RELATIVE_PATH_COMMAND_ID, { value: nls.localize('copyRelativePathOfActive', "Copy Relative Path of Active File"), original: 'File: Copy Relative Path of Active File' }, category);
appendToCommandPalette(SAVE_FILE_COMMAND_ID, { value: SAVE_FILE_LABEL, original: 'File: Save' }, category);
B
Benjamin Pasero 已提交
200
appendToCommandPalette(SAVE_FILE_WITHOUT_FORMATTING_COMMAND_ID, { value: SAVE_FILE_WITHOUT_FORMATTING_LABEL, original: 'File: Save without Formatting' }, category);
B
Benjamin Pasero 已提交
201 202 203 204 205
appendToCommandPalette(SAVE_ALL_IN_GROUP_COMMAND_ID, { value: nls.localize('saveAllInGroup', "Save All in Group"), original: 'File: Save All in Group' }, category);
appendToCommandPalette(SAVE_FILES_COMMAND_ID, { value: nls.localize('saveFiles', "Save All Files"), original: 'File: Save All Files' }, category);
appendToCommandPalette(REVERT_FILE_COMMAND_ID, { value: nls.localize('revert', "Revert File"), original: 'File: Revert File' }, category);
appendToCommandPalette(COMPARE_WITH_SAVED_COMMAND_ID, { value: nls.localize('compareActiveWithSaved', "Compare Active File with Saved"), original: 'File: Compare Active File with Saved' }, category);
appendToCommandPalette(REVEAL_IN_OS_COMMAND_ID, { value: REVEAL_IN_OS_LABEL, original: isWindows ? 'File: Reveal in Explorer' : isMacintosh ? 'File: Reveal in Finder' : 'File: Open Containing Folder' }, category);
M
Martin Aeschlimann 已提交
206
appendToCommandPalette(SAVE_FILE_AS_COMMAND_ID, { value: SAVE_FILE_AS_LABEL, original: 'File: Save As...' }, category);
B
Benjamin Pasero 已提交
207 208 209
appendToCommandPalette(CLOSE_EDITOR_COMMAND_ID, { value: nls.localize('closeEditor', "Close Editor"), original: 'View: Close Editor' }, nls.localize('view', "View"));
appendToCommandPalette(NEW_FILE_COMMAND_ID, { value: NEW_FILE_LABEL, original: 'File: New File' }, category);
appendToCommandPalette(NEW_FOLDER_COMMAND_ID, { value: NEW_FOLDER_LABEL, original: 'File: New Folder' }, category);
I
isidor 已提交
210

211 212 213 214 215 216 217
// 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 已提交
218
	group: 'navigation',
219 220
	order: 10,
	command: openToSideCommand,
221
	when: ResourceContextKey.IsFileSystemResource
222 223 224 225 226 227 228
});

const revealInOsCommand = {
	id: REVEAL_IN_OS_COMMAND_ID,
	title: isWindows ? nls.localize('revealInWindows', "Reveal in Explorer") : isMacintosh ? nls.localize('revealInMac', "Reveal in Finder") : nls.localize('openContainer', "Open Containing Folder")
};
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
I
isidor 已提交
229
	group: 'navigation',
230 231
	order: 20,
	command: revealInOsCommand,
232
	when: ResourceContextKey.IsFileSystemResource
233 234 235
});

MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
236 237
	group: '1_cutcopypaste',
	order: 10,
238
	command: copyPathCommand,
239 240 241 242 243 244 245
	when: ResourceContextKey.IsFileSystemResource
});

MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
	group: '1_cutcopypaste',
	order: 20,
	command: copyRelativePathCommand,
246
	when: ResourceContextKey.IsFileSystemResource
247 248 249 250 251 252 253
});

MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
	group: '2_save',
	order: 10,
	command: {
		id: SAVE_FILE_COMMAND_ID,
254 255
		title: SAVE_FILE_LABEL,
		precondition: DirtyEditorContext
256
	},
257
	when: ContextKeyExpr.and(ResourceContextKey.IsFileSystemResource, AutoSaveContext.notEqualsTo('afterDelay') && AutoSaveContext.notEqualsTo(''))
258 259 260 261 262 263 264
});

MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
	group: '2_save',
	order: 20,
	command: {
		id: REVERT_FILE_COMMAND_ID,
265 266
		title: nls.localize('revert', "Revert File"),
		precondition: DirtyEditorContext
267
	},
268
	when: ContextKeyExpr.and(ResourceContextKey.IsFileSystemResource, AutoSaveContext.notEqualsTo('afterDelay') && AutoSaveContext.notEqualsTo(''))
269 270 271 272 273 274 275 276
});

MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
	group: '2_save',
	command: {
		id: SAVE_FILE_AS_COMMAND_ID,
		title: SAVE_FILE_AS_LABEL
	},
277
	when: ResourceContextKey.Scheme.isEqualTo(Schemas.untitled)
278 279 280 281 282 283 284 285
});

MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
	group: '2_save',
	command: {
		id: SAVE_ALL_IN_GROUP_COMMAND_ID,
		title: nls.localize('saveAll', "Save All")
	},
286
	when: ContextKeyExpr.and(OpenEditorsGroupContext, AutoSaveContext.notEqualsTo('afterDelay') && AutoSaveContext.notEqualsTo(''))
287 288 289 290 291 292 293
});

MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
	group: '3_compare',
	order: 10,
	command: {
		id: COMPARE_WITH_SAVED_COMMAND_ID,
294 295
		title: nls.localize('compareWithSaved', "Compare with Saved"),
		precondition: DirtyEditorContext
296
	},
297
	when: ContextKeyExpr.and(ResourceContextKey.IsFileSystemResource, AutoSaveContext.notEqualsTo('afterDelay') && AutoSaveContext.notEqualsTo(''), WorkbenchListDoubleSelection.toNegated())
298 299 300 301
});

const compareResourceCommand = {
	id: COMPARE_RESOURCE_COMMAND_ID,
I
isidor 已提交
302
	title: nls.localize('compareWithSelected', "Compare with Selected")
303 304 305 306 307
};
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
	group: '3_compare',
	order: 20,
	command: compareResourceCommand,
I
isidor 已提交
308
	when: ContextKeyExpr.and(ResourceContextKey.HasResource, ResourceSelectedForCompareContext, WorkbenchListDoubleSelection.toNegated())
309 310 311 312 313 314 315 316 317 318
});

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 已提交
319
	when: ContextKeyExpr.and(ResourceContextKey.HasResource, WorkbenchListDoubleSelection.toNegated())
I
isidor 已提交
320 321 322 323 324 325 326 327 328 329
});

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 已提交
330
	when: ContextKeyExpr.and(ResourceContextKey.HasResource, WorkbenchListDoubleSelection)
331 332 333 334 335 336 337 338 339
});

MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
	group: '4_close',
	order: 10,
	command: {
		id: CLOSE_EDITOR_COMMAND_ID,
		title: nls.localize('close', "Close")
	},
B
Benjamin Pasero 已提交
340
	when: OpenEditorsGroupContext.toNegated()
341 342 343 344 345 346 347 348 349
});

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 已提交
350
	when: OpenEditorsGroupContext.toNegated()
351 352 353 354 355 356
});

MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
	group: '4_close',
	order: 30,
	command: {
357
		id: CLOSE_SAVED_EDITORS_COMMAND_ID,
358
		title: nls.localize('closeSaved', "Close Saved")
359 360 361 362 363 364 365 366 367 368 369 370 371 372
	}
});

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 已提交
373
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
I
isidor 已提交
374
	group: 'navigation',
I
isidor 已提交
375 376 377
	order: 4,
	command: {
		id: NEW_FILE_COMMAND_ID,
378
		title: NEW_FILE_LABEL,
379
		precondition: ExplorerResourceNotReadonlyContext
I
isidor 已提交
380
	},
I
isidor 已提交
381
	when: ExplorerFolderContext
I
isidor 已提交
382 383 384
});

MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
I
isidor 已提交
385
	group: 'navigation',
I
isidor 已提交
386 387 388
	order: 6,
	command: {
		id: NEW_FOLDER_COMMAND_ID,
389
		title: NEW_FOLDER_LABEL,
390
		precondition: ExplorerResourceNotReadonlyContext
I
isidor 已提交
391
	},
I
isidor 已提交
392
	when: ExplorerFolderContext
I
isidor 已提交
393 394
});

395
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
I
isidor 已提交
396
	group: 'navigation',
397 398
	order: 10,
	command: openToSideCommand,
399
	when: ContextKeyExpr.and(ExplorerFolderContext.toNegated(), ResourceContextKey.HasResource)
400 401 402
});

MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
I
isidor 已提交
403
	group: 'navigation',
404 405
	order: 20,
	command: revealInOsCommand,
B
Benjamin Pasero 已提交
406
	when: ResourceContextKey.Scheme.isEqualTo(Schemas.file)
407 408 409 410 411 412
});

MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
	group: '3_compare',
	order: 20,
	command: compareResourceCommand,
413
	when: ContextKeyExpr.and(ExplorerFolderContext.toNegated(), ResourceContextKey.HasResource, ResourceSelectedForCompareContext, WorkbenchListDoubleSelection.toNegated())
414 415 416 417 418 419
});

MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
	group: '3_compare',
	order: 30,
	command: selectForCompareCommand,
420
	when: ContextKeyExpr.and(ExplorerFolderContext.toNegated(), ResourceContextKey.HasResource, WorkbenchListDoubleSelection.toNegated())
I
isidor 已提交
421 422 423 424 425
});

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

I
isidor 已提交
430 431 432 433 434 435 436 437 438 439
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
	group: '5_cutcopypaste',
	order: 8,
	command: {
		id: CUT_FILE_ID,
		title: nls.localize('cut', "Cut")
	},
	when: ExplorerRootContext.toNegated()
});

I
isidor 已提交
440
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
I
isidor 已提交
441
	group: '5_cutcopypaste',
I
isidor 已提交
442 443 444 445 446 447 448 449 450
	order: 10,
	command: {
		id: COPY_FILE_ID,
		title: COPY_FILE_LABEL
	},
	when: ExplorerRootContext.toNegated()
});

MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
I
isidor 已提交
451
	group: '5_cutcopypaste',
I
isidor 已提交
452 453 454
	order: 20,
	command: {
		id: PASTE_FILE_ID,
455
		title: PASTE_FILE_LABEL,
456
		precondition: ContextKeyExpr.and(ExplorerResourceNotReadonlyContext, FileCopiedContext)
I
isidor 已提交
457
	},
458
	when: ExplorerFolderContext
I
isidor 已提交
459 460 461
});

MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
462
	group: '6_copypath',
I
isidor 已提交
463 464
	order: 30,
	command: copyPathCommand,
465 466 467 468
	when: ResourceContextKey.IsFileSystemResource
});

MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
469
	group: '6_copypath',
470 471
	order: 30,
	command: copyRelativePathCommand,
472
	when: ResourceContextKey.IsFileSystemResource
I
isidor 已提交
473 474
});

I
isidor 已提交
475 476 477 478 479 480 481
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
	group: '2_workspace',
	order: 10,
	command: {
		id: ADD_ROOT_FOLDER_COMMAND_ID,
		title: ADD_ROOT_FOLDER_LABEL
	},
A
Alex Ross 已提交
482
	when: ContextKeyExpr.and(ExplorerRootContext, SupportsWorkspacesContext)
I
isidor 已提交
483
});
I
isidor 已提交
484

I
isidor 已提交
485 486 487 488 489 490 491 492 493
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
	group: '2_workspace',
	order: 30,
	command: {
		id: REMOVE_ROOT_FOLDER_COMMAND_ID,
		title: REMOVE_ROOT_FOLDER_LABEL
	},
	when: ContextKeyExpr.and(ExplorerRootContext, ExplorerFolderContext)
});
I
isidor 已提交
494 495

MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
I
isidor 已提交
496
	group: '7_modification',
I
isidor 已提交
497 498
	order: 10,
	command: {
I
isidor 已提交
499
		id: RENAME_ID,
500
		title: TRIGGER_RENAME_LABEL,
501
		precondition: ExplorerResourceNotReadonlyContext
I
isidor 已提交
502 503 504
	},
	when: ExplorerRootContext.toNegated()
});
I
isidor 已提交
505 506

MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
I
isidor 已提交
507
	group: '7_modification',
I
isidor 已提交
508 509 510
	order: 20,
	command: {
		id: MOVE_FILE_TO_TRASH_ID,
511
		title: MOVE_FILE_TO_TRASH_LABEL,
512
		precondition: ExplorerResourceNotReadonlyContext
I
isidor 已提交
513
	},
514 515
	alt: {
		id: DELETE_FILE_ID,
516
		title: nls.localize('deleteFile', "Delete Permanently"),
517
		precondition: ExplorerResourceNotReadonlyContext
518
	},
B
Benjamin Pasero 已提交
519 520 521 522 523 524 525 526 527 528 529 530
	when: ContextKeyExpr.and(ExplorerRootContext.toNegated(), ContextKeyExpr.has('config.files.enableTrash'))
});

MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
	group: '7_modification',
	order: 20,
	command: {
		id: DELETE_FILE_ID,
		title: nls.localize('deleteFile', "Delete Permanently"),
		precondition: ExplorerResourceNotReadonlyContext
	},
	when: ContextKeyExpr.and(ExplorerRootContext.toNegated(), ContextKeyExpr.not('config.files.enableTrash'))
I
isidor 已提交
531
});
532 533

// Empty Editor Group Context Menu
I
isidor 已提交
534
MenuRegistry.appendMenuItem(MenuId.EmptyEditorGroupContext, { command: { id: GlobalNewUntitledFileAction.ID, title: nls.localize('newFile', "New File") }, group: '1_file', order: 10 });
535
MenuRegistry.appendMenuItem(MenuId.EmptyEditorGroupContext, { command: { id: 'workbench.action.quickOpen', title: nls.localize('openFile', "Open File...") }, group: '1_file', order: 20 });
I
isidor 已提交
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551

// 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,
552
		title: nls.localize({ key: 'miSave', comment: ['&& denotes a mnemonic'] }, "&&Save")
I
isidor 已提交
553 554 555 556 557 558 559 560
	},
	order: 1
});

MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
	group: '4_save',
	command: {
		id: SAVE_FILE_AS_COMMAND_ID,
561
		title: nls.localize({ key: 'miSaveAs', comment: ['&& denotes a mnemonic'] }, "Save &&As...")
I
isidor 已提交
562
	},
M
Martin Aeschlimann 已提交
563
	order: 2
I
isidor 已提交
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
});

MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
	group: '4_save',
	command: {
		id: SaveAllAction.ID,
		title: nls.localize({ key: 'miSaveAll', comment: ['&& denotes a mnemonic'] }, "Save A&&ll")
	},
	order: 3
});

MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
	group: '5_autosave',
	command: {
		id: ToggleAutoSaveAction.ID,
579 580
		title: nls.localize({ key: 'miAutoSave', comment: ['&& denotes a mnemonic'] }, "A&&uto Save"),
		toggled: ContextKeyExpr.notEquals('config.files.autoSave', 'off')
I
isidor 已提交
581 582 583 584 585 586 587 588
	},
	order: 1
});

MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
	group: '6_close',
	command: {
		id: REVERT_FILE_COMMAND_ID,
589
		title: nls.localize({ key: 'miRevert', comment: ['&& denotes a mnemonic'] }, "Re&&vert File")
I
isidor 已提交
590 591 592 593 594 595 596 597 598 599 600 601
	},
	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
});
602 603 604 605

// Go to menu

MenuRegistry.appendMenuItem(MenuId.MenubarGoMenu, {
606
	group: '3_global_nav',
607 608 609 610 611
	command: {
		id: 'workbench.action.quickOpen',
		title: nls.localize({ key: 'miGotoFile', comment: ['&& denotes a mnemonic'] }, "Go to &&File...")
	},
	order: 1
612
});