未验证 提交 a0e0e88a 编写于 作者: M Martin Aeschlimann 提交者: GitHub

Merge pull request #38683 from Microsoft/ben/30032

cache icon data optimistically like color themes
......@@ -77,6 +77,39 @@ export class FileIconThemeData implements IFileIconTheme {
}
return themeData;
}
static fromStorageData(input: string): FileIconThemeData {
try {
let data = JSON.parse(input);
let theme = new FileIconThemeData();
for (let key in data) {
switch (key) {
case 'id':
case 'label':
case 'description':
case 'settingsId':
case 'extensionData':
case 'path':
theme[key] = data[key];
break;
}
}
return theme;
} catch (e) {
return null;
}
}
toStorageData() {
return JSON.stringify({
id: this.id,
label: this.label,
description: this.description,
settingsId: this.settingsId,
path: this.path,
extensionData: this.extensionData
});
}
}
interface IconDefinition {
......
......@@ -38,6 +38,7 @@ const DEFAULT_THEME_ID = 'vs-dark vscode-theme-defaults-themes-dark_plus-json';
const DEFAULT_THEME_SETTING_VALUE = 'Default Dark+';
const PERSISTED_THEME_STORAGE_KEY = 'colorThemeData';
const PERSISTED_ICON_THEME_STORAGE_KEY = 'iconThemeData';
const defaultThemeExtensionId = 'vscode-theme-defaults';
const oldDefaultThemeExtensionId = 'vscode-theme-colorful-defaults';
......@@ -132,6 +133,20 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
this.updateDynamicCSSRules(themeData);
this.applyTheme(themeData, null, true);
let iconData: FileIconThemeData = null;
let persistedIconThemeData = this.storageService.get(PERSISTED_ICON_THEME_STORAGE_KEY);
if (persistedIconThemeData) {
iconData = FileIconThemeData.fromStorageData(persistedIconThemeData);
if (iconData) {
_applyIconTheme(iconData, () => {
this.doSetFileIconTheme(iconData);
return TPromise.wrap(iconData);
});
}
}
this.initialize().then(null, errors.onUnexpectedError).then(_ => {
this.installConfigurationListener();
});
......@@ -353,23 +368,15 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
return this.writeFileIconConfiguration(settingsTarget);
}
let onApply = (newIconTheme: FileIconThemeData) => {
this.doSetFileIconTheme(newIconTheme);
// remember theme data for a quick restore
if (newIconTheme) {
this.currentIconTheme = newIconTheme;
this.storageService.store(PERSISTED_ICON_THEME_STORAGE_KEY, newIconTheme.toStorageData());
} else {
this.currentIconTheme = FileIconThemeData.noIconTheme();
this.storageService.remove(PERSISTED_ICON_THEME_STORAGE_KEY);
}
if (this.container) {
if (newIconTheme) {
$(this.container).addClass(fileIconsEnabledClass);
} else {
$(this.container).removeClass(fileIconsEnabledClass);
}
}
if (newIconTheme) {
this.sendTelemetry(newIconTheme.id, newIconTheme.extensionData, 'fileIcon');
}
this.onFileIconThemeChange.fire(this.currentIconTheme);
return this.writeFileIconConfiguration(settingsTarget);
};
......@@ -378,6 +385,27 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
});
}
private doSetFileIconTheme(iconThemeData: FileIconThemeData): void {
if (iconThemeData) {
this.currentIconTheme = iconThemeData;
} else {
this.currentIconTheme = FileIconThemeData.noIconTheme();
}
if (this.container) {
if (iconThemeData) {
$(this.container).addClass(fileIconsEnabledClass);
} else {
$(this.container).removeClass(fileIconsEnabledClass);
}
}
if (iconThemeData) {
this.sendTelemetry(iconThemeData.id, iconThemeData.extensionData, 'fileIcon');
}
this.onFileIconThemeChange.fire(this.currentIconTheme);
}
private writeFileIconConfiguration(settingsTarget: ConfigurationTarget): TPromise<IFileIconTheme> {
if (!types.isUndefinedOrNull(settingsTarget)) {
return this.configurationWriter.writeConfiguration(ICON_THEME_SETTING, this.currentIconTheme.settingsId, settingsTarget).then(_ => this.currentIconTheme);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册