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

Allow themes to be defined in JSON

上级 2fbdbe80
......@@ -11,12 +11,12 @@
{
"label": "Dark+ (default dark)",
"uiTheme": "vs-dark",
"path": "./themes/dark_plus.tmTheme"
"path": "./themes/dark_plus.json"
},
{
"label": "Light+ (default light)",
"uiTheme": "vs",
"path": "./themes/light_plus.tmTheme"
"path": "./themes/light_plus.json"
}
]
}
......
{
"name": "Dark+",
"settings": [
{
"name": "Types declaration and references",
"scope": ["meta.type.name", "meta.return.type", "meta.return-type", "meta.cast", "meta.type.annotation",
"support.type", "entity.name.class", "entity.name.type", "storage.type.cs", "storage.type.java"],
"settings": {
"foreground": "#4EC9B0"
}
},
{
"name": "Function declarations",
"scope": ["entity.name.function", "entity.method.name"],
"settings": {
"foreground": "#DCDCAA"
}
},
{
"name": "Control flow keywords",
"scope": "keyword.control",
"settings": {
"foreground": "#C586C0"
}
},
{
"name": "Variable and parameter name",
"scope": ["meta.parameter.type.variable", "variable.parameter", "variable", "variable.name"],
"settings": {
"foreground": "#9CDCFE"
}
},
{
"name": "C includes",
"scope": "keyword.control.import",
"settings": {
"foreground": "#569CD6"
}
},
{
"name": "CSS property value",
"scope": ["css.support.property-value", "css.constant.rgb-value"],
"settings": {
"foreground": "#CE9178"
}
},
{
"name": "JSON keys",
"scope": "support.type.property-name",
"settings": {
"foreground": "#9CDCFE"
}
},
{
"name": "LESS workaround",
"scope": "keyword.control.less",
"settings": {
"foreground": "#D7BA7D"
}
}
]
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Dark+</string>
<key>settings</key>
<array>
<dict>
<key>name</key>
<string>Types declaration and references</string>
<key>scope</key>
<string>meta.type.name, meta.return.type, meta.return-type, meta.cast, meta.type.annotation, support.type, entity.name.class, entity.name.type,
storage.type.cs, storage.type.java
</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#4EC9B0</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Function declarations</string>
<key>scope</key>
<string>entity.name.function, entity.method.name</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#DCDCAA</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Control flow keywords</string>
<key>scope</key>
<string>keyword.control</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#C586C0</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Variable and parameter name</string>
<key>scope</key>
<string>meta.parameter.type.variable, variable.parameter, variable, variable.name</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#9CDCFE</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>C includes</string>
<key>scope</key>
<string>keyword.control.import</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#569CD6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>CSS property value</string>
<key>scope</key>
<string>css.support.property-value, css.constant.rgb-value</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#CE9178</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>JSON keys</string>
<key>scope</key>
<string>support.type.property-name</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#9CDCFE</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>LESS workaround</string>
<key>scope</key>
<string>keyword.control.less</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#D7BA7D</string>
</dict>
</dict>
</array>
</dict>
</plist>
{
"name": "Light+",
"settings": [
{
"name": "Types declaration and references",
"scope": ["meta.type.name", "meta.return.type", "meta.return-type", "meta.cast", "meta.type.annotation",
"support.type", "entity.name.class", "entity.name.type", "storage.type.cs", "storage.type.java"],
"settings": {
"foreground": "#267f99"
}
},
{
"name": "Function declarations",
"scope": ["entity.name.function", "entity.method.name"],
"settings": {
"foreground": "#795E26"
}
},
{
"name": "Control flow keywords",
"scope": "keyword.control",
"settings": {
"foreground": "#AF00DB"
}
},
{
"name": "Parameter name",
"scope": ["meta.parameter.type.variable", "variable.parameter", "variable", "variable.name"],
"settings": {
"foreground": "#001080"
}
},
{
"name": "C includes must match meta.preprocessor",
"scope": "keyword.control.import",
"settings": {
"foreground": "#0000FF"
}
},
{
"name": "CSS keys",
"scope": ["support.type.property-name.css", "support.type.property-name.less", "support.type.property-name.sass"],
"settings": {
"foreground": "#FF0000"
}
},
{
"name": "JSON keys",
"scope": "support.type.property-name",
"settings": {
"foreground": "#0451A5"
}
},
{
"name": "LESS workaround",
"scope": "keyword.control.less",
"settings": {
"foreground": "#800000"
}
}
]
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Light+</string>
<key>settings</key>
<array>
<dict>
<key>name</key>
<string>Types declaration and references</string>
<key>scope</key>
<string>meta.type.name, meta.return.type, meta.return-type, meta.cast, meta.type.annotation, support.type, entity.name.class, entity.name.type,
storage.type.cs, storage.type.java
</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#267f99</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Function declarations</string>
<key>scope</key>
<string>entity.name.function, entity.method.name</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#795E26</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Control flow keywords</string>
<key>scope</key>
<string>keyword.control</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#AF00DB</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Parameter name</string>
<key>scope</key>
<string>meta.parameter.type.variable, variable.parameter, variable, variable.name</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#001080</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>C includes must match meta.preprocessor</string>
<key>scope</key>
<string>keyword.control.import</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#0000FF</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>CSS keys</string>
<key>scope</key>
<string>support.type.property-name.css, support.type.property-name.less, support.type.property-name.sass</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#FF0000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>JSON keys</string>
<key>scope</key>
<string>support.type.property-name</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#0451A5</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>LESS workaround</string>
<key>scope</key>
<string>keyword.control.less</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#800000</string>
</dict>
</dict>
</array>
</dict>
</plist>
......@@ -7,6 +7,7 @@
import {TPromise} from 'vs/base/common/winjs.base';
import nls = require('vs/nls');
import Paths = require('vs/base/common/paths');
import Json = require('vs/base/common/json');
import Themes = require('vs/platform/theme/common/themes');
import {IThemeExtensionPoint} from 'vs/platform/theme/common/themeExtensionPoint';
import {IExtensionService} from 'vs/platform/extensions/common/extensions';
......@@ -130,11 +131,21 @@ function applyTheme(theme: IThemeData): TPromise<boolean> {
}
return pfs.readFile(theme.path).then(content => {
let parseResult = plist.parse(content.toString());
if (parseResult.errors && parseResult.errors.length) {
return TPromise.wrapError(new Error(nls.localize('error.cannotparse', "Problems parsing plist file: {0}", parseResult.errors.join(', '))));
let contentValue: any;
if (Paths.extname(theme.path) === '.json') {
let errors: string[] = [];
contentValue = Json.parse(content.toString(), errors);
if (errors.length > 0) {
return TPromise.wrapError(new Error(nls.localize('error.cannotparsejson', "Problems parsing json file: {0}", errors.join(', '))));
}
} else {
let parseResult = plist.parse(content.toString());
if (parseResult.errors && parseResult.errors.length) {
return TPromise.wrapError(new Error(nls.localize('error.cannotparse', "Problems parsing plist file: {0}", parseResult.errors.join(', '))));
}
contentValue = parseResult.value;
}
let styleSheetContent = _processThemeObject(theme.id, parseResult.value);
let styleSheetContent = _processThemeObject(theme.id, contentValue);
theme.styleSheetContent = styleSheetContent;
_applyRules(styleSheetContent);
return true;
......@@ -163,10 +174,10 @@ function _processThemeObject(themeId: string, themeDocument: any): string {
if (index === 0 && !s.scope) {
editorSettings = s.settings;
} else {
let scope: string = s.scope;
let scope: string | string[] = s.scope;
let settings: string = s.settings;
if (scope && settings) {
let rules = scope.split(',');
let rules = Array.isArray(scope) ? <string[]> scope : scope.split(',');
let statements = _settingsToStatements(settings);
rules.forEach(rule => {
rule = rule.trim().replace(/ /g, '.'); // until we have scope hierarchy in the editor dom: replace spaces with .
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册