Skip to content

Commit

Permalink
polish color theme configuration (microsoft#210923)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschli authored and sergioengineer committed Apr 23, 2024
1 parent 8981143 commit 2edff46
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 31 deletions.
6 changes: 4 additions & 2 deletions src/vs/platform/theme/electron-main/themeMainService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const THEME_STORAGE_KEY = 'theme';
const THEME_BG_STORAGE_KEY = 'themeBackground';
const THEME_WINDOW_SPLASH = 'windowSplash';

const SYSTEM_COLOR_THEME = 'window.systemColorTheme';

export const IThemeMainService = createDecorator<IThemeMainService>('themeMainService');

export interface IThemeMainService {
Expand Down Expand Up @@ -50,7 +52,7 @@ export class ThemeMainService extends Disposable implements IThemeMainService {

// System Theme
this._register(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('window.systemColorTheme')) {
if (e.affectsConfiguration(SYSTEM_COLOR_THEME)) {
this.updateSystemColorTheme();
}
}));
Expand All @@ -61,7 +63,7 @@ export class ThemeMainService extends Disposable implements IThemeMainService {
}

private updateSystemColorTheme(): void {
switch (this.configurationService.getValue<'default' | 'auto' | 'light' | 'dark'>('window.systemColorTheme')) {
switch (this.configurationService.getValue<'default' | 'auto' | 'light' | 'dark'>(SYSTEM_COLOR_THEME)) {
case 'dark':
nativeTheme.themeSource = 'dark';
break;
Expand Down
16 changes: 8 additions & 8 deletions src/vs/workbench/contrib/themes/browser/themes.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,14 @@ registerAction2(class extends Action2 {
});
}

private getTitle(colorScheme: ColorScheme | undefined): string | undefined {
private getTitle(colorScheme: ColorScheme | undefined): string {
switch (colorScheme) {
case ColorScheme.DARK: return localize('themes.selectTheme.darkScheme', "Select Color Theme for Dark Mode");
case ColorScheme.LIGHT: return localize('themes.selectTheme.lightScheme', "Select Color Theme for Light Mode");
case ColorScheme.DARK: return localize('themes.selectTheme.darkScheme', "Select Color Theme for Dark OS System Theme");
case ColorScheme.LIGHT: return localize('themes.selectTheme.lightScheme', "Select Color Theme for Light OS System Theme");
case ColorScheme.HIGH_CONTRAST_DARK: return localize('themes.selectTheme.darkHC', "Select Color Theme for Dark High Contrast Mode");
case ColorScheme.HIGH_CONTRAST_LIGHT: return localize('themes.selectTheme.lightHC', "Select Color Theme for Light High Contrast Mode");
default:
return undefined;
return localize('themes.selectTheme.default', "Select Color Theme for all OS System Themes");
}
}

Expand All @@ -443,15 +443,15 @@ registerAction2(class extends Action2 {
let modeConfigureToggle;
if (preferredColorScheme) {
modeConfigureToggle = new Toggle({
title: 'Automatic Mode Switching is Enabled. Click to configure.',
title: localize('themes.configure.switchingEnabled', 'Configure themes for other OS system themes.'),
icon: Codicon.colorMode,
isChecked: false,
...defaultToggleStyles
});
} else {
modeConfigureToggle = new Toggle({
title: 'Click to configure automatic mode switching.',
icon: Codicon.gear,
title: localize('themes.configure.switchingDisabled', 'Configure themes switching based on the OS system theme.'),
icon: Codicon.colorMode,
isChecked: false,
...defaultToggleStyles
});
Expand All @@ -460,7 +460,7 @@ registerAction2(class extends Action2 {
const options = {
installMessage: localize('installColorThemes', "Install Additional Color Themes..."),
browseMessage: '$(plus) ' + localize('browseColorThemes', "Browse Additional Color Themes..."),
placeholderMessage: this.getTitle(preferredColorScheme) ?? 'Select Color Theme (Mode Switching Disabled)',
placeholderMessage: this.getTitle(preferredColorScheme),
marketplaceTag: 'category:themes',
toggles: [modeConfigureToggle],
onToggle: async (toggle, picker) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export class WorkbenchThemeService extends Disposable implements IWorkbenchTheme
|| e.affectsConfiguration(ThemeSettings.PREFERRED_HC_LIGHT_THEME)
|| e.affectsConfiguration(ThemeSettings.DETECT_COLOR_SCHEME)
|| e.affectsConfiguration(ThemeSettings.DETECT_HC)
|| e.affectsConfiguration(ThemeSettings.SYSTEM_COLOR_THEME)
) {
this.restoreColorTheme();
}
Expand Down
21 changes: 12 additions & 9 deletions src/vs/workbench/services/themes/common/themeConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { IJSONSchema } from 'vs/base/common/jsonSchema';
import { textmateColorsSchemaId, textmateColorGroupSchemaId } from 'vs/workbench/services/themes/common/colorThemeSchema';
import { workbenchColorsSchemaId } from 'vs/platform/theme/common/colorRegistry';
import { tokenStylingSchemaId } from 'vs/platform/theme/common/tokenClassificationRegistry';
import { ThemeSettings, IWorkbenchColorTheme, IWorkbenchFileIconTheme, IColorCustomizations, ITokenColorCustomizations, IWorkbenchProductIconTheme, ISemanticTokenColorCustomizations, ThemeSettingTarget, ThemeSettingDefaults } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { ThemeSettings, IWorkbenchColorTheme, IWorkbenchFileIconTheme, IColorCustomizations, ITokenColorCustomizations, IWorkbenchProductIconTheme, ISemanticTokenColorCustomizations, ThemeSettingTarget, ThemeSettingDefaults, ENABLE_SYSTEM_COLOR_SCHEME_SETTING } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { isWeb } from 'vs/base/common/platform';
import { ColorScheme } from 'vs/platform/theme/common/theme';
Expand All @@ -25,15 +25,15 @@ const colorThemeSettingEnum: string[] = [];
const colorThemeSettingEnumItemLabels: string[] = [];
const colorThemeSettingEnumDescriptions: string[] = [];

function formatSettingAsLink(str: string) {
export function formatSettingAsLink(str: string) {
return `\`#${str}#\``;
}

export const COLOR_THEME_CONFIGURATION_SETTINGS_TAG = 'colorThemeConfiguration';

const colorThemeSettingSchema: IConfigurationPropertySchema = {
type: 'string',
description: nls.localize({ key: 'colorTheme', comment: ['{0} will become a link to another setting.'] }, "Specifies the color theme used in the workbench if {0} is not enabled.", formatSettingAsLink(ThemeSettings.DETECT_COLOR_SCHEME)),
markdownDescription: nls.localize({ key: 'colorTheme', comment: ['{0} will become a link to another setting.'] }, "Specifies the color theme used in the workbench when {0} is not enabled.", formatSettingAsLink(ThemeSettings.DETECT_COLOR_SCHEME)),
default: isWeb ? ThemeSettingDefaults.COLOR_THEME_LIGHT : ThemeSettingDefaults.COLOR_THEME_DARK,
tags: [COLOR_THEME_CONFIGURATION_SETTINGS_TAG],
enum: colorThemeSettingEnum,
Expand All @@ -43,7 +43,7 @@ const colorThemeSettingSchema: IConfigurationPropertySchema = {
};
const preferredDarkThemeSettingSchema: IConfigurationPropertySchema = {
type: 'string', //
markdownDescription: nls.localize({ key: 'preferredDarkColorTheme', comment: ['{0} will become a link to another setting.'] }, 'Specifies the color theme for dark OS appearance when {0} is enabled.', formatSettingAsLink(ThemeSettings.DETECT_COLOR_SCHEME)),
markdownDescription: nls.localize({ key: 'preferredDarkColorTheme', comment: ['{0} will become a link to another setting.'] }, 'Specifies the color theme when the system color is dark and {0} is enabled.', formatSettingAsLink(ThemeSettings.DETECT_COLOR_SCHEME)),
default: ThemeSettingDefaults.COLOR_THEME_DARK,
tags: [COLOR_THEME_CONFIGURATION_SETTINGS_TAG],
enum: colorThemeSettingEnum,
Expand All @@ -53,7 +53,7 @@ const preferredDarkThemeSettingSchema: IConfigurationPropertySchema = {
};
const preferredLightThemeSettingSchema: IConfigurationPropertySchema = {
type: 'string',
markdownDescription: nls.localize({ key: 'preferredLightColorTheme', comment: ['{0} will become a link to another setting.'] }, 'Specifies the color theme for light OS appearance when {0} is enabled.', formatSettingAsLink(ThemeSettings.DETECT_COLOR_SCHEME)),
markdownDescription: nls.localize({ key: 'preferredLightColorTheme', comment: ['{0} will become a link to another setting.'] }, 'Specifies the color theme when the system color is light and {0} is enabled.', formatSettingAsLink(ThemeSettings.DETECT_COLOR_SCHEME)),
default: ThemeSettingDefaults.COLOR_THEME_LIGHT,
tags: [COLOR_THEME_CONFIGURATION_SETTINGS_TAG],
enum: colorThemeSettingEnum,
Expand All @@ -63,7 +63,7 @@ const preferredLightThemeSettingSchema: IConfigurationPropertySchema = {
};
const preferredHCDarkThemeSettingSchema: IConfigurationPropertySchema = {
type: 'string',
markdownDescription: nls.localize({ key: 'preferredHCDarkColorTheme', comment: ['{0} will become a link to another setting.'] }, 'Specifies the color theme used in high contrast dark mode when {0} is enabled.', formatSettingAsLink(ThemeSettings.DETECT_HC)),
markdownDescription: nls.localize({ key: 'preferredHCDarkColorTheme', comment: ['{0} will become a link to another setting.'] }, 'Specifies the color theme when in high contrast dark mode and {0} is enabled.', formatSettingAsLink(ThemeSettings.DETECT_HC)),
default: ThemeSettingDefaults.COLOR_THEME_HC_DARK,
tags: [COLOR_THEME_CONFIGURATION_SETTINGS_TAG],
enum: colorThemeSettingEnum,
Expand All @@ -73,7 +73,7 @@ const preferredHCDarkThemeSettingSchema: IConfigurationPropertySchema = {
};
const preferredHCLightThemeSettingSchema: IConfigurationPropertySchema = {
type: 'string',
markdownDescription: nls.localize({ key: 'preferredHCLightColorTheme', comment: ['{0} will become a link to another setting.'] }, 'Specifies the color theme used in high contrast light mode when {0} is enabled.', formatSettingAsLink(ThemeSettings.DETECT_HC)),
markdownDescription: nls.localize({ key: 'preferredHCLightColorTheme', comment: ['{0} will become a link to another setting.'] }, 'Specifies the color theme when in high contrast light mode and {0} is enabled.', formatSettingAsLink(ThemeSettings.DETECT_HC)),
default: ThemeSettingDefaults.COLOR_THEME_HC_LIGHT,
tags: [COLOR_THEME_CONFIGURATION_SETTINGS_TAG],
enum: colorThemeSettingEnum,
Expand All @@ -83,7 +83,10 @@ const preferredHCLightThemeSettingSchema: IConfigurationPropertySchema = {
};
const detectColorSchemeSettingSchema: IConfigurationPropertySchema = {
type: 'boolean',
markdownDescription: nls.localize({ key: 'detectColorScheme', comment: ['{0} and {1} will become links to other settings.'] }, 'If set, automatically switch to the preferred color theme based on the OS color mode. If the OS mode is dark, the theme specified at {0} is used, for light {1}.', formatSettingAsLink(ThemeSettings.PREFERRED_DARK_THEME), formatSettingAsLink(ThemeSettings.PREFERRED_LIGHT_THEME)),
markdownDescription:
nls.localize({ key: 'detectColorScheme', comment: ['{0} and {1} will become links to other settings.'] }, 'If enabled, will automatically select a color theme based on the OS system color. If the OS system color is dark, the theme specified at {0} is used, else {1}.', formatSettingAsLink(ThemeSettings.PREFERRED_DARK_THEME), formatSettingAsLink(ThemeSettings.PREFERRED_LIGHT_THEME))
+ (ENABLE_SYSTEM_COLOR_SCHEME_SETTING ? nls.localize({ key: 'detectColorSchemeSys', comment: ['{0} will become a link to another setting.'] }, '\n\nThis setting is ignored if {0} is configured.', formatSettingAsLink(ThemeSettings.SYSTEM_COLOR_THEME)) : ''),

default: false,
tags: [COLOR_THEME_CONFIGURATION_SETTINGS_TAG],
};
Expand Down Expand Up @@ -313,7 +316,7 @@ export class ThemeConfiguration {
if (this.configurationService.getValue(ThemeSettings.DETECT_HC) && this.hostColorService.highContrast) {
return this.hostColorService.dark ? ColorScheme.HIGH_CONTRAST_DARK : ColorScheme.HIGH_CONTRAST_LIGHT;
}
if (this.configurationService.getValue(ThemeSettings.DETECT_COLOR_SCHEME)) {
if (this.configurationService.getValue(ThemeSettings.DETECT_COLOR_SCHEME) && (!ENABLE_SYSTEM_COLOR_SCHEME_SETTING || this.configurationService.getValue(ThemeSettings.SYSTEM_COLOR_THEME) === 'default')) {
return this.hostColorService.dark ? ColorScheme.DARK : ColorScheme.LIGHT;
}
return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ConfigurationTarget } from 'vs/platform/configuration/common/configurat
import { isBoolean, isString } from 'vs/base/common/types';
import { IconContribution, IconDefinition } from 'vs/platform/theme/common/iconRegistry';
import { ColorScheme } from 'vs/platform/theme/common/theme';
import { isLinux } from 'vs/base/common/platform';

export const IWorkbenchThemeService = refineServiceDecorator<IThemeService, IWorkbenchThemeService>(IThemeService);

Expand Down Expand Up @@ -38,9 +39,13 @@ export enum ThemeSettings {
PREFERRED_HC_DARK_THEME = 'workbench.preferredHighContrastColorTheme', /* id kept for compatibility reasons */
PREFERRED_HC_LIGHT_THEME = 'workbench.preferredHighContrastLightColorTheme',
DETECT_COLOR_SCHEME = 'window.autoDetectColorScheme',
DETECT_HC = 'window.autoDetectHighContrast'
DETECT_HC = 'window.autoDetectHighContrast',

SYSTEM_COLOR_THEME = 'window.systemColorTheme'
}

export const ENABLE_SYSTEM_COLOR_SCHEME_SETTING = !isLinux;

export enum ThemeSettingDefaults {
COLOR_THEME_DARK = 'Default Dark Modern',
COLOR_THEME_LIGHT = 'Default Light Modern',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@
import { localize } from 'vs/nls';
import { Registry } from 'vs/platform/registry/common/platform';
import { IConfigurationRegistry, Extensions as ConfigurationExtensions, ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
import { isLinux } from 'vs/base/common/platform';
import { ENABLE_SYSTEM_COLOR_SCHEME_SETTING, ThemeSettings } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { COLOR_THEME_CONFIGURATION_SETTINGS_TAG, formatSettingAsLink } from 'vs/workbench/services/themes/common/themeConfiguration';

const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
configurationRegistry.registerConfiguration({
'properties': {
'window.systemColorTheme': {
'type': 'string',
'enum': ['default', 'auto', 'light', 'dark'],
'enumDescriptions': [
properties: {
[ThemeSettings.SYSTEM_COLOR_THEME]: {
type: 'string',
enum: ['default', 'matchColorTheme', 'light', 'dark'],
enumDescriptions: [
localize('window.systemColorTheme.default', "System color theme matches the configured OS theme."),
localize('window.systemColorTheme.auto', "Enforce a light system color theme when a light workbench color theme is configured and the same for configured dark workbench color themes."),
localize('window.systemColorTheme.matchColorTheme', "Enforce a light system color theme when a light workbench color theme is configured and the same for configured dark workbench color themes."),
localize('window.systemColorTheme.light', "Enforce a light system color theme."),
localize('window.systemColorTheme.dark', "Enforce a dark system color theme."),
],
'markdownDescription': localize('window.systemColorTheme', "The system color theme applies to native UI elements such as native dialogs, menus and title bar. Even if your OS is configured in light appearance mode, you can select a dark system color theme for the window. You can also configure to automatically adjust based on the `#workbench.colorTheme#` setting."),
'default': 'default',
'included': !isLinux, // not supported on Linux (https://github.com/electron/electron/issues/28887)
'scope': ConfigurationScope.APPLICATION
markdownDescription: localize({ key: 'window.systemColorTheme', comment: ['{0} and {1} will become links to other settings.'] }, "Overrides the system color theme that is used for native UI elements such as native dialogs, menus and title bar. Even if your OS is configured in light appearance mode, you can select a dark system color theme for the window. You can also configure to automatically adjust based on the {0} setting. Note: Using this setting will disable {1}", formatSettingAsLink(ThemeSettings.COLOR_THEME), formatSettingAsLink(ThemeSettings.DETECT_COLOR_SCHEME)),
default: 'default',
included: ENABLE_SYSTEM_COLOR_SCHEME_SETTING,
scope: ConfigurationScope.APPLICATION,
tags: [COLOR_THEME_CONFIGURATION_SETTINGS_TAG],
}
}
});

0 comments on commit 2edff46

Please sign in to comment.