From 1c4ffb26d9f78f73515ef03586803b3256fa0a0d Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Wed, 9 Mar 2022 14:45:14 +0100 Subject: [PATCH] preferredHighContrastLightTheme setting and more changes --- extensions/theme-defaults/package.json | 2 +- .../theme-defaults/themes/hc_light.json | 1 - .../themes/browser/themes.contribution.ts | 6 ++--- .../browser/gettingStartedExtensionPoint.ts | 6 ++++- .../common/media/theme_picker.ts | 4 +++ .../themes/browser/workbenchThemeService.ts | 26 ++++++++++++++++--- .../services/themes/common/colorThemeData.ts | 10 +++++-- .../themes/common/themeConfiguration.ts | 24 ++++++++++++----- .../themes/common/workbenchThemeService.ts | 5 ++-- 9 files changed, 62 insertions(+), 22 deletions(-) diff --git a/extensions/theme-defaults/package.json b/extensions/theme-defaults/package.json index f36e68f02af..a05e93a6393 100644 --- a/extensions/theme-defaults/package.json +++ b/extensions/theme-defaults/package.json @@ -44,7 +44,7 @@ "path": "./themes/hc_black.json" }, { - "id": "Light High Contrast", + "id": "Default High Contrast Light", "label": "%lightHcColorThemeLabel%", "uiTheme": "hc-light", "path": "./themes/hc_light.json" diff --git a/extensions/theme-defaults/themes/hc_light.json b/extensions/theme-defaults/themes/hc_light.json index 70cdffe7c00..a97a88ca730 100644 --- a/extensions/theme-defaults/themes/hc_light.json +++ b/extensions/theme-defaults/themes/hc_light.json @@ -1,7 +1,6 @@ { "$schema": "vscode://schemas/color-theme", "name": "Light High Contrast", - "type": "hc", "colors": { "contrastActiveBorder": "#0F4A85", "contrastBorder": "#0F4A85", diff --git a/src/vs/workbench/contrib/themes/browser/themes.contribution.ts b/src/vs/workbench/contrib/themes/browser/themes.contribution.ts index 796869d5fbc..30308a2a8fb 100644 --- a/src/vs/workbench/contrib/themes/browser/themes.contribution.ts +++ b/src/vs/workbench/contrib/themes/browser/themes.contribution.ts @@ -14,7 +14,7 @@ import { IExtensionGalleryService, IExtensionManagementService, IGalleryExtensio import { IColorRegistry, Extensions as ColorRegistryExtensions } from 'vs/platform/theme/common/colorRegistry'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { Color } from 'vs/base/common/color'; -import { ColorScheme } from 'vs/platform/theme/common/theme'; +import { ColorScheme, isHighContrast } from 'vs/platform/theme/common/theme'; import { colorThemeSchemaId } from 'vs/workbench/services/themes/common/colorThemeSchema'; import { isCancellationError, onUnexpectedError } from 'vs/base/common/errors'; import { IQuickInputButton, IQuickInputService, IQuickPickItem, QuickPickInput } from 'vs/platform/quickinput/common/quickInput'; @@ -376,9 +376,7 @@ registerAction2(class extends Action2 { const picks: QuickPickInput[] = [ ...toEntries(themes.filter(t => t.type === ColorScheme.LIGHT), localize('themes.category.light', "light themes")), ...toEntries(themes.filter(t => t.type === ColorScheme.DARK), localize('themes.category.dark', "dark themes")), - ...toEntries(themes.filter(t => t.type === ColorScheme.HIGH_CONTRAST_LIGHT), localize('themes.category.hclight', "light high contrast themes")), - ...toEntries(themes.filter(t => t.type === ColorScheme.HIGH_CONTRAST_DARK), localize('themes.category.hcdark', "dark high contrast themes")), - + ...toEntries(themes.filter(t => isHighContrast(t.type)), localize('themes.category.hc', "high contrast themes")), ]; await picker.openQuickPick(picks, currentTheme); } diff --git a/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedExtensionPoint.ts b/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedExtensionPoint.ts index cd36dedd298..47c767d1249 100644 --- a/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedExtensionPoint.ts +++ b/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedExtensionPoint.ts @@ -90,7 +90,7 @@ export const walkthroughsExtensionPoint = ExtensionsRegistry.registerExtensionPo }, { type: 'object', - required: ['dark', 'light', 'hc'], + required: ['dark', 'light', 'hc', 'hcLight'], properties: { dark: { description: localize('walkthroughs.steps.media.image.path.dark.string', "Path to the image for dark themes, relative to extension directory."), @@ -103,6 +103,10 @@ export const walkthroughsExtensionPoint = ExtensionsRegistry.registerExtensionPo hc: { description: localize('walkthroughs.steps.media.image.path.hc.string', "Path to the image for hc themes, relative to extension directory."), type: 'string', + }, + hcLight: { + description: localize('walkthroughs.steps.media.image.path.hcLight.string', "Path to the image for hc light themes, relative to extension directory."), + type: 'string', } } } diff --git a/src/vs/workbench/contrib/welcomeGettingStarted/common/media/theme_picker.ts b/src/vs/workbench/contrib/welcomeGettingStarted/common/media/theme_picker.ts index ddc6e9b4a95..e60df2b320b 100644 --- a/src/vs/workbench/contrib/welcomeGettingStarted/common/media/theme_picker.ts +++ b/src/vs/workbench/contrib/welcomeGettingStarted/common/media/theme_picker.ts @@ -20,6 +20,10 @@ export default () => ` ${escape(localize('HighContrast', "High Contrast"))} + + + ${escape(localize('HighContrast Light', "High Contrast Light"))} + ${escape(localize('seeMore', "See More Themes..."))} diff --git a/src/vs/workbench/services/themes/browser/workbenchThemeService.ts b/src/vs/workbench/services/themes/browser/workbenchThemeService.ts index 92900965e02..6f8986a8963 100644 --- a/src/vs/workbench/services/themes/browser/workbenchThemeService.ts +++ b/src/vs/workbench/services/themes/browser/workbenchThemeService.ts @@ -243,21 +243,32 @@ export class WorkbenchThemeService implements IWorkbenchThemeService { private installConfigurationListener() { this.configurationService.onDidChangeConfiguration(e => { + let lazyPreferredColorScheme: ColorScheme | undefined | null = null; + const getPreferredColorScheme = () => { + if (lazyPreferredColorScheme === null) { + lazyPreferredColorScheme = this.getPreferredColorScheme(); + } + return lazyPreferredColorScheme; + }; + if (e.affectsConfiguration(ThemeSettings.COLOR_THEME)) { this.restoreColorTheme(); } if (e.affectsConfiguration(ThemeSettings.DETECT_COLOR_SCHEME) || e.affectsConfiguration(ThemeSettings.DETECT_HC)) { this.handlePreferredSchemeUpdated(); } - if (e.affectsConfiguration(ThemeSettings.PREFERRED_DARK_THEME) && this.getPreferredColorScheme() === ColorScheme.DARK) { + if (e.affectsConfiguration(ThemeSettings.PREFERRED_DARK_THEME) && getPreferredColorScheme() === ColorScheme.DARK) { this.applyPreferredColorTheme(ColorScheme.DARK); } - if (e.affectsConfiguration(ThemeSettings.PREFERRED_LIGHT_THEME) && this.getPreferredColorScheme() === ColorScheme.LIGHT) { + if (e.affectsConfiguration(ThemeSettings.PREFERRED_LIGHT_THEME) && getPreferredColorScheme() === ColorScheme.LIGHT) { this.applyPreferredColorTheme(ColorScheme.LIGHT); } - if (e.affectsConfiguration(ThemeSettings.PREFERRED_HC_THEME) && this.getPreferredColorScheme() === ColorScheme.HIGH_CONTRAST_DARK) { + if (e.affectsConfiguration(ThemeSettings.PREFERRED_HC_DARK_THEME) && getPreferredColorScheme() === ColorScheme.HIGH_CONTRAST_DARK) { this.applyPreferredColorTheme(ColorScheme.HIGH_CONTRAST_DARK); } + if (e.affectsConfiguration(ThemeSettings.PREFERRED_HC_LIGHT_THEME) && getPreferredColorScheme() === ColorScheme.HIGH_CONTRAST_LIGHT) { + this.applyPreferredColorTheme(ColorScheme.HIGH_CONTRAST_LIGHT); + } if (e.affectsConfiguration(ThemeSettings.FILE_ICON_THEME)) { this.restoreFileIconTheme(); } @@ -392,7 +403,14 @@ export class WorkbenchThemeService implements IWorkbenchThemeService { } private async applyPreferredColorTheme(type: ColorScheme): Promise { - const settingId = type === ColorScheme.DARK ? ThemeSettings.PREFERRED_DARK_THEME : type === ColorScheme.LIGHT ? ThemeSettings.PREFERRED_LIGHT_THEME : ThemeSettings.PREFERRED_HC_THEME; + let settingId: ThemeSettings; + switch (type) { + case ColorScheme.LIGHT: settingId = ThemeSettings.PREFERRED_LIGHT_THEME; break; + case ColorScheme.HIGH_CONTRAST_DARK: settingId = ThemeSettings.PREFERRED_HC_DARK_THEME; break; + case ColorScheme.HIGH_CONTRAST_LIGHT: settingId = ThemeSettings.PREFERRED_HC_LIGHT_THEME; break; + default: + settingId = ThemeSettings.PREFERRED_DARK_THEME; + } const themeSettingId = this.configurationService.getValue(settingId); if (themeSettingId && typeof themeSettingId === 'string') { const theme = this.colorThemeRegistry.findThemeBySettingsId(themeSettingId, undefined); diff --git a/src/vs/workbench/services/themes/common/colorThemeData.ts b/src/vs/workbench/services/themes/common/colorThemeData.ts index 6d9a2a02994..9af7e58c941 100644 --- a/src/vs/workbench/services/themes/common/colorThemeData.ts +++ b/src/vs/workbench/services/themes/common/colorThemeData.ts @@ -781,12 +781,18 @@ let defaultThemeColors: { [baseTheme: string]: ITextMateThemingRule[] } = { { scope: 'token.error-token', settings: { foreground: '#f44747' } }, { scope: 'token.debug-token', settings: { foreground: '#b267e6' } } ], - 'hc': [ + 'hcLight': [ + { scope: 'token.info-token', settings: { foreground: '#316bcd' } }, + { scope: 'token.warn-token', settings: { foreground: '#cd9731' } }, + { scope: 'token.error-token', settings: { foreground: '#cd3131' } }, + { scope: 'token.debug-token', settings: { foreground: '#800080' } } + ], + 'hcDark': [ { scope: 'token.info-token', settings: { foreground: '#6796e6' } }, { scope: 'token.warn-token', settings: { foreground: '#008000' } }, { scope: 'token.error-token', settings: { foreground: '#FF0000' } }, { scope: 'token.debug-token', settings: { foreground: '#b267e6' } } - ], + ] }; const noMatch = (_scope: ProbeScope) => -1; diff --git a/src/vs/workbench/services/themes/common/themeConfiguration.ts b/src/vs/workbench/services/themes/common/themeConfiguration.ts index 364d1bee23a..8f33a4418f3 100644 --- a/src/vs/workbench/services/themes/common/themeConfiguration.ts +++ b/src/vs/workbench/services/themes/common/themeConfiguration.ts @@ -18,7 +18,8 @@ import { isMacintosh, isWeb, isWindows } from 'vs/base/common/platform'; const DEFAULT_THEME_DARK_SETTING_VALUE = 'Default Dark+'; const DEFAULT_THEME_LIGHT_SETTING_VALUE = 'Default Light+'; -const DEFAULT_THEME_HC_SETTING_VALUE = 'Default High Contrast'; +const DEFAULT_THEME_HC_DARK_SETTING_VALUE = 'Default High Contrast'; +const DEFAULT_THEME_HC_LIGHT_SETTING_VALUE = 'Default High Contrast Light'; const DEFAULT_FILE_ICON_THEME_SETTING_VALUE = 'vs-seti'; @@ -58,10 +59,20 @@ const preferredLightThemeSettingSchema: IConfigurationPropertySchema = { enumItemLabels: colorThemeSettingEnumItemLabels, errorMessage: nls.localize('colorThemeError', "Theme is unknown or not installed."), }; -const preferredHCThemeSettingSchema: IConfigurationPropertySchema = { +const preferredHCDarkThemeSettingSchema: IConfigurationPropertySchema = { type: 'string', - markdownDescription: nls.localize({ key: 'preferredHCColorTheme', comment: ['`#{0}#` will become a link to an other setting. Do not remove backtick or #'] }, 'Specifies the preferred color theme used in high contrast mode when `#{0}#` is enabled.', ThemeSettings.DETECT_HC), - default: DEFAULT_THEME_HC_SETTING_VALUE, + markdownDescription: nls.localize({ key: 'preferredHCDarkColorTheme', comment: ['`#{0}#` will become a link to an other setting. Do not remove backtick or #'] }, 'Specifies the preferred color theme used in high contrast dark mode when `#{0}#` is enabled.', ThemeSettings.DETECT_HC), + default: DEFAULT_THEME_HC_DARK_SETTING_VALUE, + enum: colorThemeSettingEnum, + enumDescriptions: colorThemeSettingEnumDescriptions, + enumItemLabels: colorThemeSettingEnumItemLabels, + included: isWindows || isMacintosh, + errorMessage: nls.localize('colorThemeError', "Theme is unknown or not installed."), +}; +const preferredHCLightThemeSettingSchema: IConfigurationPropertySchema = { + type: 'string', + markdownDescription: nls.localize({ key: 'preferredHCLightColorTheme', comment: ['`#{0}#` will become a link to an other setting. Do not remove backtick or #'] }, 'Specifies the preferred color theme used in high contrast light mode when `#{0}#` is enabled.', ThemeSettings.DETECT_HC), + default: DEFAULT_THEME_HC_LIGHT_SETTING_VALUE, enum: colorThemeSettingEnum, enumDescriptions: colorThemeSettingEnumDescriptions, enumItemLabels: colorThemeSettingEnumItemLabels, @@ -106,7 +117,7 @@ const productIconThemeSettingSchema: IConfigurationPropertySchema = { const detectHCSchemeSettingSchema: IConfigurationPropertySchema = { type: 'boolean', default: true, - markdownDescription: nls.localize('autoDetectHighContrast', "If enabled, will automatically change to high contrast theme if the OS is using a high contrast theme. The high contrast theme to use is specified by `#{0}#`", ThemeSettings.PREFERRED_HC_THEME), + markdownDescription: nls.localize('autoDetectHighContrast', "If enabled, will automatically change to high contrast theme if the OS is using a high contrast theme. The high contrast theme to use is specified by `#{0}#` and `#{1}#`", ThemeSettings.PREFERRED_HC_DARK_THEME, ThemeSettings.PREFERRED_HC_LIGHT_THEME), scope: ConfigurationScope.APPLICATION }; @@ -118,7 +129,8 @@ const themeSettingsConfiguration: IConfigurationNode = { [ThemeSettings.COLOR_THEME]: colorThemeSettingSchema, [ThemeSettings.PREFERRED_DARK_THEME]: preferredDarkThemeSettingSchema, [ThemeSettings.PREFERRED_LIGHT_THEME]: preferredLightThemeSettingSchema, - [ThemeSettings.PREFERRED_HC_THEME]: preferredHCThemeSettingSchema, + [ThemeSettings.PREFERRED_HC_DARK_THEME]: preferredHCDarkThemeSettingSchema, + [ThemeSettings.PREFERRED_HC_LIGHT_THEME]: preferredHCLightThemeSettingSchema, [ThemeSettings.FILE_ICON_THEME]: fileIconThemeSettingSchema, [ThemeSettings.COLOR_CUSTOMIZATIONS]: colorCustomizationsSchema, [ThemeSettings.PRODUCT_ICON_THEME]: productIconThemeSettingSchema diff --git a/src/vs/workbench/services/themes/common/workbenchThemeService.ts b/src/vs/workbench/services/themes/common/workbenchThemeService.ts index d07c448adbb..9d7bc2a6edd 100644 --- a/src/vs/workbench/services/themes/common/workbenchThemeService.ts +++ b/src/vs/workbench/services/themes/common/workbenchThemeService.ts @@ -18,8 +18,6 @@ export const VS_DARK_THEME = 'vs-dark'; export const VS_HC_THEME = 'hc-black'; export const VS_HC_LIGHT_THEME = 'hc-light'; -export const HC_THEME_ID = 'Default High Contrast'; - export const THEME_SCOPE_OPEN_PAREN = '['; export const THEME_SCOPE_CLOSE_PAREN = ']'; export const THEME_SCOPE_WILDCARD = '*'; @@ -36,7 +34,8 @@ export enum ThemeSettings { PREFERRED_DARK_THEME = 'workbench.preferredDarkColorTheme', PREFERRED_LIGHT_THEME = 'workbench.preferredLightColorTheme', - PREFERRED_HC_THEME = 'workbench.preferredHighContrastColorTheme', + 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' }