Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/files/browser/fileActions.contribution.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as nls from '../../../../nls.js';
7
import { ToggleAutoSaveAction, FocusFilesExplorer, GlobalCompareResourcesAction, ShowActiveFileInExplorer, 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, OpenActiveFileInEmptyWorkspace, UPLOAD_COMMAND_ID, UPLOAD_LABEL, CompareNewUntitledTextFilesAction, SetActiveEditorReadonlyInSession, SetActiveEditorWriteableInSession, ToggleActiveEditorReadonlyInSession, ResetActiveEditorReadonlyInSession } from './fileActions.js';
8
import { revertLocalChangesCommand, acceptLocalChangesCommand, CONFLICT_RESOLUTION_CONTEXT } from './editors/textFileSaveErrorHandler.js';
9
import { MenuId, MenuRegistry, registerAction2 } from '../../../../platform/actions/common/actions.js';
10
import { ICommandAction } from '../../../../platform/action/common/action.js';
11
import { KeyMod, KeyCode } from '../../../../base/common/keyCodes.js';
12
import { openWindowCommand, newWindowCommand } from './fileCommands.js';
13
import { 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, OpenEditorsDirtyEditorContext, 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, OpenEditorsReadonlyEditorContext, OPEN_WITH_EXPLORER_COMMAND_ID, NEW_UNTITLED_FILE_COMMAND_ID, NEW_UNTITLED_FILE_LABEL, SAVE_ALL_COMMAND_ID, OpenEditorsSelectedFileOrUntitledContext } from './fileConstants.js';
14
import { CommandsRegistry, ICommandHandler } from '../../../../platform/commands/common/commands.js';
15
import { ContextKeyExpr, ContextKeyExpression } from '../../../../platform/contextkey/common/contextkey.js';
16
import { KeybindingsRegistry, KeybindingWeight } from '../../../../platform/keybinding/common/keybindingsRegistry.js';
17
import { FilesExplorerFocusCondition, ExplorerRootContext, ExplorerFolderContext, ExplorerResourceWritableContext, ExplorerResourceCut, ExplorerResourceMoveableToTrash, ExplorerResourceAvailableEditorIdsContext, FoldersViewVisibleContext } from '../common/files.js';
18
import { ADD_ROOT_FOLDER_COMMAND_ID, ADD_ROOT_FOLDER_LABEL } from '../../../browser/actions/workspaceCommands.js';
19
import { CLOSE_SAVED_EDITORS_COMMAND_ID, CLOSE_EDITORS_IN_GROUP_COMMAND_ID, CLOSE_EDITOR_COMMAND_ID, CLOSE_OTHER_EDITORS_IN_GROUP_COMMAND_ID, REOPEN_WITH_COMMAND_ID } from '../../../browser/parts/editor/editorCommands.js';
20
import { AutoSaveAfterShortDelayContext } from '../../../services/filesConfiguration/common/filesConfigurationService.js';
21
import { WorkbenchListDoubleSelection } from '../../../../platform/list/browser/listService.js';
22
import { Schemas } from '../../../../base/common/network.js';
23
import { DirtyWorkingCopiesContext, EnterMultiRootWorkspaceSupportContext, HasWebFileSystemAccess, WorkbenchStateContext, WorkspaceFolderCountContext, SidebarFocusContext, ActiveEditorCanRevertContext, ActiveEditorContext, ResourceContextKey, ActiveEditorAvailableEditorIdsContext, MultipleEditorsSelectedInGroupContext, TwoEditorsSelectedInGroupContext, SelectedEditorsInGroupFileOrUntitledResourceContextKey } from '../../../common/contextkeys.js';
24
import { IsWebContext } from '../../../../platform/contextkey/common/contextkeys.js';
25
import { ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js';
26
import { ThemeIcon } from '../../../../base/common/themables.js';
27
import { IExplorerService } from './files.js';
28
import { Codicon } from '../../../../base/common/codicons.js';
29
import { Categories } from '../../../../platform/action/common/actionCommonCategories.js';
30
31
// Contribute Global Actions
32
33
registerAction2(GlobalCompareResourcesAction);
34
registerAction2(FocusFilesExplorer);
35
registerAction2(ShowActiveFileInExplorer);
36
registerAction2(CompareWithClipboardAction);
37
registerAction2(CompareNewUntitledTextFilesAction);
38
registerAction2(ToggleAutoSaveAction);
39
registerAction2(OpenActiveFileInEmptyWorkspace);
40
registerAction2(SetActiveEditorReadonlyInSession);
41
registerAction2(SetActiveEditorWriteableInSession);
42
registerAction2(ToggleActiveEditorReadonlyInSession);
43
registerAction2(ResetActiveEditorReadonlyInSession);
44
45
// Commands
46
CommandsRegistry.registerCommand('_files.windowOpen', openWindowCommand);
47
CommandsRegistry.registerCommand('_files.newWindow', newWindowCommand);
48
49
const explorerCommandsWeightBonus = 10; // give our commands a little bit more weight over other default list/tree commands
50
51
const RENAME_ID = 'renameFile';
52
KeybindingsRegistry.registerCommandAndKeybindingRule({
53
id: RENAME_ID,
54
weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
55
when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerRootContext.toNegated(), ExplorerResourceWritableContext),
56
primary: KeyCode.F2,
57
mac: {
58
primary: KeyCode.Enter
59
},
60
handler: renameHandler
61
});
62
63
const MOVE_FILE_TO_TRASH_ID = 'moveFileToTrash';
64
KeybindingsRegistry.registerCommandAndKeybindingRule({
65
id: MOVE_FILE_TO_TRASH_ID,
66
weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
67
when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerResourceMoveableToTrash),
68
primary: KeyCode.Delete,
69
mac: {
70
primary: KeyMod.CtrlCmd | KeyCode.Backspace,
71
secondary: [KeyCode.Delete]
72
},
73
handler: moveFileToTrashHandler
74
});
75
76
const DELETE_FILE_ID = 'deleteFile';
77
KeybindingsRegistry.registerCommandAndKeybindingRule({
78
id: DELETE_FILE_ID,
79
weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
80
when: FilesExplorerFocusCondition,
81
primary: KeyMod.Shift | KeyCode.Delete,
82
mac: {
83
primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.Backspace
84
},
85
handler: deleteFileHandler
86
});
87
88
KeybindingsRegistry.registerCommandAndKeybindingRule({
89
id: DELETE_FILE_ID,
90
weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
91
when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerResourceMoveableToTrash.toNegated()),
92
primary: KeyCode.Delete,
93
mac: {
94
primary: KeyMod.CtrlCmd | KeyCode.Backspace
95
},
96
handler: deleteFileHandler
97
});
98
99
const CUT_FILE_ID = 'filesExplorer.cut';
100
KeybindingsRegistry.registerCommandAndKeybindingRule({
101
id: CUT_FILE_ID,
102
weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
103
when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerRootContext.toNegated(), ExplorerResourceWritableContext),
104
primary: KeyMod.CtrlCmd | KeyCode.KeyX,
105
handler: cutFileHandler,
106
});
107
108
const COPY_FILE_ID = 'filesExplorer.copy';
109
KeybindingsRegistry.registerCommandAndKeybindingRule({
110
id: COPY_FILE_ID,
111
weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
112
when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerRootContext.toNegated()),
113
primary: KeyMod.CtrlCmd | KeyCode.KeyC,
114
handler: copyFileHandler,
115
});
116
117
const PASTE_FILE_ID = 'filesExplorer.paste';
118
119
CommandsRegistry.registerCommand(PASTE_FILE_ID, pasteFileHandler);
120
121
KeybindingsRegistry.registerKeybindingRule({
122
id: `^${PASTE_FILE_ID}`, // the `^` enables pasting files into the explorer by preventing default bubble up
123
weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
124
when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerResourceWritableContext),
125
primary: KeyMod.CtrlCmd | KeyCode.KeyV,
126
});
127
128
KeybindingsRegistry.registerCommandAndKeybindingRule({
129
id: 'filesExplorer.cancelCut',
130
weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
131
when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerResourceCut),
132
primary: KeyCode.Escape,
133
handler: async (accessor: ServicesAccessor) => {
134
const explorerService = accessor.get(IExplorerService);
135
await explorerService.setToCopy([], true);
136
}
137
});
138
139
KeybindingsRegistry.registerCommandAndKeybindingRule({
140
id: 'filesExplorer.openFilePreserveFocus',
141
weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus,
142
when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerFolderContext.toNegated()),
143
primary: KeyCode.Space,
144
handler: openFilePreserveFocusHandler
145
});
146
147
const copyPathCommand = {
148
id: COPY_PATH_COMMAND_ID,
149
title: nls.localize('copyPath', "Copy Path")
150
};
151
152
const copyRelativePathCommand = {
153
id: COPY_RELATIVE_PATH_COMMAND_ID,
154
title: nls.localize('copyRelativePath', "Copy Relative Path")
155
};
156
157
export const revealInSideBarCommand = {
158
id: REVEAL_IN_EXPLORER_COMMAND_ID,
159
title: nls.localize('revealInSideBar', "Reveal in Explorer View")
160
};
161
162
// Editor Title Context Menu
163
appendEditorTitleContextMenuItem(COPY_PATH_COMMAND_ID, copyPathCommand.title, ResourceContextKey.IsFileSystemResource, '1_cutcopypaste', true);
164
appendEditorTitleContextMenuItem(COPY_RELATIVE_PATH_COMMAND_ID, copyRelativePathCommand.title, ResourceContextKey.IsFileSystemResource, '1_cutcopypaste', true);
165
appendEditorTitleContextMenuItem(revealInSideBarCommand.id, revealInSideBarCommand.title, ResourceContextKey.IsFileSystemResource, '2_files', false, 1);
166
167
export function appendEditorTitleContextMenuItem(id: string, title: string, when: ContextKeyExpression | undefined, group: string, supportsMultiSelect: boolean, order?: number): void {
168
const precondition = supportsMultiSelect !== true ? MultipleEditorsSelectedInGroupContext.negate() : undefined;
169
170
// Menu
171
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, {
172
command: { id, title, precondition },
173
when,
174
group,
175
order,
176
});
177
}
178
179
// Editor Title Menu for Conflict Resolution
180
appendSaveConflictEditorTitleAction('workbench.files.action.acceptLocalChanges', nls.localize('acceptLocalChanges', "Use your changes and overwrite file contents"), Codicon.check, -10, acceptLocalChangesCommand);
181
appendSaveConflictEditorTitleAction('workbench.files.action.revertLocalChanges', nls.localize('revertLocalChanges', "Discard your changes and revert to file contents"), Codicon.discard, -9, revertLocalChangesCommand);
182
183
function appendSaveConflictEditorTitleAction(id: string, title: string, icon: ThemeIcon, order: number, command: ICommandHandler): void {
184
185
// Command
186
CommandsRegistry.registerCommand(id, command);
187
188
// Action
189
MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
190
command: { id, title, icon },
191
when: ContextKeyExpr.equals(CONFLICT_RESOLUTION_CONTEXT, true),
192
group: 'navigation',
193
order
194
});
195
}
196
197
// Menu registration - command palette
198
199
export function appendToCommandPalette({ id, title, category, metadata }: ICommandAction, when?: ContextKeyExpression): void {
200
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
201
command: {
202
id,
203
title,
204
category,
205
metadata
206
},
207
when
208
});
209
}
210
211
appendToCommandPalette({
212
id: COPY_PATH_COMMAND_ID,
213
title: nls.localize2('copyPathOfActive', "Copy Path of Active File"),
214
category: Categories.File
215
});
216
appendToCommandPalette({
217
id: COPY_RELATIVE_PATH_COMMAND_ID,
218
title: nls.localize2('copyRelativePathOfActive', "Copy Relative Path of Active File"),
219
category: Categories.File
220
});
221
222
appendToCommandPalette({
223
id: SAVE_FILE_COMMAND_ID,
224
title: SAVE_FILE_LABEL,
225
category: Categories.File
226
});
227
228
appendToCommandPalette({
229
id: SAVE_FILE_WITHOUT_FORMATTING_COMMAND_ID,
230
title: SAVE_FILE_WITHOUT_FORMATTING_LABEL,
231
category: Categories.File
232
});
233
234
appendToCommandPalette({
235
id: SAVE_ALL_IN_GROUP_COMMAND_ID,
236
title: nls.localize2('saveAllInGroup', "Save All in Group"),
237
category: Categories.File
238
});
239
240
appendToCommandPalette({
241
id: SAVE_FILES_COMMAND_ID,
242
title: nls.localize2('saveFiles', "Save All Files"),
243
category: Categories.File
244
});
245
246
appendToCommandPalette({
247
id: REVERT_FILE_COMMAND_ID,
248
title: nls.localize2('revert', "Revert File"),
249
category: Categories.File
250
});
251
252
appendToCommandPalette({
253
id: COMPARE_WITH_SAVED_COMMAND_ID,
254
title: nls.localize2('compareActiveWithSaved', "Compare Active File with Saved"),
255
category: Categories.File,
256
metadata: {
257
description: nls.localize2('compareActiveWithSavedMeta', "Opens a new diff editor to compare the active file with the version on disk.")
258
}
259
});
260
261
appendToCommandPalette({
262
id: SAVE_FILE_AS_COMMAND_ID,
263
title: SAVE_FILE_AS_LABEL,
264
category: Categories.File
265
});
266
267
appendToCommandPalette({
268
id: NEW_FILE_COMMAND_ID,
269
title: NEW_FILE_LABEL,
270
category: Categories.File
271
}, WorkspaceFolderCountContext.notEqualsTo('0'));
272
273
appendToCommandPalette({
274
id: NEW_FOLDER_COMMAND_ID,
275
title: NEW_FOLDER_LABEL,
276
category: Categories.File,
277
metadata: { description: nls.localize2('newFolderDescription', "Create a new folder or directory") }
278
}, WorkspaceFolderCountContext.notEqualsTo('0'));
279
280
appendToCommandPalette({
281
id: NEW_UNTITLED_FILE_COMMAND_ID,
282
title: NEW_UNTITLED_FILE_LABEL,
283
category: Categories.File
284
});
285
286
// Menu registration - open editors
287
288
const isFileOrUntitledResourceContextKey = ContextKeyExpr.or(ResourceContextKey.IsFileSystemResource, ResourceContextKey.Scheme.isEqualTo(Schemas.untitled));
289
290
const openToSideCommand = {
291
id: OPEN_TO_SIDE_COMMAND_ID,
292
title: nls.localize('openToSide', "Open to the Side")
293
};
294
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
295
group: 'navigation',
296
order: 10,
297
command: openToSideCommand,
298
when: isFileOrUntitledResourceContextKey
299
});
300
301
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
302
group: '1_open',
303
order: 10,
304
command: {
305
id: REOPEN_WITH_COMMAND_ID,
306
title: nls.localize('reopenWith', "Reopen Editor With...")
307
},
308
when: ContextKeyExpr.and(
309
// Editors with Available Choices to Open With
310
ActiveEditorAvailableEditorIdsContext,
311
// Not: editor groups
312
OpenEditorsGroupContext.toNegated()
313
)
314
});
315
316
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
317
group: '1_cutcopypaste',
318
order: 10,
319
command: copyPathCommand,
320
when: ResourceContextKey.IsFileSystemResource
321
});
322
323
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
324
group: '1_cutcopypaste',
325
order: 20,
326
command: copyRelativePathCommand,
327
when: ResourceContextKey.IsFileSystemResource
328
});
329
330
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
331
group: '2_save',
332
order: 10,
333
command: {
334
id: SAVE_FILE_COMMAND_ID,
335
title: SAVE_FILE_LABEL,
336
precondition: OpenEditorsDirtyEditorContext
337
},
338
when: ContextKeyExpr.or(
339
// Untitled Editors
340
ResourceContextKey.Scheme.isEqualTo(Schemas.untitled),
341
// Or:
342
ContextKeyExpr.and(
343
// Not: editor groups
344
OpenEditorsGroupContext.toNegated(),
345
// Not: readonly editors
346
OpenEditorsReadonlyEditorContext.toNegated(),
347
// Not: auto save after short delay
348
AutoSaveAfterShortDelayContext.toNegated()
349
)
350
)
351
});
352
353
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
354
group: '2_save',
355
order: 20,
356
command: {
357
id: REVERT_FILE_COMMAND_ID,
358
title: nls.localize('revert', "Revert File"),
359
precondition: OpenEditorsDirtyEditorContext
360
},
361
when: ContextKeyExpr.and(
362
// Not: editor groups
363
OpenEditorsGroupContext.toNegated(),
364
// Not: readonly editors
365
OpenEditorsReadonlyEditorContext.toNegated(),
366
// Not: untitled editors (revert closes them)
367
ResourceContextKey.Scheme.notEqualsTo(Schemas.untitled),
368
// Not: auto save after short delay
369
AutoSaveAfterShortDelayContext.toNegated()
370
)
371
});
372
373
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
374
group: '2_save',
375
order: 30,
376
command: {
377
id: SAVE_ALL_IN_GROUP_COMMAND_ID,
378
title: nls.localize('saveAll', "Save All"),
379
precondition: DirtyWorkingCopiesContext
380
},
381
// Editor Group
382
when: OpenEditorsGroupContext
383
});
384
385
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
386
group: '3_compare',
387
order: 10,
388
command: {
389
id: COMPARE_WITH_SAVED_COMMAND_ID,
390
title: nls.localize('compareWithSaved', "Compare with Saved"),
391
precondition: OpenEditorsDirtyEditorContext
392
},
393
when: ContextKeyExpr.and(ResourceContextKey.IsFileSystemResource, AutoSaveAfterShortDelayContext.toNegated(), WorkbenchListDoubleSelection.toNegated())
394
});
395
396
const compareResourceCommand = {
397
id: COMPARE_RESOURCE_COMMAND_ID,
398
title: nls.localize('compareWithSelected', "Compare with Selected")
399
};
400
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
401
group: '3_compare',
402
order: 20,
403
command: compareResourceCommand,
404
when: ContextKeyExpr.and(ResourceContextKey.HasResource, ResourceSelectedForCompareContext, isFileOrUntitledResourceContextKey, WorkbenchListDoubleSelection.toNegated())
405
});
406
407
const selectForCompareCommand = {
408
id: SELECT_FOR_COMPARE_COMMAND_ID,
409
title: nls.localize('compareSource', "Select for Compare")
410
};
411
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
412
group: '3_compare',
413
order: 30,
414
command: selectForCompareCommand,
415
when: ContextKeyExpr.and(ResourceContextKey.HasResource, isFileOrUntitledResourceContextKey, WorkbenchListDoubleSelection.toNegated())
416
});
417
418
const compareSelectedCommand = {
419
id: COMPARE_SELECTED_COMMAND_ID,
420
title: nls.localize('compareSelected', "Compare Selected")
421
};
422
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
423
group: '3_compare',
424
order: 30,
425
command: compareSelectedCommand,
426
when: ContextKeyExpr.and(ResourceContextKey.HasResource, WorkbenchListDoubleSelection, OpenEditorsSelectedFileOrUntitledContext)
427
});
428
429
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, {
430
group: '1_compare',
431
order: 30,
432
command: compareSelectedCommand,
433
when: ContextKeyExpr.and(ResourceContextKey.HasResource, TwoEditorsSelectedInGroupContext, SelectedEditorsInGroupFileOrUntitledResourceContextKey)
434
});
435
436
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
437
group: '4_close',
438
order: 10,
439
command: {
440
id: CLOSE_EDITOR_COMMAND_ID,
441
title: nls.localize('close', "Close")
442
},
443
when: OpenEditorsGroupContext.toNegated()
444
});
445
446
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
447
group: '4_close',
448
order: 20,
449
command: {
450
id: CLOSE_OTHER_EDITORS_IN_GROUP_COMMAND_ID,
451
title: nls.localize('closeOthers', "Close Others")
452
},
453
when: OpenEditorsGroupContext.toNegated()
454
});
455
456
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
457
group: '4_close',
458
order: 30,
459
command: {
460
id: CLOSE_SAVED_EDITORS_COMMAND_ID,
461
title: nls.localize('closeSaved', "Close Saved")
462
}
463
});
464
465
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
466
group: '4_close',
467
order: 40,
468
command: {
469
id: CLOSE_EDITORS_IN_GROUP_COMMAND_ID,
470
title: nls.localize('closeAll', "Close All")
471
}
472
});
473
474
// Menu registration - explorer
475
476
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
477
group: 'navigation',
478
order: 4,
479
command: {
480
id: NEW_FILE_COMMAND_ID,
481
title: NEW_FILE_LABEL,
482
precondition: ExplorerResourceWritableContext
483
},
484
when: ExplorerFolderContext
485
});
486
487
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
488
group: 'navigation',
489
order: 6,
490
command: {
491
id: NEW_FOLDER_COMMAND_ID,
492
title: NEW_FOLDER_LABEL,
493
precondition: ExplorerResourceWritableContext
494
},
495
when: ExplorerFolderContext
496
});
497
498
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
499
group: 'navigation',
500
order: 10,
501
command: openToSideCommand,
502
when: ContextKeyExpr.and(ExplorerFolderContext.toNegated(), ResourceContextKey.HasResource)
503
});
504
505
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
506
group: 'navigation',
507
order: 20,
508
command: {
509
id: OPEN_WITH_EXPLORER_COMMAND_ID,
510
title: nls.localize('explorerOpenWith', "Open With..."),
511
},
512
when: ContextKeyExpr.and(ExplorerFolderContext.toNegated(), ExplorerResourceAvailableEditorIdsContext),
513
});
514
515
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
516
group: '3_compare',
517
order: 20,
518
command: compareResourceCommand,
519
when: ContextKeyExpr.and(ExplorerFolderContext.toNegated(), ResourceContextKey.HasResource, ResourceSelectedForCompareContext, WorkbenchListDoubleSelection.toNegated())
520
});
521
522
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
523
group: '3_compare',
524
order: 30,
525
command: selectForCompareCommand,
526
when: ContextKeyExpr.and(ExplorerFolderContext.toNegated(), ResourceContextKey.HasResource, WorkbenchListDoubleSelection.toNegated())
527
});
528
529
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
530
group: '3_compare',
531
order: 30,
532
command: compareSelectedCommand,
533
when: ContextKeyExpr.and(ExplorerFolderContext.toNegated(), ResourceContextKey.HasResource, WorkbenchListDoubleSelection)
534
});
535
536
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
537
group: '5_cutcopypaste',
538
order: 8,
539
command: {
540
id: CUT_FILE_ID,
541
title: nls.localize('cut', "Cut"),
542
},
543
when: ContextKeyExpr.and(ExplorerRootContext.toNegated(), ExplorerResourceWritableContext)
544
});
545
546
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
547
group: '5_cutcopypaste',
548
order: 10,
549
command: {
550
id: COPY_FILE_ID,
551
title: COPY_FILE_LABEL,
552
},
553
when: ExplorerRootContext.toNegated()
554
});
555
556
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
557
group: '5_cutcopypaste',
558
order: 20,
559
command: {
560
id: PASTE_FILE_ID,
561
title: PASTE_FILE_LABEL,
562
precondition: ContextKeyExpr.and(ExplorerResourceWritableContext, FileCopiedContext)
563
},
564
when: ExplorerFolderContext
565
});
566
567
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, ({
568
group: '5b_importexport',
569
order: 10,
570
command: {
571
id: DOWNLOAD_COMMAND_ID,
572
title: DOWNLOAD_LABEL
573
},
574
when: ContextKeyExpr.or(
575
// native: for any remote resource
576
ContextKeyExpr.and(IsWebContext.toNegated(), ResourceContextKey.Scheme.notEqualsTo(Schemas.file)),
577
// web: for any files
578
ContextKeyExpr.and(IsWebContext, ExplorerFolderContext.toNegated(), ExplorerRootContext.toNegated()),
579
// web: for any folders if file system API support is provided
580
ContextKeyExpr.and(IsWebContext, HasWebFileSystemAccess)
581
)
582
}));
583
584
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, ({
585
group: '5b_importexport',
586
order: 20,
587
command: {
588
id: UPLOAD_COMMAND_ID,
589
title: UPLOAD_LABEL,
590
},
591
when: ContextKeyExpr.and(
592
// only in web
593
IsWebContext,
594
// only on folders
595
ExplorerFolderContext,
596
// only on writable folders
597
ExplorerResourceWritableContext
598
)
599
}));
600
601
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
602
group: '6_copypath',
603
order: 10,
604
command: copyPathCommand,
605
when: ResourceContextKey.IsFileSystemResource
606
});
607
608
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
609
group: '6_copypath',
610
order: 20,
611
command: copyRelativePathCommand,
612
when: ResourceContextKey.IsFileSystemResource
613
});
614
615
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
616
group: '2_workspace',
617
order: 10,
618
command: {
619
id: ADD_ROOT_FOLDER_COMMAND_ID,
620
title: ADD_ROOT_FOLDER_LABEL,
621
},
622
when: ContextKeyExpr.and(ExplorerRootContext, ContextKeyExpr.or(EnterMultiRootWorkspaceSupportContext, WorkbenchStateContext.isEqualTo('workspace')))
623
});
624
625
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
626
group: '2_workspace',
627
order: 30,
628
command: {
629
id: REMOVE_ROOT_FOLDER_COMMAND_ID,
630
title: REMOVE_ROOT_FOLDER_LABEL,
631
},
632
when: ContextKeyExpr.and(ExplorerRootContext, ExplorerFolderContext, ContextKeyExpr.and(WorkspaceFolderCountContext.notEqualsTo('0'), ContextKeyExpr.or(EnterMultiRootWorkspaceSupportContext, WorkbenchStateContext.isEqualTo('workspace'))))
633
});
634
635
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
636
group: '7_modification',
637
order: 10,
638
command: {
639
id: RENAME_ID,
640
title: TRIGGER_RENAME_LABEL,
641
precondition: ExplorerResourceWritableContext,
642
},
643
when: ExplorerRootContext.toNegated()
644
});
645
646
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
647
group: '7_modification',
648
order: 20,
649
command: {
650
id: MOVE_FILE_TO_TRASH_ID,
651
title: MOVE_FILE_TO_TRASH_LABEL
652
},
653
alt: {
654
id: DELETE_FILE_ID,
655
title: nls.localize('deleteFile', "Delete Permanently")
656
},
657
when: ContextKeyExpr.and(ExplorerRootContext.toNegated(), ExplorerResourceMoveableToTrash)
658
});
659
660
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
661
group: '7_modification',
662
order: 20,
663
command: {
664
id: DELETE_FILE_ID,
665
title: nls.localize('deleteFile', "Delete Permanently")
666
},
667
when: ContextKeyExpr.and(ExplorerRootContext.toNegated(), ExplorerResourceMoveableToTrash.toNegated())
668
});
669
670
// Empty Editor Group / Editor Tabs Container Context Menu
671
for (const menuId of [MenuId.EmptyEditorGroupContext, MenuId.EditorTabsBarContext]) {
672
MenuRegistry.appendMenuItem(menuId, { command: { id: NEW_UNTITLED_FILE_COMMAND_ID, title: nls.localize('newFile', "New Text File") }, group: '1_file', order: 10 });
673
MenuRegistry.appendMenuItem(menuId, { command: { id: 'workbench.action.quickOpen', title: nls.localize('openFile', "Open File...") }, group: '1_file', order: 20 });
674
}
675
676
// File menu
677
678
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
679
group: '1_new',
680
command: {
681
id: NEW_UNTITLED_FILE_COMMAND_ID,
682
title: nls.localize({ key: 'miNewFile', comment: ['&& denotes a mnemonic'] }, "&&New Text File")
683
},
684
order: 1
685
});
686
687
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
688
group: '4_save',
689
command: {
690
id: SAVE_FILE_COMMAND_ID,
691
title: nls.localize({ key: 'miSave', comment: ['&& denotes a mnemonic'] }, "&&Save"),
692
precondition: ContextKeyExpr.or(ActiveEditorContext, ContextKeyExpr.and(FoldersViewVisibleContext, SidebarFocusContext))
693
},
694
order: 1
695
});
696
697
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
698
group: '4_save',
699
command: {
700
id: SAVE_FILE_AS_COMMAND_ID,
701
title: nls.localize({ key: 'miSaveAs', comment: ['&& denotes a mnemonic'] }, "Save &&As..."),
702
precondition: ContextKeyExpr.or(ActiveEditorContext, ContextKeyExpr.and(FoldersViewVisibleContext, SidebarFocusContext))
703
},
704
order: 2
705
});
706
707
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
708
group: '4_save',
709
command: {
710
id: SAVE_ALL_COMMAND_ID,
711
title: nls.localize({ key: 'miSaveAll', comment: ['&& denotes a mnemonic'] }, "Save A&&ll"),
712
precondition: DirtyWorkingCopiesContext
713
},
714
order: 3
715
});
716
717
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
718
group: '5_autosave',
719
command: {
720
id: ToggleAutoSaveAction.ID,
721
title: nls.localize({ key: 'miAutoSave', comment: ['&& denotes a mnemonic'] }, "A&&uto Save"),
722
toggled: ContextKeyExpr.notEquals('config.files.autoSave', 'off')
723
},
724
order: 1
725
});
726
727
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
728
group: '6_close',
729
command: {
730
id: REVERT_FILE_COMMAND_ID,
731
title: nls.localize({ key: 'miRevert', comment: ['&& denotes a mnemonic'] }, "Re&&vert File"),
732
precondition: ContextKeyExpr.or(
733
// Active editor can revert
734
ContextKeyExpr.and(ActiveEditorCanRevertContext),
735
// Explorer focused but not on untitled
736
ContextKeyExpr.and(ResourceContextKey.Scheme.notEqualsTo(Schemas.untitled), FoldersViewVisibleContext, SidebarFocusContext)
737
),
738
},
739
order: 1
740
});
741
742
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
743
group: '6_close',
744
command: {
745
id: CLOSE_EDITOR_COMMAND_ID,
746
title: nls.localize({ key: 'miCloseEditor', comment: ['&& denotes a mnemonic'] }, "&&Close Editor"),
747
precondition: ContextKeyExpr.or(ActiveEditorContext, ContextKeyExpr.and(FoldersViewVisibleContext, SidebarFocusContext))
748
},
749
order: 2
750
});
751
752
// Go to menu
753
754
MenuRegistry.appendMenuItem(MenuId.MenubarGoMenu, {
755
group: '3_global_nav',
756
command: {
757
id: 'workbench.action.quickOpen',
758
title: nls.localize({ key: 'miGotoFile', comment: ['&& denotes a mnemonic'] }, "Go to &&File...")
759
},
760
order: 1
761
});
762
763
764
// Chat used attachment anchor context menu
765
766
MenuRegistry.appendMenuItem(MenuId.ChatAttachmentsContext, {
767
group: 'navigation',
768
order: 10,
769
command: openToSideCommand,
770
when: ContextKeyExpr.and(ResourceContextKey.IsFileSystemResource, ExplorerFolderContext.toNegated())
771
});
772
773
MenuRegistry.appendMenuItem(MenuId.ChatAttachmentsContext, {
774
group: 'navigation',
775
order: 20,
776
command: revealInSideBarCommand,
777
when: ResourceContextKey.IsFileSystemResource
778
});
779
780
MenuRegistry.appendMenuItem(MenuId.ChatAttachmentsContext, {
781
group: '1_cutcopypaste',
782
order: 10,
783
command: copyPathCommand,
784
when: ResourceContextKey.IsFileSystemResource
785
});
786
787
MenuRegistry.appendMenuItem(MenuId.ChatAttachmentsContext, {
788
group: '1_cutcopypaste',
789
order: 20,
790
command: copyRelativePathCommand,
791
when: ResourceContextKey.IsFileSystemResource
792
});
793
794
// Chat resource anchor attachments/anchors context menu
795
796
for (const menuId of [MenuId.ChatInlineResourceAnchorContext, MenuId.ChatInputResourceAttachmentContext]) {
797
MenuRegistry.appendMenuItem(menuId, {
798
group: 'navigation',
799
order: 10,
800
command: openToSideCommand,
801
when: ContextKeyExpr.and(ResourceContextKey.HasResource, ExplorerFolderContext.toNegated())
802
});
803
804
MenuRegistry.appendMenuItem(menuId, {
805
group: 'navigation',
806
order: 20,
807
command: revealInSideBarCommand,
808
when: ResourceContextKey.IsFileSystemResource
809
});
810
811
MenuRegistry.appendMenuItem(menuId, {
812
group: '1_cutcopypaste',
813
order: 10,
814
command: copyPathCommand,
815
when: ResourceContextKey.IsFileSystemResource
816
});
817
818
MenuRegistry.appendMenuItem(menuId, {
819
group: '1_cutcopypaste',
820
order: 20,
821
command: copyRelativePathCommand,
822
when: ResourceContextKey.IsFileSystemResource
823
});
824
}
825
826