84
return undefined;
85
}
87
>
88
>
89
>
export interface IconFontSource {
90
>
readonly location: URI;
91
>
readonly format: string;
92
>
}
93
>
94
>
export interface IIconRegistry {
95
>
96
>
readonly onDidChange: Event<void>;
97
>
98
>
/**
99
>
* Register a icon to the registry.
100
>
* @param id The icon id
101
>
* @param defaults The default values
102
>
* @param description The description
103
>
*/
104
>
registerIcon(id: IconIdentifier, defaults: IconDefaults, description?: string): ThemeIcon;
105
>
106
>
/**
107
>
* Deregister a icon from the registry.
108
>
*/
109
>
deregisterIcon(id: IconIdentifier): void;
110
>
111
>
/**
112
>
* Get all icon contributions
113
>
*/
114
>
getIcons(): IconContribution[];
115
>
116
>
/**
117
>
* Get the icon for the given id
118
>
*/
119
>
getIcon(id: IconIdentifier): IconContribution | undefined;
120
>
121
>
/**
122
>
* JSON schema for an object to assign icon values to one of the icon contributions.
123
>
*/
124
>
getIconSchema(): IJSONSchema;
125
>
126
>
/**
127
>
* JSON schema to for a reference to a icon contribution.
128
>
*/
129
>
getIconReferenceSchema(): IJSONSchema;
130
>
131
>
/**
132
>
* Register a icon font to the registry.
133
>
* @param id The icon font id
134
>
* @param definition The icon font definition
135
>
*/
136
>
registerIconFont(id: string, definition: IconFontDefinition): IconFontDefinition;
137
>
138
>
/**
139
>
* Deregister an icon font to the registry.
140
>
*/
141
>
deregisterIconFont(id: string): void;
142
>
143
>
/**
144
>
* Get the icon font for the given id
145
>
*/
146
>
getIconFont(id: string): IconFontDefinition | undefined;
147
>
}
148
>
149
>
// regexes for validation of font properties
150
>
151
>
export const fontIdRegex = /^([\w_-]+)$/;
152
>
export const fontStyleRegex = /^(normal|italic|(oblique[ \w\s-]+))$/;
153
>
export const fontWeightRegex = /^(normal|bold|lighter|bolder|(\d{0-1000}))$/;
154
>
export const fontSizeRegex = /^([\w_.%+-]+)$/;
155
>
export const fontFormatRegex = /^woff|woff2|truetype|opentype|embedded-opentype|svg$/;
156
>
export const fontColorRegex = /^#[0-9a-fA-F]{0,6}$/;
157
>
158
>
export const fontIdErrorMessage = localize('schema.fontId.formatError', 'The font ID must only contain letters, numbers, underscores and dashes.');
159
>
160
>
class IconRegistry extends Disposable implements IIconRegistry {
161
>
162
>
private readonly _onDidChange = this._register(new Emitter<void>());
163
>
readonly onDidChange: Event<void> = this._onDidChange.event;
164
>
165
>
private iconsById: { [key: string]: IconContribution };
166
>
private iconSchema: IJSONSchema & { properties: IJSONSchemaMap } = {
167
>
definitions: {
168
>
icons: {
169
>
type: 'object',
170
>
properties: {
171
>
fontId: { type: 'string', description: localize('iconDefinition.fontId', 'The id of the font to use. If not set, the font that is defined first is used.'), pattern: fontIdRegex.source, patternErrorMessage: fontIdErrorMessage },
172
>
fontCharacter: { type: 'string', description: localize('iconDefinition.fontCharacter', 'The font character associated with the icon definition.') }
173
>
},
174
>
additionalProperties: false,
175
>
defaultSnippets: [{ body: { fontCharacter: '\\\\e030' } }]
176
>
}
177
>
},
178
>
type: 'object',
179
>
properties: {}
180
>
};
181
>
private iconReferenceSchema: IJSONSchema & { enum: string[]; enumDescriptions: string[] } = { type: 'string', pattern: `^${ThemeIcon.iconNameExpression}$`, enum: [], enumDescriptions: [] };
182
>
183
>
private iconFontsById: { [key: string]: IconFontDefinition };
184
>
185
>
constructor() {
186
>
super();
187
>
this.iconsById = {};
188
>
this.iconFontsById = {};
189
>
}
190
>
191
>
public registerIcon(id: string, defaults: IconDefaults, description?: string, deprecationMessage?: string): ThemeIcon {
192
>
const existing = this.iconsById[id];
193
>
if (existing) {
194
if (description && !existing.description) {
195
existing.description = description;