提交 8ad8151a 编写于 作者: M Martin Aeschlimann

[themes] convert default themes to new format

上级 f9f4e583
......@@ -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'));
......
{
"$schema": "vscode://schemas/color-theme",
"name": "Dark Default Colors",
"colors": {
"editorBackground": "#1e1e1e",
"editorForeground": "#D4D4D4"
}
}
\ No newline at end of file
{
"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": {
......
{
"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"
}
......
{
"name": "Dark Visual Studio",
"$schema": "vscode://schemas/color-theme",
"name": "Dark High Contrast",
"include": "./hc_black_defaults.json",
"settings": [
{
"settings": {
......
{
"$schema": "vscode://schemas/color-theme",
"name": "High Contrast Default Colors",
"colors": {
"editorBackground": "#000000",
"editorForeground": "#FFFFFF"
}
}
\ No newline at end of file
{
"$schema": "vscode://schemas/color-theme",
"name": "Light Default Colors",
"colors": {
"editorBackground": "#ffffff",
"editorForeground": "#000000"
}
}
\ No newline at end of file
{
"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": {
......
{
"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"
}
......
......@@ -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: {
......
......@@ -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<any> {
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)));
});
}
......@@ -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];
}
}
}
}
......
......@@ -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));
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册