Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/preferences/browser/preferencesEditorRegistry.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 { Disposable, IDisposable } from '../../../../base/common/lifecycle.js';
7
import * as DOM from '../../../../base/browser/dom.js';
8
import { Event, Emitter } from '../../../../base/common/event.js';
9
import { ThemeIcon } from '../../../../base/common/themables.js';
10
import { URI } from '../../../../base/common/uri.js';
11
import { SyncDescriptor } from '../../../../platform/instantiation/common/descriptors.js';
12
import { Registry } from '../../../../platform/registry/common/platform.js';
13
14
export namespace Extensions {
15
export const PreferencesEditorPane = 'workbench.registry.preferences.editorPanes';
16
}
17
18
export interface IPreferencesEditorPane extends IDisposable {
19
20
getDomNode(): HTMLElement;
21
22
layout(dimension: DOM.Dimension): void;
23
24
search(text: string): void;
25
26
}
27
28
export interface IPreferencesEditorPaneDescriptor {
29
30
/**
31
* The id of the view container
32
*/
33
readonly id: string;
34
35
/**
36
* The title of the view container
37
*/
38
readonly title: string;
39
40
/**
41
* Icon representation of the View container
42
*/
43
readonly icon?: ThemeIcon | URI;
44
45
/**
46
* Order of the view container.
47
*/
48
readonly order: number;
49
50
/**
51
* IViewPaneContainer Ctor to instantiate
52
*/
53
readonly ctorDescriptor: SyncDescriptor<IPreferencesEditorPane>;
54
55
/**
56
* Storage id to use to store the view container state.
57
* If not provided, it will be derived.
58
*/
59
readonly storageId?: string;
60
}
61
62
export interface IPreferencesEditorPaneRegistry {
63
readonly onDidRegisterPreferencesEditorPanes: Event<IPreferencesEditorPaneDescriptor[]>;
64
readonly onDidDeregisterPreferencesEditorPanes: Event<IPreferencesEditorPaneDescriptor[]>;
65
66
registerPreferencesEditorPane(descriptor: IPreferencesEditorPaneDescriptor): IDisposable;
67
68
getPreferencesEditorPanes(): readonly IPreferencesEditorPaneDescriptor[];
69
}
70
71
class PreferencesEditorPaneRegistryImpl extends Disposable implements IPreferencesEditorPaneRegistry {
72
73
private readonly descriptors = new Map<string, IPreferencesEditorPaneDescriptor>();
74
75
private readonly _onDidRegisterPreferencesEditorPanes = this._register(new Emitter<IPreferencesEditorPaneDescriptor[]>());
76
readonly onDidRegisterPreferencesEditorPanes = this._onDidRegisterPreferencesEditorPanes.event;
77
78
private readonly _onDidDeregisterPreferencesEditorPanes = this._register(new Emitter<IPreferencesEditorPaneDescriptor[]>());
79
readonly onDidDeregisterPreferencesEditorPanes = this._onDidDeregisterPreferencesEditorPanes.event;
80
81
constructor() {
82
super();
83
}
84
85
registerPreferencesEditorPane(descriptor: IPreferencesEditorPaneDescriptor): IDisposable {
86
if (this.descriptors.has(descriptor.id)) {
87
throw new Error(`PreferencesEditorPane with id ${descriptor.id} already registered`);
88
}
89
this.descriptors.set(descriptor.id, descriptor);
90
this._onDidRegisterPreferencesEditorPanes.fire([descriptor]);
91
return {
92
dispose: () => {
93
if (this.descriptors.delete(descriptor.id)) {
94
this._onDidDeregisterPreferencesEditorPanes.fire([descriptor]);
95
}
96
}
97
};
98
}
99
100
getPreferencesEditorPanes(): readonly IPreferencesEditorPaneDescriptor[] {
101
return [...this.descriptors.values()].sort((a, b) => a.order - b.order);
102
}
103
104
}
105
106
Registry.add(Extensions.PreferencesEditorPane, new PreferencesEditorPaneRegistryImpl());
107
108