Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: allow unsetting color theme values in settings #14

Closed
wants to merge 16 commits into from
13 changes: 11 additions & 2 deletions src/vs/platform/theme/common/colorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { IJSONSchema, IJSONSchemaMap } from 'vs/base/common/jsonSchema';
import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
import * as platform from 'vs/platform/registry/common/platform';
import { IColorTheme } from 'vs/platform/theme/common/themeService';
import * as nls from 'vs/nls';

// ------ API types

Expand Down Expand Up @@ -79,6 +80,8 @@ export const Extensions = {
ColorContribution: 'base.contributions.colors'
};

export const DEFAULT_COLOR_CONFIG_VALUE = 'default';

export interface IColorRegistry {

readonly onDidChangeSchema: Event<void>;
Expand Down Expand Up @@ -141,9 +144,14 @@ class ColorRegistry implements IColorRegistry {
}
if (needsTransparency) {
propertySchema.pattern = '^#(?:(?<rgba>[0-9a-fA-f]{3}[0-9a-eA-E])|(?:[0-9a-fA-F]{6}(?:(?![fF]{2})(?:[0-9a-fA-F]{2}))))?$';
propertySchema.patternErrorMessage = 'This color must be transparent or it will obscure content';
propertySchema.patternErrorMessage = nls.localize('transparecyRequired', 'This color must be transparent or it will obscure content');
}
this.colorSchema.properties[id] = propertySchema;
this.colorSchema.properties[id] = {
oneOf: [
propertySchema,
{ type: 'string', const: DEFAULT_COLOR_CONFIG_VALUE, description: nls.localize('useDefault', 'Use the default color.') }
]
};
this.colorReferenceSchema.enum.push(id);
this.colorReferenceSchema.enumDescriptions.push(description);

Expand Down Expand Up @@ -319,6 +327,7 @@ const schemaRegistry = platform.Registry.as<IJSONContributionRegistry>(JSONExten
schemaRegistry.registerSchema(workbenchColorsSchemaId, colorRegistry.getColorSchema());

const delayer = new RunOnceScheduler(() => schemaRegistry.notifySchemaChanged(workbenchColorsSchemaId), 200);

colorRegistry.onDidChangeSchema(() => {
if (!delayer.isScheduled()) {
delayer.schedule();
Expand Down
12 changes: 8 additions & 4 deletions src/vs/workbench/services/themes/common/colorThemeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { convertSettings } from 'vs/workbench/services/themes/common/themeCompat
import * as nls from 'vs/nls';
import * as types from 'vs/base/common/types';
import * as resources from 'vs/base/common/resources';
import { Extensions as ColorRegistryExtensions, IColorRegistry, ColorIdentifier, editorBackground, editorForeground } from 'vs/platform/theme/common/colorRegistry';
import { Extensions as ColorRegistryExtensions, IColorRegistry, ColorIdentifier, editorBackground, editorForeground, DEFAULT_COLOR_CONFIG_VALUE } from 'vs/platform/theme/common/colorRegistry';
import { ITokenStyle, getThemeTypeSelector } from 'vs/platform/theme/common/themeService';
import { Registry } from 'vs/platform/registry/common/platform';
import { getParseErrorMessage } from 'vs/base/common/jsonErrorMessages';
Expand Down Expand Up @@ -372,7 +372,9 @@ export class ColorThemeData implements IWorkbenchColorTheme {
private overwriteCustomColors(colors: IColorCustomizations) {
for (const id in colors) {
const colorVal = colors[id];
if (typeof colorVal === 'string') {
if (colorVal === DEFAULT_COLOR_CONFIG_VALUE) {
delete this.colorMap[id];
} else if (typeof colorVal === 'string') {
this.customColorMap[id] = Color.fromHex(colorVal);
}
}
Expand Down Expand Up @@ -716,8 +718,10 @@ async function _loadColorTheme(extensionResourceLoaderService: IExtensionResourc
}
// new JSON color themes format
for (const colorId in colors) {
const colorHex = colors[colorId];
if (typeof colorHex === 'string') { // ignore colors tht are null
const colorVal = colors[colorId];
if (colorVal === DEFAULT_COLOR_CONFIG_VALUE) {
delete result.colors[colorId];
} else if (typeof colorVal === 'string') { // ignore colors that are null
result.colors[colorId] = Color.fromHex(colors[colorId]);
}
}
Expand Down
Loading