From 8ad8151abc7636da0dade81242fe24b0a0f58593 Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Thu, 9 Mar 2017 16:32:32 +0100 Subject: [PATCH] [themes] convert default themes to new format --- build/npm/update-theme.js | 2 +- .../theme-defaults/themes/dark_defaults.json | 8 +++++ .../theme-defaults/themes/dark_plus.json | 10 ++---- extensions/theme-defaults/themes/dark_vs.json | 19 ++++++---- .../theme-defaults/themes/hc_black.json | 4 ++- .../themes/hc_black_defaults.json | 8 +++++ .../theme-defaults/themes/light_defaults.json | 8 +++++ .../theme-defaults/themes/light_plus.json | 10 ++---- .../theme-defaults/themes/light_vs.json | 27 +++++++------- .../themes/common/colorThemeSchema.ts | 2 +- .../themes/electron-browser/colorThemeData.ts | 35 +++++++++++++------ .../electron-browser/stylesContributions.ts | 8 +++-- .../themes/electron-browser/themeService.ts | 2 +- 13 files changed, 90 insertions(+), 53 deletions(-) create mode 100644 extensions/theme-defaults/themes/dark_defaults.json create mode 100644 extensions/theme-defaults/themes/hc_black_defaults.json create mode 100644 extensions/theme-defaults/themes/light_defaults.json diff --git a/build/npm/update-theme.js b/build/npm/update-theme.js index c11ef31b940..4698c459009 100644 --- a/build/npm/update-theme.js +++ b/build/npm/update-theme.js @@ -47,7 +47,7 @@ exports.update = function (srcName, destName) { } } result.name = theme.name; - result.syntaxTokens = settings; + result.tokenColors = settings; result.colors = colorMap; } fs.writeFileSync(destName, JSON.stringify(result, null, '\t')); diff --git a/extensions/theme-defaults/themes/dark_defaults.json b/extensions/theme-defaults/themes/dark_defaults.json new file mode 100644 index 00000000000..65cf5bc4c2b --- /dev/null +++ b/extensions/theme-defaults/themes/dark_defaults.json @@ -0,0 +1,8 @@ +{ + "$schema": "vscode://schemas/color-theme", + "name": "Dark Default Colors", + "colors": { + "editorBackground": "#1e1e1e", + "editorForeground": "#D4D4D4" + } +} \ No newline at end of file diff --git a/extensions/theme-defaults/themes/dark_plus.json b/extensions/theme-defaults/themes/dark_plus.json index 960abe1a025..600050b1140 100644 --- a/extensions/theme-defaults/themes/dark_plus.json +++ b/extensions/theme-defaults/themes/dark_plus.json @@ -1,13 +1,13 @@ { - "name": "Dark+", + "$schema": "vscode://schemas/color-theme", + "name": "Dark+ (default dark)", "include": "./dark_vs.json", - "settings": [ + "tokenColors": [ { "name": "Function declarations", "scope": [ "entity.name.function", "support.function", - "support.constant.handlebars" ], "settings": { @@ -22,12 +22,10 @@ "support.type", "entity.name.type", "entity.name.class", - "storage.type.cs", "storage.type.generic.cs", "storage.type.modifier.cs", "storage.type.variable.cs", - "storage.type.annotation.java", "storage.type.generic.java", "storage.type.java", @@ -35,7 +33,6 @@ "storage.type.primitive.array.java", "storage.type.primitive.java", "storage.type.token.java", - "storage.type.groovy", "storage.type.annotation.groovy", "storage.type.parameters.groovy", @@ -57,7 +54,6 @@ "support.constant.math", "support.constant.dom", "support.constant.json", - "entity.other.inherited-class" ], "settings": { diff --git a/extensions/theme-defaults/themes/dark_vs.json b/extensions/theme-defaults/themes/dark_vs.json index 4b0ce07fc7a..8bdf64941e8 100644 --- a/extensions/theme-defaults/themes/dark_vs.json +++ b/extensions/theme-defaults/themes/dark_vs.json @@ -1,6 +1,8 @@ { - "name": "Dark Visual Studio", - "settings": [ + "$schema": "vscode://schemas/color-theme", + "name": "Dark (Visual Studio)", + "include": "./dark_defaults.json", + "tokenColors": [ { "settings": { "foreground": "#D4D4D4", @@ -25,7 +27,6 @@ "foreground": "#000080" } }, - { "scope": "comment", "settings": { @@ -78,9 +79,7 @@ "entity.other.attribute-name.parent-selector.css", "entity.other.attribute-name.pseudo-class.css", "entity.other.attribute-name.pseudo-element.css", - "source.css.less entity.other.attribute-name.id", - "entity.other.attribute-name.attribute.scss", "entity.other.attribute-name.scss" ], @@ -282,7 +281,10 @@ } }, { - "scope": ["keyword.operator.new", "keyword.operator.expression"], + "scope": [ + "keyword.operator.new", + "keyword.operator.expression" + ], "settings": { "foreground": "#569cd6" } @@ -316,7 +318,10 @@ }, { "name": "coloring of the Java import and package identifiers", - "scope": ["storage.modifier.import.java", "storage.modifier.package.java"], + "scope": [ + "storage.modifier.import.java", + "storage.modifier.package.java" + ], "settings": { "foreground": "#d4d4d4" } diff --git a/extensions/theme-defaults/themes/hc_black.json b/extensions/theme-defaults/themes/hc_black.json index a2c82bcf8fd..2a55b310398 100644 --- a/extensions/theme-defaults/themes/hc_black.json +++ b/extensions/theme-defaults/themes/hc_black.json @@ -1,5 +1,7 @@ { - "name": "Dark Visual Studio", + "$schema": "vscode://schemas/color-theme", + "name": "Dark High Contrast", + "include": "./hc_black_defaults.json", "settings": [ { "settings": { diff --git a/extensions/theme-defaults/themes/hc_black_defaults.json b/extensions/theme-defaults/themes/hc_black_defaults.json new file mode 100644 index 00000000000..3d55f194810 --- /dev/null +++ b/extensions/theme-defaults/themes/hc_black_defaults.json @@ -0,0 +1,8 @@ +{ + "$schema": "vscode://schemas/color-theme", + "name": "High Contrast Default Colors", + "colors": { + "editorBackground": "#000000", + "editorForeground": "#FFFFFF" + } +} \ No newline at end of file diff --git a/extensions/theme-defaults/themes/light_defaults.json b/extensions/theme-defaults/themes/light_defaults.json new file mode 100644 index 00000000000..afe33ce8164 --- /dev/null +++ b/extensions/theme-defaults/themes/light_defaults.json @@ -0,0 +1,8 @@ +{ + "$schema": "vscode://schemas/color-theme", + "name": "Light Default Colors", + "colors": { + "editorBackground": "#ffffff", + "editorForeground": "#000000" + } +} \ No newline at end of file diff --git a/extensions/theme-defaults/themes/light_plus.json b/extensions/theme-defaults/themes/light_plus.json index f7a9e902b0f..51fe8b5accd 100644 --- a/extensions/theme-defaults/themes/light_plus.json +++ b/extensions/theme-defaults/themes/light_plus.json @@ -1,13 +1,13 @@ { - "name": "Light+", + "$schema": "vscode://schemas/color-theme", + "name": "Light+ (default light)", "include": "./light_vs.json", - "settings": [ + "tokenColors": [ { "name": "Function declarations", "scope": [ "entity.name.function", "support.function", - "support.constant.handlebars" ], "settings": { @@ -22,12 +22,10 @@ "support.type", "entity.name.type", "entity.name.class", - "storage.type.cs", "storage.type.generic.cs", "storage.type.modifier.cs", "storage.type.variable.cs", - "storage.type.annotation.java", "storage.type.generic.java", "storage.type.java", @@ -35,7 +33,6 @@ "storage.type.primitive.array.java", "storage.type.primitive.java", "storage.type.token.java", - "storage.type.groovy", "storage.type.annotation.groovy", "storage.type.parameters.groovy", @@ -57,7 +54,6 @@ "support.constant.math", "support.constant.dom", "support.constant.json", - "entity.other.inherited-class" ], "settings": { diff --git a/extensions/theme-defaults/themes/light_vs.json b/extensions/theme-defaults/themes/light_vs.json index 475453e404e..4c3161f434a 100644 --- a/extensions/theme-defaults/themes/light_vs.json +++ b/extensions/theme-defaults/themes/light_vs.json @@ -1,6 +1,8 @@ { - "name": "Light Visual Studio", - "settings": [ + "$schema": "vscode://schemas/color-theme", + "name": "Light (Visual Studio)", + "include": "./light_defaults.json", + "tokenColors": [ { "scope": "emphasis", "settings": { @@ -19,14 +21,12 @@ "foreground": "#000080" } }, - { "scope": "comment", "settings": { "foreground": "#008000" } }, - { "scope": "constant.language", "settings": { @@ -74,9 +74,7 @@ "entity.other.attribute-name.parent-selector.css", "entity.other.attribute-name.pseudo-class.css", "entity.other.attribute-name.pseudo-element.css", - "source.css.less entity.other.attribute-name.id", - "entity.other.attribute-name.attribute.scss", "entity.other.attribute-name.scss" ], @@ -101,7 +99,6 @@ "settings": { "fontStyle": "bold", "foreground": "#000080" - } }, { @@ -213,24 +210,19 @@ }, { "scope": [ - "string.comment.buffered.block.jade", "string.quoted.jade", "string.interpolated.jade", - "string.unquoted.plain.in.yaml", "string.unquoted.plain.out.yaml", "string.unquoted.block.yaml", "string.quoted.single.yaml", - "string.quoted.double.xml", "string.quoted.single.xml", "string.unquoted.cdata.xml", - "string.quoted.double.html", "string.quoted.single.html", "string.unquoted.html", - "string.quoted.single.handlebars", "string.quoted.double.handlebars" ], @@ -275,7 +267,6 @@ "variable.css", "variable.scss", "variable.other.less" - ], "settings": { "foreground": "#ff0000" @@ -306,7 +297,10 @@ } }, { - "scope": ["keyword.operator.new", "keyword.operator.expression"], + "scope": [ + "keyword.operator.new", + "keyword.operator.expression" + ], "settings": { "foreground": "#0000ff" } @@ -340,7 +334,10 @@ }, { "name": "coloring of the Java import and package identifiers", - "scope": ["storage.modifier.import.java", "storage.modifier.package.java"], + "scope": [ + "storage.modifier.import.java", + "storage.modifier.package.java" + ], "settings": { "foreground": "#000000" } diff --git a/src/vs/workbench/services/themes/common/colorThemeSchema.ts b/src/vs/workbench/services/themes/common/colorThemeSchema.ts index 6ca76697270..bace23782c2 100644 --- a/src/vs/workbench/services/themes/common/colorThemeSchema.ts +++ b/src/vs/workbench/services/themes/common/colorThemeSchema.ts @@ -119,7 +119,7 @@ const schema: IJSONSchema = { type: 'object', properties: { colors: themingRegistry.getColorSchema(), - syntaxTokens: { + tokenColors: { type: 'array', description: nls.localize('schema.colors', 'Colors for syntax highlighting'), items: { diff --git a/src/vs/workbench/services/themes/electron-browser/colorThemeData.ts b/src/vs/workbench/services/themes/electron-browser/colorThemeData.ts index 74c615e437b..0f8476885b3 100644 --- a/src/vs/workbench/services/themes/electron-browser/colorThemeData.ts +++ b/src/vs/workbench/services/themes/electron-browser/colorThemeData.ts @@ -7,7 +7,7 @@ import Paths = require('vs/base/common/paths'); import Json = require('vs/base/common/json'); import { Color } from 'vs/base/common/color'; import { ExtensionData, ITokenColorizationRule, IColorTheme, IColorMap } from 'vs/workbench/services/themes/common/themeService'; -import { initializeColorMapsFromSettings, generateStyleSheetContent } from 'vs/workbench/services/themes/electron-browser/stylesContributions'; +import { convertSettings, generateStyleSheetContent } from 'vs/workbench/services/themes/electron-browser/stylesContributions'; import { TPromise } from 'vs/base/common/winjs.base'; import { getBaseThemeId, getSyntaxThemeId, isDarkTheme, isLightTheme } from 'vs/platform/theme/common/themes'; import nls = require('vs/nls'); @@ -46,6 +46,17 @@ export class ColorThemeData implements IColorTheme { return TPromise.as(null); } + toThemeFile() { + if (!this.isLoaded) { + return ''; + } + let content = { name: this.label, colors: {}, tokenColors: this.tokenColors }; + for (let key in this.colorMap) { + content.colors[key] = this.colorMap[key].toRGBAHex(true); + } + return JSON.stringify(content, null, '\t'); + } + isLightTheme() { return isLightTheme(this.id); } @@ -86,8 +97,10 @@ let defaultThemeColors: { [baseTheme: string]: ITokenColorizationRule[] } = { function _loadThemeDocument(baseTheme: string, themePath: string, resultRules: ITokenColorizationRule[], resultColors: IColorMap): TPromise { return pfs.readFile(themePath).then(content => { - let defaultRules = defaultThemeColors[baseTheme] || []; - resultRules.push(...defaultRules); + if (resultRules.length === 0) { + let defaultRules = defaultThemeColors[baseTheme] || []; + resultRules.push(...defaultRules); + } if (Paths.extname(themePath) === '.json') { let errors: Json.ParseError[] = []; let contentValue = Json.parse(content.toString(), errors); @@ -101,14 +114,13 @@ function _loadThemeDocument(baseTheme: string, themePath: string, resultRules: I return includeCompletes.then(_ => { if (Array.isArray(contentValue.settings)) { // legacy information - resultRules.push(...contentValue.settings); - initializeColorMapsFromSettings(contentValue.settings, resultColors); + convertSettings(contentValue.settings, resultRules, resultColors); } else { - if (!Array.isArray(contentValue.syntaxTokens) && typeof contentValue.colors !== 'object') { - return TPromise.wrapError(new Error(nls.localize({ key: 'error.invalidformat', comment: ['{0} will be replaced by a path. Values in quotes should not be translated.'] }, "Problem parsing JSON theme file: {0}. Expecting 'syntaxTokens' and 'colors'."))); + if (!Array.isArray(contentValue.tokenColors) && typeof contentValue.colors !== 'object') { + return TPromise.wrapError(new Error(nls.localize({ key: 'error.invalidformat', comment: ['{0} will be replaced by a path. Values in quotes should not be translated.'] }, "Problem parsing JSON theme file: {0}. Expecting 'tokenColors' and 'colors'.", themePath))); } - if (contentValue.syntaxTokens) { - resultRules.push(...contentValue.syntaxTokens); + if (contentValue.tokenColors) { + resultRules.push(...contentValue.tokenColors); } if (contentValue.colors) { for (let colorId in contentValue.colors) { @@ -126,11 +138,12 @@ function _loadThemeDocument(baseTheme: string, themePath: string, resultRules: I if (!Array.isArray(settings)) { return TPromise.wrapError(new Error(nls.localize('error.plist.invalidformat', "Problem parsing theme file: {0}. 'settings' is not array."))); } - resultRules.push(...settings); - initializeColorMapsFromSettings(settings, resultColors); + convertSettings(settings, resultRules, resultColors); return TPromise.as(null); } catch (e) { return TPromise.wrapError(new Error(nls.localize('error.cannotparse', "Problems parsing theme file: {0}", e.message))); } + }, error => { + return TPromise.wrapError(new Error(nls.localize('error.cannotload', "Problems loading theme file {0}: {1}", themePath, error.message))); }); } diff --git a/src/vs/workbench/services/themes/electron-browser/stylesContributions.ts b/src/vs/workbench/services/themes/electron-browser/stylesContributions.ts index 2111343210f..800ed9947e4 100644 --- a/src/vs/workbench/services/themes/electron-browser/stylesContributions.ts +++ b/src/vs/workbench/services/themes/electron-browser/stylesContributions.ts @@ -29,8 +29,9 @@ function addSettingMapping(settingId: string, colorId: string) { colorIds.push(colorId); } -export function initializeColorMapsFromSettings(resultRules: ITokenColorizationRule[], resultColors: IColorMap): void { - for (let rule of resultRules) { +export function convertSettings(oldSettings: ITokenColorizationRule[], resultRules: ITokenColorizationRule[], resultColors: IColorMap): void { + for (let rule of oldSettings) { + resultRules.push(rule); if (!rule.scope) { let settings = rule.settings; for (let key in settings) { @@ -41,6 +42,9 @@ export function initializeColorMapsFromSettings(resultRules: ITokenColorizationR resultColors[colorId] = color; } } + if (key !== 'foreground' && key !== 'background') { + delete settings[key]; + } } } } diff --git a/src/vs/workbench/services/themes/electron-browser/themeService.ts b/src/vs/workbench/services/themes/electron-browser/themeService.ts index 6f4126ca6d9..1471fb9f34d 100644 --- a/src/vs/workbench/services/themes/electron-browser/themeService.ts +++ b/src/vs/workbench/services/themes/electron-browser/themeService.ts @@ -835,7 +835,7 @@ function applyTheme(theme: ColorThemeData, onApply: (theme: ColorThemeData) => T _applyRules(theme.styleSheetContent, colorThemeRulesClassName); return onApply(theme); }, error => { - return TPromise.wrapError(nls.localize('error.cannotloadtheme', "Unable to load {0}", theme.path)); + return TPromise.wrapError(nls.localize('error.cannotloadtheme', "Unable to load {0}: {1}", theme.path, error.message)); }); }