[themes] revert uiTheme-> type change

This commit is contained in:
Martin Aeschlimann 2017-04-25 15:37:27 +02:00
parent 5e31e04cf0
commit c725d0706a
15 changed files with 53 additions and 73 deletions

View file

@ -1,6 +1,5 @@
{
"name": "Abyss",
"type": "dark",
"tokenColors": [
{
"settings": {

View file

@ -1,7 +1,6 @@
{
"$schema": "vscode://schemas/color-theme",
"name": "Dark Default Colors",
"type": "dark",
"colors": {
"editorBackground": "#1e1e1e",
"editorForeground": "#D4D4D4",

View file

@ -1,7 +1,6 @@
{
"$schema": "vscode://schemas/color-theme",
"name": "Dark+ (default dark)",
"type": "dark",
"include": "./dark_vs.json",
"tokenColors": [
{

View file

@ -1,7 +1,6 @@
{
"$schema": "vscode://schemas/color-theme",
"name": "Dark (Visual Studio)",
"type": "dark",
"include": "./dark_defaults.json",
"tokenColors": [
{

View file

@ -1,7 +1,6 @@
{
"$schema": "vscode://schemas/color-theme",
"name": "Dark High Contrast",
"type": "hc",
"include": "./hc_black_defaults.json",
"settings": [
{

View file

@ -1,7 +1,6 @@
{
"$schema": "vscode://schemas/color-theme",
"name": "High Contrast Default Colors",
"type": "hc",
"colors": {
"editorBackground": "#000000",
"editorForeground": "#FFFFFF",

View file

@ -1,7 +1,6 @@
{
"$schema": "vscode://schemas/color-theme",
"name": "Light Default Colors",
"type": "light",
"colors": {
"editorBackground": "#ffffff",
"editorForeground": "#000000",

View file

@ -1,7 +1,6 @@
{
"$schema": "vscode://schemas/color-theme",
"name": "Light+ (default light)",
"type": "light",
"include": "./light_vs.json",
"tokenColors": [
{

View file

@ -1,7 +1,6 @@
{
"$schema": "vscode://schemas/color-theme",
"name": "Light (Visual Studio)",
"type": "light",
"include": "./light_defaults.json",
"tokenColors": [
{

View file

@ -1,6 +1,5 @@
{
"name": "Quiet Light",
"type": "light",
"tokenColors": [
{
"settings": {

View file

@ -1,6 +1,5 @@
{
"name": "Solarized (dark)",
"type": "dark",
"tokenColors": [
{
"settings": {

View file

@ -1,6 +1,5 @@
{
"name": "Solarized (light)",
"type": "light",
"tokenColors": [
{
"settings": {

View file

@ -172,15 +172,9 @@ const schemaId = 'vscode://schemas/color-theme';
const schema: IJSONSchema = {
type: 'object',
properties: {
type: {
description: nls.localize('schema.type', 'The type of the theme, either light, dark or high contrast. Depending on the type, a different set of icons is used.'),
enum: ['light', 'dark', 'hc'],
enumDescriptions: [nls.localize('schema.light', 'Light theme, using dark icons'), nls.localize('schema.dark', 'Dark theme, using light icons'), nls.localize('schema.hc', 'High contrast theme, using light icons')]
},
colors: colorsSchema,
tokenColors: tokenColorsSchema
},
required: ['type']
}
};
export function register() {

View file

@ -29,7 +29,6 @@ export class ColorThemeData implements IColorTheme {
}
id: string;
type: ThemeType;
label: string;
settingsId: string;
description?: string;
@ -78,8 +77,7 @@ export class ColorThemeData implements IColorTheme {
this.colorMap = {};
this.defaultColorMap = {};
if (this.path) {
return _loadColorThemeFromFile(this.path, this.tokenColors, this.colorMap, this.type).then(type => {
this.type = type;
return _loadColorThemeFromFile(this.path, this.tokenColors, this.colorMap).then(_ => {
this.isLoaded = true;
_completeTokenColors(this);
});
@ -106,7 +104,6 @@ export class ColorThemeData implements IColorTheme {
}
return JSON.stringify({
id: this.id,
type: this.type,
label: this.label,
settingsId: this.settingsId,
selector: this.selector,
@ -119,25 +116,35 @@ export class ColorThemeData implements IColorTheme {
hasEqualData(other: ColorThemeData) {
return objects.equals(this.colorMap, other.colorMap) && objects.equals(this.tokenColors, other.tokenColors);
}
get type(): ThemeType {
let baseTheme = this.id.split(' ')[0];
switch (baseTheme) {
case VS_LIGHT_THEME: return 'light';
case VS_HC_THEME: return 'hc';
default: return 'dark';
}
}
}
export function fromStorageData(themeService: WorkbenchThemeService, input: string): ColorThemeData {
let data = JSON.parse(input);
let theme = new ColorThemeData(themeService);
for (let key in data) {
if (key !== 'colorMap') {
theme[key] = data[key];
} else {
let colorMapData = data[key];
for (let id in colorMapData) {
theme.colorMap[id] = Color.fromHex(colorMapData[id]);
try {
let data = JSON.parse(input);
let theme = new ColorThemeData(themeService);
for (let key in data) {
if (key !== 'colorMap') {
theme[key] = data[key];
} else {
let colorMapData = data[key];
for (let id in colorMapData) {
theme.colorMap[id] = Color.fromHex(colorMapData[id]);
}
}
}
return theme;
} catch (e) {
return null;
}
if (!theme.type) {
theme.type = baseThemeToType(theme.id);
}
return theme;
}
export function fromExtensionTheme(themeService: WorkbenchThemeService, theme: IThemeExtensionPoint, normalizedAbsolutePath: string, extensionData: ExtensionData): ColorThemeData {
@ -146,7 +153,6 @@ export function fromExtensionTheme(themeService: WorkbenchThemeService, theme: I
let themeSelector = toCSSSelector(extensionData.extensionId + '-' + Paths.normalize(theme.path));
let themeData = new ColorThemeData(themeService);
themeData.id = `${baseTheme} ${themeSelector}`;
themeData.type = baseThemeToType(baseTheme);
themeData.label = theme.label || Paths.basename(theme.path);
themeData.settingsId = theme.id || themeData.label;
themeData.selector = `${baseTheme}.${themeSelector}`;
@ -157,15 +163,6 @@ export function fromExtensionTheme(themeService: WorkbenchThemeService, theme: I
return themeData;
}
function baseThemeToType(themeId: string): ThemeType {
let baseTheme = themeId.split(' ')[0];
switch (baseTheme) {
case VS_LIGHT_THEME: return 'light';
case VS_HC_THEME: return 'hc';
default: return 'dark';
}
}
function toCSSSelector(str: string) {
str = str.replace(/[^_\-a-zA-Z0-9]/g, '-');
if (str.charAt(0).match(/[0-9\-]/)) {
@ -174,33 +171,27 @@ function toCSSSelector(str: string) {
return str;
}
function _loadColorThemeFromFile(themePath: string, resultRules: ITokenColorizationRule[], resultColors: IColorMap, defaultType: ThemeType): TPromise<ThemeType> {
function _loadColorThemeFromFile(themePath: string, resultRules: ITokenColorizationRule[], resultColors: IColorMap): TPromise<any> {
if (Paths.extname(themePath) === '.json') {
return pfs.readFile(themePath).then(content => {
let errors: Json.ParseError[] = [];
let contentValue = Json.parse(content.toString(), errors);
if (errors.length > 0) {
return TPromise.wrapError<ThemeType>(new Error(nls.localize('error.cannotparsejson', "Problems parsing JSON theme file: {0}", errors.map(e => Json.getParseErrorMessage(e.error)).join(', '))));
return TPromise.wrapError(new Error(nls.localize('error.cannotparsejson', "Problems parsing JSON theme file: {0}", errors.map(e => Json.getParseErrorMessage(e.error)).join(', '))));
}
let includeCompletes = TPromise.as(defaultType);
let includeCompletes = TPromise.as(null);
if (contentValue.include) {
includeCompletes = _loadColorThemeFromFile(Paths.join(Paths.dirname(themePath), contentValue.include), resultRules, resultColors, defaultType);
includeCompletes = _loadColorThemeFromFile(Paths.join(Paths.dirname(themePath), contentValue.include), resultRules, resultColors);
}
return includeCompletes.then(type => {
return includeCompletes.then(_ => {
if (Array.isArray(contentValue.settings)) {
convertSettings(contentValue.settings, resultRules, resultColors);
return type;
return null;
}
let themeType = contentValue.type;
if (themeType !== 'light' && themeType !== 'dark' && themeType !== 'hc') {
return TPromise.wrapError<ThemeType>(new Error(nls.localize({ key: 'error.invalidformat.type', comment: ['{0} will be replaced by a path. Values in quotes should not be translated.'] }, "Problem parsing color theme file: {0}. Property 'type' must be 'light', 'dark' or 'hc'", themePath)));
}
type = themeType;
let colors = contentValue.colors;
if (colors) {
if (typeof colors !== 'object') {
return TPromise.wrapError<ThemeType>(new Error(nls.localize({ key: 'error.invalidformat.colors', comment: ['{0} will be replaced by a path. Values in quotes should not be translated.'] }, "Problem parsing color theme file: {0}. Property 'colors' is not of type 'object'.", themePath)));
return TPromise.wrapError(new Error(nls.localize({ key: 'error.invalidformat.colors', comment: ['{0} will be replaced by a path. Values in quotes should not be translated.'] }, "Problem parsing color theme file: {0}. Property 'colors' is not of type 'object'.", themePath)));
}
// new JSON color themes format
for (let colorId in colors) {
@ -214,35 +205,36 @@ function _loadColorThemeFromFile(themePath: string, resultRules: ITokenColorizat
if (tokenColors) {
if (Array.isArray(tokenColors)) {
resultRules.push(...tokenColors);
return null;
} else if (typeof tokenColors === 'string') {
return _loadSyntaxTokensFromFile(Paths.join(Paths.dirname(themePath), tokenColors), resultRules, {}, type);
return _loadSyntaxTokensFromFile(Paths.join(Paths.dirname(themePath), tokenColors), resultRules, {});
} else {
return TPromise.wrapError<ThemeType>(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 text mate theme file", themePath)));
return TPromise.wrapError(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 text mate theme file", themePath)));
}
}
return type;
return null;
});
});
} else {
return _loadSyntaxTokensFromFile(themePath, resultRules, resultColors, defaultType);
return _loadSyntaxTokensFromFile(themePath, resultRules, resultColors);
}
}
function _loadSyntaxTokensFromFile(themePath: string, resultRules: ITokenColorizationRule[], resultColors: IColorMap, type: ThemeType): TPromise<ThemeType> {
function _loadSyntaxTokensFromFile(themePath: string, resultRules: ITokenColorizationRule[], resultColors: IColorMap): TPromise<any> {
return pfs.readFile(themePath).then(content => {
try {
let contentValue = plist.parse(content.toString());
let settings: ITokenColorizationRule[] = contentValue.settings;
if (!Array.isArray(settings)) {
return TPromise.wrapError<ThemeType>(new Error(nls.localize('error.plist.invalidformat', "Problem parsing tmTheme file: {0}. 'settings' is not array.")));
return TPromise.wrapError(new Error(nls.localize('error.plist.invalidformat', "Problem parsing tmTheme file: {0}. 'settings' is not array.")));
}
convertSettings(settings, resultRules, resultColors);
return TPromise.as(type);
return TPromise.as(null);
} catch (e) {
return TPromise.wrapError<ThemeType>(new Error(nls.localize('error.cannotparse', "Problems parsing tmTheme file: {0}", e.message)));
return TPromise.wrapError(new Error(nls.localize('error.cannotparse', "Problems parsing tmTheme file: {0}", e.message)));
}
}, error => {
return TPromise.wrapError<ThemeType>(new Error(nls.localize('error.cannotload', "Problems loading tmTheme file {0}: {1}", themePath, error.message)));
return TPromise.wrapError(new Error(nls.localize('error.cannotload', "Problems loading tmTheme file {0}: {1}", themePath, error.message)));
});
}
/**

View file

@ -83,8 +83,12 @@ let themesExtPoint = ExtensionsRegistry.registerExtensionPoint<IThemeExtensionPo
description: nls.localize('vscode.extension.contributes.themes.label', 'Label of the color theme as shown in the UI.'),
type: 'string'
},
uiTheme: {
description: nls.localize('vscode.extension.contributes.themes.uiTheme', 'Base theme defining the colors around the editor: \'vs\' is the light color theme, \'vs-dark\' is the dark color theme. \'hc-black\' is the dark high contrast theme.'),
enum: [VS_LIGHT_THEME, VS_DARK_THEME, VS_HC_THEME]
},
path: {
description: nls.localize('vscode.extension.contributes.themes.path', 'Path of the color theme file. The path is relative to the extension folder and is typically \'./themes/my-color-theme.json\'.'),
description: nls.localize('vscode.extension.contributes.themes.path', 'Path of the tmTheme file. The path is relative to the extension folder and is typically \'./themes/themeFile.tmTheme\'.'),
type: 'string'
}
},
@ -221,9 +225,12 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
extensionData: null
};
let themeData = null;
let persistedThemeData = this.storageService.get(PERSISTED_THEME_STORAGE_KEY);
if (persistedThemeData) {
let themeData = fromStorageData(this, persistedThemeData);
themeData = fromStorageData(this, persistedThemeData);
}
if (themeData !== null) {
this.updateColorCustomizations(this.configurationService.lookup<IColorCustomizations>(CUSTOM_COLORS_SETTING).value, false);
this.updateDynamicCSSRules(themeData);
this.applyTheme(themeData, null, true);
@ -235,7 +242,6 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
let initialTheme = new ColorThemeData(this);
initialTheme.id = isLightTheme ? VS_LIGHT_THEME : VS_DARK_THEME;
initialTheme.type = isLightTheme ? 'light' : 'dark';
initialTheme.label = '';
initialTheme.selector = isLightTheme ? VS_LIGHT_THEME : VS_DARK_THEME;
initialTheme.settingsId = null;
@ -402,7 +408,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
if (themeData) {
return themeData.ensureLoaded(this).then(_ => {
if (themeId === this.currentColorTheme.id && !this.currentColorTheme.isLoaded && this.currentColorTheme.hasEqualData(themeData)) {
// the loaded theme is identical to the persisted theme. Don't need to send an event.
// the loaded theme is identical to the perisisted theme. Don't need to send an event.
this.currentColorTheme = themeData;
return TPromise.as(themeData);
}
@ -469,7 +475,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
return TPromise.as(this.currentColorTheme);
}
public getColorTheme() {
public getColorTheme(): IColorTheme {
return this.currentColorTheme;
}