Path: blob/main/src/vs/workbench/contrib/preferences/browser/preferencesEditorRegistry.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 { Disposable, IDisposable } from '../../../../base/common/lifecycle.js';6import * as DOM from '../../../../base/browser/dom.js';7import { Event, Emitter } from '../../../../base/common/event.js';8import { ThemeIcon } from '../../../../base/common/themables.js';9import { URI } from '../../../../base/common/uri.js';10import { SyncDescriptor } from '../../../../platform/instantiation/common/descriptors.js';11import { Registry } from '../../../../platform/registry/common/platform.js';1213export namespace Extensions {14export const PreferencesEditorPane = 'workbench.registry.preferences.editorPanes';15}1617export interface IPreferencesEditorPane extends IDisposable {1819getDomNode(): HTMLElement;2021layout(dimension: DOM.Dimension): void;2223search(text: string): void;2425}2627export interface IPreferencesEditorPaneDescriptor {2829/**30* The id of the view container31*/32readonly id: string;3334/**35* The title of the view container36*/37readonly title: string;3839/**40* Icon representation of the View container41*/42readonly icon?: ThemeIcon | URI;4344/**45* Order of the view container.46*/47readonly order: number;4849/**50* IViewPaneContainer Ctor to instantiate51*/52readonly ctorDescriptor: SyncDescriptor<IPreferencesEditorPane>;5354/**55* Storage id to use to store the view container state.56* If not provided, it will be derived.57*/58readonly storageId?: string;59}6061export interface IPreferencesEditorPaneRegistry {62readonly onDidRegisterPreferencesEditorPanes: Event<IPreferencesEditorPaneDescriptor[]>;63readonly onDidDeregisterPreferencesEditorPanes: Event<IPreferencesEditorPaneDescriptor[]>;6465registerPreferencesEditorPane(descriptor: IPreferencesEditorPaneDescriptor): IDisposable;6667getPreferencesEditorPanes(): readonly IPreferencesEditorPaneDescriptor[];68}6970class PreferencesEditorPaneRegistryImpl extends Disposable implements IPreferencesEditorPaneRegistry {7172private readonly descriptors = new Map<string, IPreferencesEditorPaneDescriptor>();7374private readonly _onDidRegisterPreferencesEditorPanes = this._register(new Emitter<IPreferencesEditorPaneDescriptor[]>());75readonly onDidRegisterPreferencesEditorPanes = this._onDidRegisterPreferencesEditorPanes.event;7677private readonly _onDidDeregisterPreferencesEditorPanes = this._register(new Emitter<IPreferencesEditorPaneDescriptor[]>());78readonly onDidDeregisterPreferencesEditorPanes = this._onDidDeregisterPreferencesEditorPanes.event;7980constructor() {81super();82}8384registerPreferencesEditorPane(descriptor: IPreferencesEditorPaneDescriptor): IDisposable {85if (this.descriptors.has(descriptor.id)) {86throw new Error(`PreferencesEditorPane with id ${descriptor.id} already registered`);87}88this.descriptors.set(descriptor.id, descriptor);89this._onDidRegisterPreferencesEditorPanes.fire([descriptor]);90return {91dispose: () => {92if (this.descriptors.delete(descriptor.id)) {93this._onDidDeregisterPreferencesEditorPanes.fire([descriptor]);94}95}96};97}9899getPreferencesEditorPanes(): readonly IPreferencesEditorPaneDescriptor[] {100return [...this.descriptors.values()].sort((a, b) => a.order - b.order);101}102103}104105Registry.add(Extensions.PreferencesEditorPane, new PreferencesEditorPaneRegistryImpl());106107108