Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/sessions/contrib/files/browser/files.contribution.ts
13401 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 { Codicon } from '../../../../base/common/codicons.js';
7
import { localize, localize2 } from '../../../../nls.js';
8
import { Action2, MenuId, registerAction2 } from '../../../../platform/actions/common/actions.js';
9
import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
10
import { SyncDescriptor } from '../../../../platform/instantiation/common/descriptors.js';
11
import { ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js';
12
import { Registry } from '../../../../platform/registry/common/platform.js';
13
import { registerIcon } from '../../../../platform/theme/common/iconRegistry.js';
14
import { IWorkbenchContribution, registerWorkbenchContribution2, WorkbenchPhase } from '../../../../workbench/common/contributions.js';
15
import { IViewContainersRegistry, IViewsRegistry, ViewContainerLocation, Extensions as ViewContainerExtensions, WindowEnablement } from '../../../../workbench/common/views.js';
16
import { ExplorerView } from '../../../../workbench/contrib/files/browser/views/explorerView.js';
17
import { ViewPaneContainer } from '../../../../workbench/browser/parts/views/viewPaneContainer.js';
18
import { IViewsService } from '../../../../workbench/services/views/common/viewsService.js';
19
import { WorkspaceFolderCountContext } from '../../../../workbench/common/contextkeys.js';
20
import { SESSIONS_FILES_EMPTY_VIEW_ID, SESSIONS_FILES_VIEW_ID, SessionsExplorerEmptyView, SessionsExplorerView } from './filesView.js';
21
import { KeyCode, KeyMod } from '../../../../base/common/keyCodes.js';
22
import { IsPhoneLayoutContext } from '../../../common/contextkeys.js';
23
24
export const SESSIONS_FILES_CONTAINER_ID = 'workbench.sessions.auxiliaryBar.filesContainer';
25
26
const filesViewIcon = registerIcon('sessions-files-view-icon', Codicon.files, localize2('sessionsFilesViewIcon', 'View icon of the files view in the sessions window.').value);
27
28
const viewContainerRegistry = Registry.as<IViewContainersRegistry>(ViewContainerExtensions.ViewContainersRegistry);
29
30
// Files view container
31
const filesViewContainer = viewContainerRegistry.registerViewContainer({
32
id: SESSIONS_FILES_CONTAINER_ID,
33
title: localize2('files', "Files"),
34
icon: filesViewIcon,
35
order: 11,
36
ctorDescriptor: new SyncDescriptor(ViewPaneContainer, [SESSIONS_FILES_CONTAINER_ID, { mergeViewWithContainerWhenSingleView: true }]),
37
storageId: SESSIONS_FILES_CONTAINER_ID,
38
hideIfEmpty: false,
39
openCommandActionDescriptor: {
40
id: SESSIONS_FILES_CONTAINER_ID,
41
title: localize2('explore', "Explorer"),
42
mnemonicTitle: localize({ key: 'miFiles', comment: ['&& denotes a mnemonic'] }, "Fil&&es"),
43
keybindings: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KeyE },
44
order: 0
45
},
46
windowEnablement: WindowEnablement.Sessions,
47
}, ViewContainerLocation.AuxiliaryBar, { isDefault: true });
48
49
class RegisterFilesViewContribution implements IWorkbenchContribution {
50
51
static readonly ID = 'sessions.registerFilesView';
52
53
constructor() {
54
const viewsRegistry = Registry.as<IViewsRegistry>(ViewContainerExtensions.ViewsRegistry);
55
56
// Re-register the explorer view inside the new Files container
57
viewsRegistry.registerViews([{
58
id: SESSIONS_FILES_VIEW_ID,
59
name: localize2('files', "Files"),
60
containerIcon: filesViewIcon,
61
ctorDescriptor: new SyncDescriptor(SessionsExplorerView),
62
canToggleVisibility: false,
63
canMoveView: false,
64
when: ContextKeyExpr.and(WorkspaceFolderCountContext.notEqualsTo('0'), IsPhoneLayoutContext.negate()),
65
windowEnablement: WindowEnablement.Sessions,
66
}], filesViewContainer);
67
68
// Register an empty view to show when there are no workspace folders
69
viewsRegistry.registerViews([{
70
id: SESSIONS_FILES_EMPTY_VIEW_ID,
71
name: localize2('files', "Files"),
72
containerIcon: filesViewIcon,
73
ctorDescriptor: new SyncDescriptor(SessionsExplorerEmptyView),
74
canToggleVisibility: false,
75
canMoveView: false,
76
when: ContextKeyExpr.and(WorkspaceFolderCountContext.isEqualTo('0'), IsPhoneLayoutContext.negate()),
77
windowEnablement: WindowEnablement.Sessions,
78
}], filesViewContainer);
79
}
80
}
81
82
registerWorkbenchContribution2(RegisterFilesViewContribution.ID, RegisterFilesViewContribution, WorkbenchPhase.BlockStartup);
83
84
registerAction2(class extends Action2 {
85
constructor() {
86
super({
87
id: 'sessions.files.action.collapseExplorerFolders',
88
title: localize2('collapseExplorerFolders', "Collapse Folders in Explorer"),
89
icon: Codicon.collapseAll,
90
menu: {
91
id: MenuId.ViewTitle,
92
group: 'navigation',
93
when: ContextKeyExpr.equals('view', SESSIONS_FILES_VIEW_ID),
94
},
95
});
96
}
97
98
run(accessor: ServicesAccessor) {
99
const viewsService = accessor.get(IViewsService);
100
const view = viewsService.getViewWithId(SESSIONS_FILES_VIEW_ID);
101
if (view !== null) {
102
(view as ExplorerView).collapseAll();
103
}
104
}
105
});
106
107