Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/files/electron-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 { URI } from '../../../../base/common/uri.js';
8
import { IWorkspaceContextService } from '../../../../platform/workspace/common/workspace.js';
9
import { isWindows, isMacintosh } from '../../../../base/common/platform.js';
10
import { Schemas } from '../../../../base/common/network.js';
11
import { INativeHostService } from '../../../../platform/native/common/native.js';
12
import { KeybindingsRegistry, KeybindingWeight } from '../../../../platform/keybinding/common/keybindingsRegistry.js';
13
import { EditorContextKeys } from '../../../../editor/common/editorContextKeys.js';
14
import { KeyMod, KeyCode, KeyChord } from '../../../../base/common/keyCodes.js';
15
import { ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js';
16
import { getMultiSelectedResources, IExplorerService } from '../browser/files.js';
17
import { IEditorService } from '../../../services/editor/common/editorService.js';
18
import { revealResourcesInOS } from './fileCommands.js';
19
import { MenuRegistry, MenuId } from '../../../../platform/actions/common/actions.js';
20
import { ResourceContextKey } from '../../../common/contextkeys.js';
21
import { appendToCommandPalette, appendEditorTitleContextMenuItem } from '../browser/fileActions.contribution.js';
22
import { SideBySideEditor, EditorResourceAccessor } from '../../../common/editor.js';
23
import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
24
import { IListService } from '../../../../platform/list/browser/listService.js';
25
import { IEditorGroupsService } from '../../../services/editor/common/editorGroupsService.js';
26
27
const REVEAL_IN_OS_COMMAND_ID = 'revealFileInOS';
28
const REVEAL_IN_OS_LABEL = isWindows ? nls.localize2('revealInWindows', "Reveal in File Explorer") : isMacintosh ? nls.localize2('revealInMac', "Reveal in Finder") : nls.localize2('openContainer', "Open Containing Folder");
29
const REVEAL_IN_OS_WHEN_CONTEXT = ContextKeyExpr.or(ResourceContextKey.Scheme.isEqualTo(Schemas.file), ResourceContextKey.Scheme.isEqualTo(Schemas.vscodeUserData));
30
31
KeybindingsRegistry.registerCommandAndKeybindingRule({
32
id: REVEAL_IN_OS_COMMAND_ID,
33
weight: KeybindingWeight.WorkbenchContrib,
34
when: EditorContextKeys.focus.toNegated(),
35
primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KeyR,
36
win: {
37
primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KeyR
38
},
39
handler: (accessor: ServicesAccessor, resource: URI | object) => {
40
const resources = getMultiSelectedResources(resource, accessor.get(IListService), accessor.get(IEditorService), accessor.get(IEditorGroupsService), accessor.get(IExplorerService));
41
revealResourcesInOS(resources, accessor.get(INativeHostService), accessor.get(IWorkspaceContextService));
42
}
43
});
44
45
const REVEAL_ACTIVE_FILE_IN_OS_COMMAND_ID = 'workbench.action.files.revealActiveFileInWindows';
46
47
KeybindingsRegistry.registerCommandAndKeybindingRule({
48
weight: KeybindingWeight.WorkbenchContrib,
49
when: undefined,
50
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyCode.KeyR),
51
id: REVEAL_ACTIVE_FILE_IN_OS_COMMAND_ID,
52
handler: (accessor: ServicesAccessor) => {
53
const editorService = accessor.get(IEditorService);
54
const activeInput = editorService.activeEditor;
55
const resource = EditorResourceAccessor.getOriginalUri(activeInput, { filterByScheme: Schemas.file, supportSideBySide: SideBySideEditor.PRIMARY });
56
const resources = resource ? [resource] : [];
57
revealResourcesInOS(resources, accessor.get(INativeHostService), accessor.get(IWorkspaceContextService));
58
}
59
});
60
61
appendEditorTitleContextMenuItem(REVEAL_IN_OS_COMMAND_ID, REVEAL_IN_OS_LABEL.value, REVEAL_IN_OS_WHEN_CONTEXT, '2_files', false, 0);
62
63
// Menu registration - open editors
64
65
const revealInOsCommand = {
66
id: REVEAL_IN_OS_COMMAND_ID,
67
title: REVEAL_IN_OS_LABEL.value
68
};
69
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
70
group: 'navigation',
71
order: 20,
72
command: revealInOsCommand,
73
when: REVEAL_IN_OS_WHEN_CONTEXT
74
});
75
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContextShare, {
76
title: nls.localize('miShare', "Share"),
77
submenu: MenuId.MenubarShare,
78
group: 'share',
79
order: 3,
80
});
81
82
// Menu registration - explorer
83
84
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
85
group: 'navigation',
86
order: 20,
87
command: revealInOsCommand,
88
when: REVEAL_IN_OS_WHEN_CONTEXT
89
});
90
91
// Command Palette
92
93
const category = nls.localize2('filesCategory', "File");
94
appendToCommandPalette({
95
id: REVEAL_IN_OS_COMMAND_ID,
96
title: REVEAL_IN_OS_LABEL,
97
category: category
98
}, REVEAL_IN_OS_WHEN_CONTEXT);
99
100
// Menu registration - chat attachments context
101
102
MenuRegistry.appendMenuItem(MenuId.ChatAttachmentsContext, {
103
group: 'navigation',
104
order: 20,
105
command: revealInOsCommand,
106
when: REVEAL_IN_OS_WHEN_CONTEXT
107
});
108
109
// Menu registration - chat inline anchor
110
111
MenuRegistry.appendMenuItem(MenuId.ChatInlineResourceAnchorContext, {
112
group: 'navigation',
113
order: 20,
114
command: revealInOsCommand,
115
when: REVEAL_IN_OS_WHEN_CONTEXT
116
});
117
118