Path: blob/main/src/vs/workbench/contrib/files/browser/explorerFileContrib.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Emitter } from '../../../../base/common/event.js';6import { Disposable, DisposableStore, IDisposable } from '../../../../base/common/lifecycle.js';7import { URI } from '../../../../base/common/uri.js';8import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';9import { Registry } from '../../../../platform/registry/common/platform.js';1011export const enum ExplorerExtensions {12FileContributionRegistry = 'workbench.registry.explorer.fileContributions'13}1415/**16* Contributes to the rendering of a file in the explorer.17*/18export interface IExplorerFileContribution extends IDisposable {19/**20* Called to render a file in the container. The implementation should21* remove any rendered elements if `resource` is undefined.22*/23setResource(resource: URI | undefined): void;24}2526export interface IExplorerFileContributionDescriptor {27create(insta: IInstantiationService, container: HTMLElement): IExplorerFileContribution;28}2930export interface IExplorerFileContributionRegistry {31/**32* Registers a new contribution. A new instance of the contribution will be33* instantiated for each template in the explorer.34*/35register(descriptor: IExplorerFileContributionDescriptor): void;36}3738class ExplorerFileContributionRegistry extends Disposable implements IExplorerFileContributionRegistry {39private readonly _onDidRegisterDescriptor = this._register(new Emitter<IExplorerFileContributionDescriptor>());40public readonly onDidRegisterDescriptor = this._onDidRegisterDescriptor.event;4142private readonly descriptors: IExplorerFileContributionDescriptor[] = [];4344/** @inheritdoc */45public register(descriptor: IExplorerFileContributionDescriptor): void {46this.descriptors.push(descriptor);47this._onDidRegisterDescriptor.fire(descriptor);48}4950/**51* Creates a new instance of all registered contributions.52*/53public create(insta: IInstantiationService, container: HTMLElement, store: DisposableStore): IExplorerFileContribution[] {54return this.descriptors.map(d => {55const i = d.create(insta, container);56store.add(i);57return i;58});59}60}6162export const explorerFileContribRegistry = new ExplorerFileContributionRegistry();63Registry.add(ExplorerExtensions.FileContributionRegistry, explorerFileContribRegistry);646566