Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/files/browser/explorerFileContrib.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 { Emitter } from '../../../../base/common/event.js';
7
import { Disposable, DisposableStore, IDisposable } from '../../../../base/common/lifecycle.js';
8
import { URI } from '../../../../base/common/uri.js';
9
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
10
import { Registry } from '../../../../platform/registry/common/platform.js';
11
12
export const enum ExplorerExtensions {
13
FileContributionRegistry = 'workbench.registry.explorer.fileContributions'
14
}
15
16
/**
17
* Contributes to the rendering of a file in the explorer.
18
*/
19
export interface IExplorerFileContribution extends IDisposable {
20
/**
21
* Called to render a file in the container. The implementation should
22
* remove any rendered elements if `resource` is undefined.
23
*/
24
setResource(resource: URI | undefined): void;
25
}
26
27
export interface IExplorerFileContributionDescriptor {
28
create(insta: IInstantiationService, container: HTMLElement): IExplorerFileContribution;
29
}
30
31
export interface IExplorerFileContributionRegistry {
32
/**
33
* Registers a new contribution. A new instance of the contribution will be
34
* instantiated for each template in the explorer.
35
*/
36
register(descriptor: IExplorerFileContributionDescriptor): void;
37
}
38
39
class ExplorerFileContributionRegistry extends Disposable implements IExplorerFileContributionRegistry {
40
private readonly _onDidRegisterDescriptor = this._register(new Emitter<IExplorerFileContributionDescriptor>());
41
public readonly onDidRegisterDescriptor = this._onDidRegisterDescriptor.event;
42
43
private readonly descriptors: IExplorerFileContributionDescriptor[] = [];
44
45
/** @inheritdoc */
46
public register(descriptor: IExplorerFileContributionDescriptor): void {
47
this.descriptors.push(descriptor);
48
this._onDidRegisterDescriptor.fire(descriptor);
49
}
50
51
/**
52
* Creates a new instance of all registered contributions.
53
*/
54
public create(insta: IInstantiationService, container: HTMLElement, store: DisposableStore): IExplorerFileContribution[] {
55
return this.descriptors.map(d => {
56
const i = d.create(insta, container);
57
store.add(i);
58
return i;
59
});
60
}
61
}
62
63
export const explorerFileContribRegistry = new ExplorerFileContributionRegistry();
64
Registry.add(ExplorerExtensions.FileContributionRegistry, explorerFileContribRegistry);
65
66