提交 6ecf3499 编写于 作者: M Martin Aeschlimann

Make color/icon theme contribution points dynamic

上级 cf67606c
......@@ -881,8 +881,11 @@
"./vs/workbench/services/themes/common/colorThemeSchema.ts",
"./vs/workbench/services/themes/common/fileIconThemeSchema.ts",
"./vs/workbench/services/themes/common/workbenchThemeService.ts",
"./vs/workbench/services/themes/electron-browser/colorThemeData.ts",
"./vs/workbench/services/themes/electron-browser/colorThemeStore.ts",
"./vs/workbench/services/themes/electron-browser/fileIconThemeData.ts",
"./vs/workbench/services/themes/electron-browser/fileIconThemeStore.ts",
"./vs/workbench/services/themes/electron-browser/workbenchThemeService.ts",
"./vs/workbench/services/themes/electron-browser/themeCompatibility.ts",
"./vs/workbench/services/timer/electron-browser/timerService.ts",
"./vs/workbench/services/title/common/titleService.ts",
......
......@@ -47,7 +47,7 @@ export interface IConfigurationRegistry {
* Signal that the schema of a configuration setting has changes. It is currently only supported to change enumeration values.
* Property or default value changes are not allowed.
*/
notifyConfigurationSchemaUpdated(configuration: IConfigurationNode): void;
notifyConfigurationSchemaUpdated(...configurations: IConfigurationNode[]): void;
/**
* Event that fires whenver a configuration has been
......@@ -251,8 +251,8 @@ class ConfigurationRegistry implements IConfigurationRegistry {
this._onDidUpdateConfiguration.fire(properties);
}
public notifyConfigurationSchemaUpdated(configuration: IConfigurationNode) {
contributionRegistry.notifySchemaChanged(editorConfigurationSchemaId);
public notifyConfigurationSchemaUpdated(...configurations: IConfigurationNode[]) {
this._onDidSchemaChange.fire();
}
public registerOverrideIdentifiers(overrideIdentifiers: string[]): void {
......
......@@ -26,7 +26,7 @@ export interface IJSONContributionRegistry {
/**
* Notifies all listeneres that the content of the given schema has changed.
* Notifies all listeners that the content of the given schema has changed.
* @param uri The id of the schema
*/
notifySchemaChanged(uri: string): void;
......
......@@ -180,7 +180,7 @@ export class ElectronWindow extends Themable {
const windowConfig = this.configurationService.getValue<IWindowSettings>('window');
if (windowConfig && windowConfig.autoDetectHighContrast) {
this.lifecycleService.when(LifecyclePhase.Ready).then(() => {
this.themeService.setColorTheme(VS_HC_THEME, null);
this.themeService.setColorTheme(VS_HC_THEME, undefined);
});
}
});
......
......@@ -129,7 +129,6 @@ export class PreferencesContribution implements IWorkbenchContribution {
const modelContent = JSON.stringify(schema);
const languageSelection = this.modeService.create('jsonc');
const model = this.modelService.createModel(modelContent, languageSelection, uri);
const disposables: IDisposable[] = [];
disposables.push(schemaRegistry.onDidChangeSchema(schemaUri => {
if (schemaUri === uri.toString()) {
......
......@@ -60,7 +60,7 @@ export class SelectColorThemeAction extends Action {
}
theme = currentTheme;
}
let target: ConfigurationTarget | null = null;
let target: ConfigurationTarget | undefined = undefined;
if (applyTheme) {
let confValue = this.configurationService.inspect(COLOR_THEME_SETTING);
target = typeof confValue.workspace !== 'undefined' ? ConfigurationTarget.WORKSPACE : ConfigurationTarget.USER;
......@@ -69,7 +69,7 @@ export class SelectColorThemeAction extends Action {
this.themeService.setColorTheme(theme.id, target).then(undefined,
err => {
onUnexpectedError(err);
this.themeService.setColorTheme(currentTheme.id, null);
this.themeService.setColorTheme(currentTheme.id, undefined);
}
);
};
......
......@@ -41,7 +41,7 @@ export interface IColorMap {
export interface IFileIconTheme extends IIconTheme {
readonly id: string;
readonly label: string;
readonly settingsId?: string;
readonly settingsId: string | null;
readonly description?: string;
readonly extensionData?: ExtensionData;
......@@ -53,13 +53,13 @@ export interface IFileIconTheme extends IIconTheme {
export interface IWorkbenchThemeService extends IThemeService {
_serviceBrand: any;
setColorTheme(themeId: string, settingsTarget: ConfigurationTarget | null): Promise<IColorTheme>;
setColorTheme(themeId: string | undefined, settingsTarget: ConfigurationTarget | undefined): Promise<IColorTheme | null>;
getColorTheme(): IColorTheme;
getColorThemes(): Promise<IColorTheme[]>;
onDidColorThemeChange: Event<IColorTheme>;
restoreColorTheme();
setFileIconTheme(iconThemeId: string, settingsTarget: ConfigurationTarget | undefined): Promise<IFileIconTheme>;
setFileIconTheme(iconThemeId: string | undefined, settingsTarget: ConfigurationTarget | undefined): Promise<IFileIconTheme>;
getFileIconTheme(): IFileIconTheme;
getFileIconThemes(): Promise<IFileIconTheme[]>;
onDidFileIconThemeChange: Event<IFileIconTheme>;
......
......@@ -57,8 +57,8 @@ export class ColorThemeData implements IColorTheme {
private colorMap: IColorMap = {};
private customColorMap: IColorMap = {};
public getColor(colorId: ColorIdentifier, useDefault?: boolean): Color {
let color = this.customColorMap[colorId];
public getColor(colorId: ColorIdentifier, useDefault?: boolean): Color | null {
let color: Color | null = this.customColorMap[colorId];
if (color) {
return color;
}
......@@ -69,7 +69,7 @@ export class ColorThemeData implements IColorTheme {
return color;
}
public getDefault(colorId: ColorIdentifier): Color {
public getDefault(colorId: ColorIdentifier): Color | null {
return colorRegistry.resolveDefaultColor(colorId, this);
}
......@@ -213,7 +213,7 @@ export class ColorThemeData implements IColorTheme {
let themeData = new ColorThemeData();
themeData.id = id;
themeData.label = '';
themeData.settingsId = null;
themeData.settingsId = '__' + id;
themeData.isLoaded = false;
themeData.themeTokenColors = [{ settings: {} }];
themeData.watch = false;
......@@ -231,7 +231,7 @@ export class ColorThemeData implements IColorTheme {
return themeData;
}
static fromStorageData(input: string): ColorThemeData {
static fromStorageData(input: string): ColorThemeData | undefined {
try {
let data = JSON.parse(input);
let theme = new ColorThemeData();
......@@ -251,7 +251,7 @@ export class ColorThemeData implements IColorTheme {
}
return theme;
} catch (e) {
return null;
return undefined;
}
}
......@@ -292,7 +292,7 @@ function _loadColorTheme(fileService: IFileService, themeLocation: URI, resultRu
}
let includeCompletes: Promise<any> = Promise.resolve(null);
if (contentValue.include) {
includeCompletes = _loadColorTheme(fileService, resources.joinPath(resources.dirname(themeLocation), contentValue.include), resultRules, resultColors);
includeCompletes = _loadColorTheme(fileService, resources.joinPath(resources.dirname(themeLocation)!, contentValue.include), resultRules, resultColors);
}
return includeCompletes.then(_ => {
if (Array.isArray(contentValue.settings)) {
......@@ -318,7 +318,7 @@ function _loadColorTheme(fileService: IFileService, themeLocation: URI, resultRu
resultRules.push(...tokenColors);
return null;
} else if (typeof tokenColors === 'string') {
return _loadSyntaxTokens(fileService, resources.joinPath(resources.dirname(themeLocation), tokenColors), resultRules, {});
return _loadSyntaxTokens(fileService, resources.joinPath(resources.dirname(themeLocation)!, tokenColors), resultRules, {});
} else {
return Promise.reject(new Error(nls.localize({ key: 'error.invalidformat.tokenColors', comment: ['{0} will be replaced by a path. Values in quotes should not be translated.'] }, "Problem parsing color theme file: {0}. Property 'tokenColors' should be either an array specifying colors or a path to a TextMate theme file", themeLocation.toString())));
}
......@@ -360,8 +360,8 @@ function _loadSyntaxTokens(fileService: IFileService, themeLocation: URI, result
}
function updateDefaultRuleSettings(defaultRule: ITokenColorizationRule, theme: ColorThemeData): ITokenColorizationRule {
const foreground = theme.getColor(editorForeground) || theme.getDefault(editorForeground);
const background = theme.getColor(editorBackground) || theme.getDefault(editorBackground);
const foreground = theme.getColor(editorForeground) || theme.getDefault(editorForeground)!;
const background = theme.getColor(editorBackground) || theme.getDefault(editorBackground)!;
defaultRule.settings.foreground = Color.Format.CSS.formatHexA(foreground);
defaultRule.settings.background = Color.Format.CSS.formatHexA(background);
return defaultRule;
......
......@@ -16,6 +16,7 @@ import { URI } from 'vs/base/common/uri';
const themesExtPoint = ExtensionsRegistry.registerExtensionPoint<IThemeExtensionPoint[]>({
extensionPoint: 'themes',
isDynamic: true,
jsonSchema: {
description: nls.localize('vscode.extension.contributes.themes', 'Contributes textmate color themes.'),
type: 'array',
......@@ -61,6 +62,7 @@ export class ColorThemeStore {
private initialize() {
themesExtPoint.setHandler((extensions) => {
this.extensionsColorThemes.length = 1; // remove all but the default theme
for (let ext of extensions) {
let extensionData = {
extensionId: ext.description.identifier.value,
......@@ -108,9 +110,9 @@ export class ColorThemeStore {
});
}
public findThemeData(themeId: string, defaultId?: string): Promise<ColorThemeData> {
public findThemeData(themeId: string, defaultId?: string): Promise<ColorThemeData | undefined> {
return this.getColorThemes().then(allThemes => {
let defaultTheme: ColorThemeData = undefined;
let defaultTheme: ColorThemeData | undefined = undefined;
for (let t of allThemes) {
if (t.id === themeId) {
return <ColorThemeData>t;
......@@ -123,9 +125,9 @@ export class ColorThemeStore {
});
}
public findThemeDataBySettingsId(settingsId: string, defaultId: string): Promise<ColorThemeData> {
public findThemeDataBySettingsId(settingsId: string, defaultId: string | undefined): Promise<ColorThemeData | undefined> {
return this.getColorThemes().then(allThemes => {
let defaultTheme: ColorThemeData = undefined;
let defaultTheme: ColorThemeData | undefined = undefined;
for (let t of allThemes) {
if (t.settingsId === settingsId) {
return <ColorThemeData>t;
......@@ -139,7 +141,7 @@ export class ColorThemeStore {
}
public getColorThemes(): Promise<IColorTheme[]> {
return this.extensionService.whenInstalledExtensionsRegistered().then(isReady => {
return this.extensionService.whenInstalledExtensionsRegistered().then(_ => {
return this.extensionsColorThemes;
});
}
......
......@@ -15,7 +15,7 @@ import { getParseErrorMessage } from 'vs/base/common/jsonErrorMessages';
export class FileIconThemeData implements IFileIconTheme {
id: string;
label: string;
settingsId?: string;
settingsId: string | null;
description?: string;
hasFileIcons: boolean;
hasFolderIcons: boolean;
......@@ -73,7 +73,7 @@ export class FileIconThemeData implements IFileIconTheme {
themeData = FileIconThemeData._noIconTheme = new FileIconThemeData();
themeData.id = '';
themeData.label = '';
themeData.settingsId = undefined;
themeData.settingsId = null;
themeData.hasFileIcons = false;
themeData.hasFolderIcons = false;
themeData.hidesExplorerArrows = false;
......@@ -86,9 +86,9 @@ export class FileIconThemeData implements IFileIconTheme {
static createUnloadedTheme(id: string): FileIconThemeData {
let themeData = new FileIconThemeData();
themeData.id = '';
themeData.id = id;
themeData.label = '';
themeData.settingsId = undefined;
themeData.settingsId = '__' + id;
themeData.isLoaded = false;
themeData.hasFileIcons = false;
themeData.hasFolderIcons = false;
......
......@@ -16,6 +16,7 @@ import { URI } from 'vs/base/common/uri';
const iconThemeExtPoint = ExtensionsRegistry.registerExtensionPoint<IThemeExtensionPoint[]>({
extensionPoint: 'iconThemes',
isDynamic: true,
jsonSchema: {
description: nls.localize('vscode.extension.contributes.iconThemes', 'Contributes file icon themes.'),
type: 'array',
......@@ -56,6 +57,7 @@ export class FileIconThemeStore {
private initialize() {
iconThemeExtPoint.setHandler((extensions) => {
this.knownIconThemes.length = 0;
for (let ext of extensions) {
let extensionData = {
extensionId: ext.description.identifier.value,
......@@ -109,25 +111,31 @@ export class FileIconThemeStore {
}
public findThemeData(iconTheme: string): Promise<FileIconThemeData | null> {
public findThemeData(iconTheme: string): Promise<FileIconThemeData | undefined> {
if (iconTheme.length === 0) {
return Promise.resolve(FileIconThemeData.noIconTheme());
}
return this.getFileIconThemes().then(allIconSets => {
for (let iconSet of allIconSets) {
if (iconSet.id === iconTheme) {
return iconSet;
}
}
return null;
return undefined;
});
}
public findThemeBySettingsId(settingsId: string): Promise<FileIconThemeData | null> {
public findThemeBySettingsId(settingsId: string | null): Promise<FileIconThemeData | undefined> {
if (!settingsId) {
return Promise.resolve(FileIconThemeData.noIconTheme());
}
return this.getFileIconThemes().then(allIconSets => {
for (let iconSet of allIconSets) {
if (iconSet.settingsId === settingsId) {
return iconSet;
}
}
return null;
return undefined;
});
}
......
......@@ -29,6 +29,7 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
import { IFileService, FileChangeType } from 'vs/platform/files/common/files';
import { URI } from 'vs/base/common/uri';
import * as resources from 'vs/base/common/resources';
import { IJSONSchema, IJSONSchemaMap } from 'vs/base/common/jsonSchema';
// implementation
......@@ -74,12 +75,12 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
private currentColorTheme: ColorThemeData;
private container: HTMLElement;
private readonly onColorThemeChange: Emitter<IColorTheme>;
private watchedColorThemeLocation: URI;
private watchedColorThemeLocation: URI | undefined;
private iconThemeStore: FileIconThemeStore;
private currentIconTheme: FileIconThemeData;
private readonly onFileIconThemeChange: Emitter<IFileIconTheme>;
private watchedIconThemeLocation: URI;
private watchedIconThemeLocation: URI | undefined;
private themingParticipantChangeListener: IDisposable;
private _configurationWriter: ConfigurationWriter;
......@@ -114,7 +115,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
// In order to avoid paint flashing for tokens, because
// themes are loaded asynchronously, we need to initialize
// a color theme document with good defaults until the theme is loaded
let themeData: ColorThemeData | null = null;
let themeData: ColorThemeData | undefined = undefined;
let persistedThemeData = this.storageService.get(PERSISTED_THEME_STORAGE_KEY, StorageScope.GLOBAL);
if (persistedThemeData) {
themeData = ColorThemeData.fromStorageData(persistedThemeData);
......@@ -126,12 +127,11 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
themeData.setCustomColors(this.colorCustomizations);
themeData.setCustomTokenColors(this.tokenColorCustomizations);
this.updateDynamicCSSRules(themeData);
this.applyTheme(themeData, null, true);
this.applyTheme(themeData, undefined, true);
let iconData: FileIconThemeData | null = null;
let persistedIconThemeData = this.storageService.get(PERSISTED_ICON_THEME_STORAGE_KEY, StorageScope.GLOBAL);
if (persistedIconThemeData) {
iconData = FileIconThemeData.fromStorageData(persistedIconThemeData);
const iconData = FileIconThemeData.fromStorageData(persistedIconThemeData);
if (iconData) {
_applyIconTheme(iconData, () => {
this.doSetFileIconTheme(iconData);
......@@ -144,33 +144,48 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
this.installConfigurationListener();
});
// update settings schema setting
// update settings schema setting for theme specific settings
this.colorThemeStore.onDidChange(themes => {
const enumDescription = themeData.description || '';
const themeSpecificWorkbenchColors: IJSONSchema = { properties: {} };
const themeSpecificTokenColors: IJSONSchema = { properties: {} };
colorCustomizationsSchema.properties = colorThemeSchema.colorsSchema.properties;
const copyColorCustomizationsSchema = { ...colorCustomizationsSchema };
copyColorCustomizationsSchema.properties = { ...colorThemeSchema.colorsSchema.properties };
for (let t of themes) {
colorThemeSettingSchema.enum!.push(t.settingsId);
colorThemeSettingSchema.enumDescriptions!.push(t.description || '');
const themeId = `[${t.settingsId}]`;
themeSpecificWorkbenchColors.properties![themeId] = colorThemeSchema.colorsSchema;
themeSpecificTokenColors.properties![themeId] = { properties: tokenColorConfigurationProperties, additionalProperties: false };
}
customEditorColorSchema.properties = customEditorColorConfigurationProperties;
const copyCustomEditorColorSchema = { ...customEditorColorSchema };
copyCustomEditorColorSchema.properties = { ...customEditorColorConfigurationProperties };
colorCustomizationsSchema.allOf![1] = themeSpecificWorkbenchColors;
tokenColorCustomizationSchema.allOf![1] = themeSpecificTokenColors;
themes.forEach(t => {
colorThemeSettingSchema.enum.push(t.settingsId);
colorThemeSettingSchema.enumDescriptions.push(enumDescription);
const themeId = `[${t.settingsId}]`;
colorCustomizationsSchema.properties[themeId] = copyColorCustomizationsSchema;
customEditorColorSchema.properties[themeId] = copyCustomEditorColorSchema;
});
configurationRegistry.notifyConfigurationSchemaUpdated(themeSettingsConfiguration, tokenColorCustomizationConfiguration);
configurationRegistry.notifyConfigurationSchemaUpdated(themeSettingsConfiguration);
configurationRegistry.notifyConfigurationSchemaUpdated(customEditorColorConfiguration);
if (this.currentColorTheme.isLoaded) {
this.colorThemeStore.findThemeData(this.currentColorTheme.id).then(theme => {
if (!theme) {
this.setColorTheme(DEFAULT_THEME_ID, undefined);
} else {
this.restoreColorTheme();
}
});
}
});
this.iconThemeStore.onDidChange(themes => {
iconThemeSettingSchema.enum = [null, ...themes.map(t => t.settingsId)];
iconThemeSettingSchema.enumDescriptions = [iconThemeSettingSchema.enumDescriptions[0], ...themes.map(t => themeData.description || '')];
iconThemeSettingSchema.enumDescriptions = [iconThemeSettingSchema.enumDescriptions![0], ...themes.map(t => t.description || '')];
configurationRegistry.notifyConfigurationSchemaUpdated(themeSettingsConfiguration);
if (this.currentIconTheme.isLoaded) {
this.iconThemeStore.findThemeData(this.currentIconTheme.id).then(theme => {
if (!theme) {
this.setFileIconTheme(DEFAULT_ICON_THEME_SETTING_VALUE, undefined);
} else {
this.restoreFileIconTheme();
}
});
}
});
}
......@@ -183,7 +198,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
this.currentColorTheme.setCustomColors(this.colorCustomizations);
this.currentColorTheme.setCustomTokenColors(this.tokenColorCustomizations);
this.updateDynamicCSSRules(this.currentColorTheme);
this.applyTheme(this.currentColorTheme, null, false);
this.applyTheme(this.currentColorTheme, undefined, false);
}
if (this.watchedIconThemeLocation && this.currentIconTheme && e.contains(this.watchedIconThemeLocation, FileChangeType.UPDATED)) {
await this.currentIconTheme.reload(this.fileService);
......@@ -208,7 +223,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
return this.onColorThemeChange.event;
}
private initialize(): Promise<[IColorTheme, IFileIconTheme]> {
private initialize(): Promise<[IColorTheme | null, IFileIconTheme | null]> {
let detectHCThemeSetting = this.configurationService.getValue<boolean>(DETECT_HC_SETTING);
let colorThemeSetting: string;
......@@ -218,14 +233,14 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
colorThemeSetting = this.configurationService.getValue<string>(COLOR_THEME_SETTING);
}
let iconThemeSetting = this.configurationService.getValue<string>(ICON_THEME_SETTING) || '';
let iconThemeSetting = this.configurationService.getValue<string | null>(ICON_THEME_SETTING);
return Promise.all([
this.colorThemeStore.findThemeDataBySettingsId(colorThemeSetting, DEFAULT_THEME_ID).then(theme => {
return this.setColorTheme(theme && theme.id, null);
return this.setColorTheme(theme && theme.id, undefined);
}),
this.iconThemeStore.findThemeBySettingsId(iconThemeSetting).then(theme => {
return this.setFileIconTheme(theme && theme.id, null);
return this.setFileIconTheme(theme && theme.id, undefined);
}),
]);
}
......@@ -235,18 +250,18 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
if (e.affectsConfiguration(COLOR_THEME_SETTING)) {
let colorThemeSetting = this.configurationService.getValue<string>(COLOR_THEME_SETTING);
if (colorThemeSetting !== this.currentColorTheme.settingsId) {
this.colorThemeStore.findThemeDataBySettingsId(colorThemeSetting, null).then(theme => {
this.colorThemeStore.findThemeDataBySettingsId(colorThemeSetting, undefined).then(theme => {
if (theme) {
this.setColorTheme(theme.id, null);
this.setColorTheme(theme.id, undefined);
}
});
}
}
if (e.affectsConfiguration(ICON_THEME_SETTING)) {
let iconThemeSetting = this.configurationService.getValue<string>(ICON_THEME_SETTING) || '';
let iconThemeSetting = this.configurationService.getValue<string | null>(ICON_THEME_SETTING);
if (iconThemeSetting !== this.currentIconTheme.settingsId) {
this.iconThemeStore.findThemeBySettingsId(iconThemeSetting).then(theme => {
this.setFileIconTheme(theme && theme.id, null);
this.setFileIconTheme(theme && theme.id, undefined);
});
}
}
......@@ -280,7 +295,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
return this.getColorTheme();
}
public setColorTheme(themeId: string, settingsTarget: ConfigurationTarget | null): Promise<IColorTheme | null> {
public setColorTheme(themeId: string | undefined, settingsTarget: ConfigurationTarget | undefined): Promise<IColorTheme | null> {
if (!themeId) {
return Promise.resolve(null);
}
......@@ -290,10 +305,11 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
themeId = validateThemeId(themeId); // migrate theme ids
return this.colorThemeStore.findThemeData(themeId, DEFAULT_THEME_ID).then(themeData => {
if (!themeData) {
return this.colorThemeStore.findThemeData(themeId, DEFAULT_THEME_ID).then(data => {
if (!data) {
return null;
}
const themeData = data;
return themeData.ensureLoaded(this.fileService).then(_ => {
if (themeId === this.currentColorTheme.id && !this.currentColorTheme.isLoaded && this.currentColorTheme.hasEqualData(themeData)) {
// the loaded theme is identical to the perisisted theme. Don't need to send an event.
......@@ -307,7 +323,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
this.updateDynamicCSSRules(themeData);
return this.applyTheme(themeData, settingsTarget);
}, error => {
return Promise.reject(new Error(nls.localize('error.cannotloadtheme', "Unable to load {0}: {1}", themeData.location.toString(), error.message)));
return Promise.reject(new Error(nls.localize('error.cannotloadtheme', "Unable to load {0}: {1}", themeData.location!.toString(), error.message)));
});
});
}
......@@ -315,9 +331,9 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
public restoreColorTheme() {
let colorThemeSetting = this.configurationService.getValue<string>(COLOR_THEME_SETTING);
if (colorThemeSetting !== this.currentColorTheme.settingsId) {
this.colorThemeStore.findThemeDataBySettingsId(colorThemeSetting, null).then(theme => {
this.colorThemeStore.findThemeDataBySettingsId(colorThemeSetting, undefined).then(theme => {
if (theme) {
this.setColorTheme(theme.id, null);
this.setColorTheme(theme.id, undefined);
}
});
}
......@@ -338,7 +354,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
_applyRules(cssRules.join('\n'), colorThemeRulesClassName);
}
private applyTheme(newTheme: ColorThemeData, settingsTarget: ConfigurationTarget, silent = false): Promise<IColorTheme | null> {
private applyTheme(newTheme: ColorThemeData, settingsTarget: ConfigurationTarget | undefined, silent = false): Promise<IColorTheme | null> {
if (this.container) {
if (this.currentColorTheme) {
removeClasses(this.container, this.currentColorTheme.id);
......@@ -355,7 +371,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
if (this.fileService && !resources.isEqual(newTheme.location, this.watchedColorThemeLocation)) {
if (this.watchedColorThemeLocation) {
this.fileService.unwatchFileChanges(this.watchedColorThemeLocation);
this.watchedColorThemeLocation = null;
this.watchedColorThemeLocation = undefined;
}
if (newTheme.location && (newTheme.watch || !!this.environmentService.extensionDevelopmentLocationURI)) {
this.watchedColorThemeLocation = newTheme.location;
......@@ -377,7 +393,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
return this.writeColorThemeConfiguration(settingsTarget);
}
private writeColorThemeConfiguration(settingsTarget: ConfigurationTarget): Promise<IColorTheme> {
private writeColorThemeConfiguration(settingsTarget: ConfigurationTarget | undefined): Promise<IColorTheme> {
if (!types.isUndefinedOrNull(settingsTarget)) {
return this.configurationWriter.writeConfiguration(COLOR_THEME_SETTING, this.currentColorTheme.settingsId, settingsTarget).then(_ => this.currentColorTheme);
}
......@@ -385,7 +401,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
}
private themeExtensionsActivated = new Map<string, boolean>();
private sendTelemetry(themeId: string, themeData: ExtensionData, themeType: string) {
private sendTelemetry(themeId: string, themeData: ExtensionData | undefined, themeType: string) {
if (themeData) {
let key = themeType + themeData.extensionId;
if (!this.themeExtensionsActivated.get(key)) {
......@@ -422,7 +438,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
return this.currentIconTheme;
}
public setFileIconTheme(iconTheme: string, settingsTarget: ConfigurationTarget): Promise<IFileIconTheme> {
public setFileIconTheme(iconTheme: string | undefined, settingsTarget: ConfigurationTarget | undefined): Promise<IFileIconTheme> {
iconTheme = iconTheme || '';
if (iconTheme === this.currentIconTheme.id && this.currentIconTheme.isLoaded) {
return this.writeFileIconConfiguration(settingsTarget);
......@@ -436,16 +452,25 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
return this.writeFileIconConfiguration(settingsTarget);
};
return this.iconThemeStore.findThemeData(iconTheme).then(iconThemeData => {
if (!iconThemeData) {
iconThemeData = FileIconThemeData.noIconTheme();
}
return this.iconThemeStore.findThemeData(iconTheme).then(data => {
const iconThemeData = data || FileIconThemeData.noIconTheme();
return iconThemeData.ensureLoaded(this.fileService).then(_ => {
return _applyIconTheme(iconThemeData, onApply);
});
});
}
public restoreFileIconTheme() {
let fileIconThemeSetting = this.configurationService.getValue<string | null>(ICON_THEME_SETTING);
if (fileIconThemeSetting !== this.currentIconTheme.settingsId) {
this.iconThemeStore.findThemeBySettingsId(fileIconThemeSetting).then(theme => {
if (theme) {
this.setFileIconTheme(theme.id, undefined);
}
});
}
}
private doSetFileIconTheme(iconThemeData: FileIconThemeData): void {
this.currentIconTheme = iconThemeData;
......@@ -460,7 +485,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
if (this.fileService && !resources.isEqual(iconThemeData.location, this.watchedIconThemeLocation)) {
if (this.watchedIconThemeLocation) {
this.fileService.unwatchFileChanges(this.watchedIconThemeLocation);
this.watchedIconThemeLocation = null;
this.watchedIconThemeLocation = undefined;
}
if (iconThemeData.location && (iconThemeData.watch || !!this.environmentService.extensionDevelopmentLocationURI)) {
this.watchedIconThemeLocation = iconThemeData.location;
......@@ -475,7 +500,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
}
private writeFileIconConfiguration(settingsTarget: ConfigurationTarget): Promise<IFileIconTheme> {
private writeFileIconConfiguration(settingsTarget: ConfigurationTarget | undefined): Promise<IFileIconTheme> {
if (!types.isUndefinedOrNull(settingsTarget)) {
return this.configurationWriter.writeConfiguration(ICON_THEME_SETTING, this.currentIconTheme.settingsId, settingsTarget).then(_ => this.currentIconTheme);
}
......@@ -504,7 +529,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
}
function _applyIconTheme(data: FileIconThemeData, onApply: (theme: FileIconThemeData) => Promise<IFileIconTheme>): Promise<IFileIconTheme> {
_applyRules(data.styleSheetContent, iconThemeRulesClassName);
_applyRules(data.styleSheetContent!, iconThemeRulesClassName);
return onApply(data);
}
......@@ -571,14 +596,10 @@ const iconThemeSettingSchema: IConfigurationPropertySchema = {
const colorCustomizationsSchema: IConfigurationPropertySchema = {
type: 'object',
description: nls.localize('workbenchColors', "Overrides colors from the currently selected color theme."),
properties: {},
additionalProperties: false,
allOf: [{ properties: colorThemeSchema.colorsSchema.properties }],
default: {},
defaultSnippets: [{
body: {
'statusBar.background': '#666666',
'panel.background': '#555555',
'sideBar.background': '#444444'
}
}]
};
......@@ -609,7 +630,7 @@ function tokenGroupSettings(description: string) {
};
}
const customEditorColorConfigurationProperties = {
const tokenColorConfigurationProperties: IJSONSchemaMap = {
comments: tokenGroupSettings(nls.localize('editorColors.comments', "Sets the colors and styles for comments")),
strings: tokenGroupSettings(nls.localize('editorColors.strings', "Sets the colors and styles for strings literals.")),
keywords: tokenGroupSettings(nls.localize('editorColors.keywords', "Sets the colors and styles for keywords.")),
......@@ -619,19 +640,18 @@ const customEditorColorConfigurationProperties = {
variables: tokenGroupSettings(nls.localize('editorColors.variables', "Sets the colors and styles for variables declarations and references.")),
[CUSTOM_EDITOR_SCOPE_COLORS_SETTING]: colorThemeSchema.tokenColorsSchema(nls.localize('editorColors.textMateRules', 'Sets colors and styles using textmate theming rules (advanced).'))
};
const customEditorColorSchema: IConfigurationPropertySchema = {
const tokenColorCustomizationSchema: IConfigurationPropertySchema = {
description: nls.localize('editorColors', "Overrides editor colors and font style from the currently selected color theme."),
default: {},
additionalProperties: false,
properties: {}
allOf: [{ properties: tokenColorConfigurationProperties }]
};
const customEditorColorConfiguration: IConfigurationNode = {
const tokenColorCustomizationConfiguration: IConfigurationNode = {
id: 'editor',
order: 7.2,
type: 'object',
properties: {
[CUSTOM_EDITOR_COLORS_SETTING]: customEditorColorSchema
[CUSTOM_EDITOR_COLORS_SETTING]: tokenColorCustomizationSchema
}
};
configurationRegistry.registerConfiguration(customEditorColorConfiguration);
configurationRegistry.registerConfiguration(tokenColorCustomizationConfiguration);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册