提交 1eb82782 编写于 作者: M Martin Aeschlimann

[theme] add color theme schema

上级 49b27148
......@@ -35,6 +35,10 @@
{
"fileMatch": "*icon-theme.json",
"url": "vscode://schemas/icon-theme"
},
{
"fileMatch": "*color-theme.json",
"url": "vscode://schemas/color-theme"
}
]
},
......
......@@ -6,21 +6,17 @@
import platform = require('vs/platform/platform');
import { Color } from 'vs/base/common/color';
import { IJSONSchema } from 'vs/base/common/jsonSchema';
import nls = require('vs/nls');
export const Extensions = {
ThemingContribution: 'base.contributions.theming'
};
export interface IColorContribution {
id: string;
description: string;
defaults?: IColorDefaults;
}
export interface IColorDefaults {
light: Color;
dark: Color;
highContrast: Color;
readonly id: string;
readonly description: string;
}
export interface ITheme {
......@@ -37,13 +33,18 @@ export interface IThemingRegistry {
/**
* Register a color to the registry.
*/
registerColor(id: string, description: string, defaults?: IColorDefaults): void;
registerColor(id: string, description: string): IColorContribution;
/**
* Get all color contributions
*/
getColors(): IColorContribution[];
/**
* JSON schema of all colors
*/
getColorSchema(): IJSONSchema;
/**
* Register a theming participant to the registry.
*/
......@@ -60,20 +61,28 @@ export interface IThemingRegistry {
class ThemingRegistry implements IThemingRegistry {
private colorsById: { [key: string]: IColorContribution };
private themingParticipants: IThemingParticipant[];
private colorSchema: IJSONSchema = { type: 'object', description: nls.localize('schema.colors', 'Colors used in the workbench.'), properties: {} };
constructor() {
this.colorsById = {};
this.themingParticipants = [];
}
public registerColor(id: string, description: string, defaults?: IColorDefaults): void {
this.colorsById[id] = { id, description, defaults };
public registerColor(id: string, description: string): IColorContribution {
let colorContribution: IColorContribution = { id, description };
this.colorsById[id] = colorContribution;
this.colorSchema.properties[id] = { type: 'string', description };
return colorContribution;
}
public getColors(): IColorContribution[] {
return Object.keys(this.colorsById).map(id => this.colorsById[id]);
}
public getColorSchema(): IJSONSchema {
return this.colorSchema;
}
public registerThemingParticipant(participant: IThemingParticipant): void {
this.themingParticipants.push(participant);
}
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import nls = require('vs/nls');
import { Registry } from 'vs/platform/platform';
import { Extensions as JSONExtensions, IJSONContributionRegistry } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
import { IJSONSchema } from 'vs/base/common/jsonSchema';
import { Extensions as ThemeingExtensions, IThemingRegistry } from 'vs/platform/theme/common/themingRegistry';
let themingRegistry = <IThemingRegistry>Registry.as(ThemeingExtensions.ThemingContribution);
let textMateScopes = [
'comment',
'comment.block',
'comment.block.documentation',
'comment.line',
'constant',
'constant.character',
'constant.character.escape',
'constant.numeric',
'constant.numeric.integer',
'constant.numeric.float',
'constant.numeric.hex',
'constant.numeric.octal',
'constant.other',
'constant.regexp',
'constant.rgb-value',
'emphasis',
'entity',
'entity.name',
'entity.name.class',
'entity.name.function',
'entity.name.method',
'entity.name.section',
'entity.name.selector',
'entity.name.tag',
'entity.name.type',
'entity.other',
'entity.other.attribute-name',
'entity.other.inherited-class',
'invalid',
'invalid.deprecated',
'invalid.illegal',
'keyword',
'keyword.control',
'keyword.operator',
'keyword.operator.new',
'keyword.operator.assignment',
'keyword.operator.arithmetic',
'keyword.operator.logical',
'keyword.other',
'markup',
'markup.bold',
'markup.changed',
'markup.deleted',
'markup.heading',
'markup.inline.raw',
'markup.inserted',
'markup.italic',
'markup.list',
'markup.list.numbered',
'markup.list.unnumbered',
'markup.other',
'markup.quote',
'markup.raw',
'markup.underline',
'markup.underline.link',
'meta',
'meta.block',
'meta.cast',
'meta.class',
'meta.function',
'meta.function-call',
'meta.preprocessor',
'meta.return-type',
'meta.selector',
'meta.tag',
'meta.type.annotation',
'meta.type',
'punctuation.definition.string.begin',
'punctuation.definition.string.end',
'punctuation.separator',
'punctuation.separator.continuation',
'punctuation.terminator',
'storage',
'storage.modifier',
'storage.type',
'string',
'string.interpolated',
'string.other',
'string.quoted',
'string.quoted.double',
'string.quoted.other',
'string.quoted.single',
'string.quoted.triple',
'string.regexp',
'string.unquoted',
'strong',
'support',
'support.class',
'support.constant',
'support.function',
'support.other',
'support.type',
'support.type.property-name',
'support.variable',
'variable',
'variable.language',
'variable.name',
'variable.other',
'variable.other.readwrite',
'variable.parameter'
];
const schemaId = 'vscode://schemas/color-theme';
const schema: IJSONSchema = {
type: 'object',
properties: {
colors: themingRegistry.getColorSchema(),
syntaxTokens: {
type: 'array',
description: nls.localize('schema.colors', 'Colors for syntax highlighting'),
items: {
type: 'object',
properties: {
name: {
type: 'string',
description: nls.localize('schema.properties.name', 'Description of the rule')
},
scope: {
anyOf: [
{
enum: textMateScopes
},
{
type: 'string'
},
{
type: 'array',
items: {
enum: textMateScopes
}
},
{
type: 'array',
items: {
type: 'string'
}
}
]
},
settings: {
type: 'object',
properties: {
foreground: {
type: 'string'
},
background: {
type: 'string'
},
fontStyle: {
type: 'string',
description: nls.localize('schema.fontStyle', 'Font style of the rule: One or a combination of \'italic\', \'bold\' and \'underline\'')
}
}
}
}
}
}
}
};
export function register() {
let schemaRegistry = <IJSONContributionRegistry>Registry.as(JSONExtensions.JSONContribution);
schemaRegistry.registerSchema(schemaId, schema);
}
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import nls = require('vs/nls');
import { Registry } from 'vs/platform/platform';
import { Extensions as JSONExtensions, IJSONContributionRegistry } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
import { IJSONSchema } from 'vs/base/common/jsonSchema';
const schemaId = 'vscode://schemas/icon-theme';
const schema: IJSONSchema = {
type: 'object',
definitions: {
folderExpanded: {
type: 'string',
description: nls.localize('schema.folderExpanded', 'The folder icon for expanded folders. The expanded folder icon is optional. If not set, the icon defined for folder will be shown.')
},
folder: {
type: 'string',
description: nls.localize('schema.folder', 'The folder icon for collapsed folders, and if folderExpanded is not set, also for expanded folders.')
},
file: {
type: 'string',
description: nls.localize('schema.file', 'The default file icon, shown for all files that don\'t match any extension, filename or language id.')
},
folderNames: {
type: 'object',
description: nls.localize('schema.folderNames', 'Associates folder names to icons. The object key is is the folder name, not including any path segments. No patterns or wildcards are allowed. Folder name matching is case insensitive.'),
additionalProperties: {
type: 'string',
description: nls.localize('schema.folderName', 'The ID of the icon definition for the association.')
}
},
folderNamesExpanded: {
type: 'object',
description: nls.localize('schema.folderNamesExpanded', 'Associates folder names to icons for expanded folders. The object key is is the folder name, not including any path segments. No patterns or wildcards are allowed. Folder name matching is case insensitive.'),
additionalProperties: {
type: 'string',
description: nls.localize('schema.folderNameExpanded', 'The ID of the icon definition for the association.')
}
},
fileExtensions: {
type: 'object',
description: nls.localize('schema.fileExtensions', 'Associates file extensions to icons. The object key is is the file extension name. The extension name is the last segment of a file name after the last dot (not including the dot). Extensions are compared case insensitive.'),
additionalProperties: {
type: 'string',
description: nls.localize('schema.fileExtension', 'The ID of the icon definition for the association.')
}
},
fileNames: {
type: 'object',
description: nls.localize('schema.fileNames', 'Associates file names to icons. The object key is is the full file name, but not including any path segments. File name can include dots and a possible file extension. No patterns or wildcards are allowed. File name matching is case insensitive.'),
additionalProperties: {
type: 'string',
description: nls.localize('schema.fileName', 'The ID of the icon definition for the association.')
}
},
languageIds: {
type: 'object',
description: nls.localize('schema.languageIds', 'Associates languages to icons. The object key is the language id as defined in the language contribution point.'),
additionalProperties: {
type: 'string',
description: nls.localize('schema.languageId', 'The ID of the icon definition for the association.')
}
},
associations: {
type: 'object',
properties: {
folderExpanded: {
$ref: '#/definitions/folderExpanded'
},
folder: {
$ref: '#/definitions/folder'
},
file: {
$ref: '#/definitions/file'
},
folderNames: {
$ref: '#/definitions/folderNames'
},
folderNamesExpanded: {
$ref: '#/definitions/folderNamesExpanded'
},
fileExtensions: {
$ref: '#/definitions/fileExtensions'
},
fileNames: {
$ref: '#/definitions/fileNames'
},
languageIds: {
$ref: '#/definitions/languageIds'
}
}
}
},
properties: {
fonts: {
type: 'array',
description: nls.localize('schema.fonts', 'Fonts that are used in the icon definitions.'),
items: {
type: 'object',
properties: {
id: {
type: 'string',
description: nls.localize('schema.id', 'The ID of the font.')
},
src: {
type: 'array',
description: nls.localize('schema.src', 'The locations of the font.'),
items: {
type: 'object',
properties: {
path: {
type: 'string',
description: nls.localize('schema.font-path', 'The font path, relative to the current icon theme file.'),
},
format: {
type: 'string',
description: nls.localize('schema.font-format', 'The format of the font.')
}
},
required: [
'path',
'format'
]
}
},
weight: {
type: 'string',
description: nls.localize('schema.font-weight', 'The weight of the font.')
},
style: {
type: 'string',
description: nls.localize('schema.font-sstyle', 'The style of the font.')
},
size: {
type: 'string',
description: nls.localize('schema.font-size', 'The default size of the font.')
}
},
required: [
'id',
'src'
]
}
},
iconDefinitions: {
type: 'object',
description: nls.localize('schema.iconDefinitions', 'Description of all icons that can be used when associating files to icons.'),
additionalProperties: {
type: 'object',
description: nls.localize('schema.iconDefinition', 'An icon definition. The object key is the ID of the definition.'),
properties: {
iconPath: {
type: 'string',
description: nls.localize('schema.iconPath', 'When using a SVG or PNG: The path to the image. The path is relative to the icon set file.')
},
fontCharacter: {
type: 'string',
description: nls.localize('schema.fontCharacter', 'When using a glyph font: The character in the font to use.')
},
fontColor: {
type: 'string',
description: nls.localize('schema.fontColor', 'When using a glyph font: The color to use.')
},
fontSize: {
type: 'string',
description: nls.localize('schema.fontSize', 'When using a font: The font size in percentage to the text font. If not set, defaults to the size in the font definition.')
},
fontId: {
type: 'string',
description: nls.localize('schema.fontId', 'When using a font: The id of the font. If not set, defaults to the first font definition.')
}
}
}
},
folderExpanded: {
$ref: '#/definitions/folderExpanded'
},
folder: {
$ref: '#/definitions/folder'
},
file: {
$ref: '#/definitions/file'
},
folderNames: {
$ref: '#/definitions/folderNames'
},
fileExtensions: {
$ref: '#/definitions/fileExtensions'
},
fileNames: {
$ref: '#/definitions/fileNames'
},
languageIds: {
$ref: '#/definitions/languageIds'
},
light: {
$ref: '#/definitions/associations',
description: nls.localize('schema.light', 'Optional associations for file icons in light color themes.')
},
highContrast: {
$ref: '#/definitions/associations',
description: nls.localize('schema.highContrast', 'Optional associations for file icons in high contrast color themes.')
}
}
};
export function register() {
let schemaRegistry = <IJSONContributionRegistry>Registry.as(JSONExtensions.JSONContribution);
schemaRegistry.registerSchema(schemaId, schema);
}
\ No newline at end of file
......@@ -19,8 +19,6 @@ export const VS_HC_THEME = 'hc-black';
export const COLOR_THEME_SETTING = 'workbench.colorTheme';
export const ICON_THEME_SETTING = 'workbench.iconTheme';
export interface IColorTheme {
readonly id: string;
readonly label: string;
......
......@@ -17,7 +17,6 @@ import { IWindowIPCService } from 'vs/workbench/services/window/electron-browser
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { Registry } from 'vs/platform/platform';
import { Extensions as JSONExtensions, IJSONContributionRegistry } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
import { IJSONSchema } from 'vs/base/common/jsonSchema';
import errors = require('vs/base/common/errors');
import { IConfigurationEditingService, ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing';
......@@ -36,6 +35,10 @@ import Event, { Emitter } from 'vs/base/common/event';
import pfs = require('vs/base/node/pfs');
import colorThemeSchema = require('vs/workbench/services/themes/common/colorThemeSchema');
import fileIconThemeSchema = require('vs/workbench/services/themes/common/fileIconThemeSchema');
// implementation
const DEFAULT_THEME_ID = 'vs-dark vscode-theme-defaults-themes-dark_plus-json';
......@@ -853,212 +856,8 @@ function _applyRules(styleSheetContent: string, rulesClassName: string) {
}
}
const schemaId = 'vscode://schemas/icon-theme';
const schema: IJSONSchema = {
type: 'object',
definitions: {
folderExpanded: {
type: 'string',
description: nls.localize('schema.folderExpanded', 'The folder icon for expanded folders. The expanded folder icon is optional. If not set, the icon defined for folder will be shown.')
},
folder: {
type: 'string',
description: nls.localize('schema.folder', 'The folder icon for collapsed folders, and if folderExpanded is not set, also for expanded folders.')
},
file: {
type: 'string',
description: nls.localize('schema.file', 'The default file icon, shown for all files that don\'t match any extension, filename or language id.')
},
folderNames: {
type: 'object',
description: nls.localize('schema.folderNames', 'Associates folder names to icons. The object key is is the folder name, not including any path segments. No patterns or wildcards are allowed. Folder name matching is case insensitive.'),
additionalProperties: {
type: 'string',
description: nls.localize('schema.folderName', 'The ID of the icon definition for the association.')
}
},
folderNamesExpanded: {
type: 'object',
description: nls.localize('schema.folderNamesExpanded', 'Associates folder names to icons for expanded folders. The object key is is the folder name, not including any path segments. No patterns or wildcards are allowed. Folder name matching is case insensitive.'),
additionalProperties: {
type: 'string',
description: nls.localize('schema.folderNameExpanded', 'The ID of the icon definition for the association.')
}
},
fileExtensions: {
type: 'object',
description: nls.localize('schema.fileExtensions', 'Associates file extensions to icons. The object key is is the file extension name. The extension name is the last segment of a file name after the last dot (not including the dot). Extensions are compared case insensitive.'),
additionalProperties: {
type: 'string',
description: nls.localize('schema.fileExtension', 'The ID of the icon definition for the association.')
}
},
fileNames: {
type: 'object',
description: nls.localize('schema.fileNames', 'Associates file names to icons. The object key is is the full file name, but not including any path segments. File name can include dots and a possible file extension. No patterns or wildcards are allowed. File name matching is case insensitive.'),
additionalProperties: {
type: 'string',
description: nls.localize('schema.fileName', 'The ID of the icon definition for the association.')
}
},
languageIds: {
type: 'object',
description: nls.localize('schema.languageIds', 'Associates languages to icons. The object key is the language id as defined in the language contribution point.'),
additionalProperties: {
type: 'string',
description: nls.localize('schema.languageId', 'The ID of the icon definition for the association.')
}
},
associations: {
type: 'object',
properties: {
folderExpanded: {
$ref: '#/definitions/folderExpanded'
},
folder: {
$ref: '#/definitions/folder'
},
file: {
$ref: '#/definitions/file'
},
folderNames: {
$ref: '#/definitions/folderNames'
},
folderNamesExpanded: {
$ref: '#/definitions/folderNamesExpanded'
},
fileExtensions: {
$ref: '#/definitions/fileExtensions'
},
fileNames: {
$ref: '#/definitions/fileNames'
},
languageIds: {
$ref: '#/definitions/languageIds'
}
}
}
},
properties: {
fonts: {
type: 'array',
description: nls.localize('schema.fonts', 'Fonts that are used in the icon definitions.'),
items: {
type: 'object',
properties: {
id: {
type: 'string',
description: nls.localize('schema.id', 'The ID of the font.')
},
src: {
type: 'array',
description: nls.localize('schema.src', 'The locations of the font.'),
items: {
type: 'object',
properties: {
path: {
type: 'string',
description: nls.localize('schema.font-path', 'The font path, relative to the current icon theme file.'),
},
format: {
type: 'string',
description: nls.localize('schema.font-format', 'The format of the font.')
}
},
required: [
'path',
'format'
]
}
},
weight: {
type: 'string',
description: nls.localize('schema.font-weight', 'The weight of the font.')
},
style: {
type: 'string',
description: nls.localize('schema.font-sstyle', 'The style of the font.')
},
size: {
type: 'string',
description: nls.localize('schema.font-size', 'The default size of the font.')
}
},
required: [
'id',
'src'
]
}
},
iconDefinitions: {
type: 'object',
description: nls.localize('schema.iconDefinitions', 'Description of all icons that can be used when associating files to icons.'),
additionalProperties: {
type: 'object',
description: nls.localize('schema.iconDefinition', 'An icon definition. The object key is the ID of the definition.'),
properties: {
iconPath: {
type: 'string',
description: nls.localize('schema.iconPath', 'When using a SVG or PNG: The path to the image. The path is relative to the icon set file.')
},
fontCharacter: {
type: 'string',
description: nls.localize('schema.fontCharacter', 'When using a glyph font: The character in the font to use.')
},
fontColor: {
type: 'string',
description: nls.localize('schema.fontColor', 'When using a glyph font: The color to use.')
},
fontSize: {
type: 'string',
description: nls.localize('schema.fontSize', 'When using a font: The font size in percentage to the text font. If not set, defaults to the size in the font definition.')
},
fontId: {
type: 'string',
description: nls.localize('schema.fontId', 'When using a font: The id of the font. If not set, defaults to the first font definition.')
}
}
}
},
folderExpanded: {
$ref: '#/definitions/folderExpanded'
},
folder: {
$ref: '#/definitions/folder'
},
file: {
$ref: '#/definitions/file'
},
folderNames: {
$ref: '#/definitions/folderNames'
},
fileExtensions: {
$ref: '#/definitions/fileExtensions'
},
fileNames: {
$ref: '#/definitions/fileNames'
},
languageIds: {
$ref: '#/definitions/languageIds'
},
light: {
$ref: '#/definitions/associations',
description: nls.localize('schema.light', 'Optional associations for file icons in light color themes.')
},
highContrast: {
$ref: '#/definitions/associations',
description: nls.localize('schema.highContrast', 'Optional associations for file icons in high contrast color themes.')
}
}
};
let schemaRegistry = <IJSONContributionRegistry>Registry.as(JSONExtensions.JSONContribution);
schemaRegistry.registerSchema(schemaId, schema);
colorThemeSchema.register();
fileIconThemeSchema.register();
// Configuration: Themes
const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册