mirror of
https://github.com/microsoft/vscode.git
synced 2026-06-05 15:16:06 +01:00
Add command to toggle between light/dark color themes (#151554)
* Added quick input action to toggle between preferred color themes * Removed quickpick in favor of command to toggle between ligh/dark and high-contrast counterparts * Moved toggle logic to themes.contribution * togglePreferredTheme -> toggleLightDarkThemes Co-authored-by: Leonardo Montini <leonardo.montini@lab.flowing.it> Co-authored-by: Martin Aeschlimann <martinae@microsoft.com>
This commit is contained in:
@@ -8,7 +8,7 @@ import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes';
|
||||
import { MenuRegistry, MenuId, Action2, registerAction2 } from 'vs/platform/actions/common/actions';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { CATEGORIES } from 'vs/workbench/common/actions';
|
||||
import { IWorkbenchThemeService, IWorkbenchTheme, ThemeSettingTarget, IWorkbenchColorTheme, IWorkbenchFileIconTheme, IWorkbenchProductIconTheme } from 'vs/workbench/services/themes/common/workbenchThemeService';
|
||||
import { IWorkbenchThemeService, IWorkbenchTheme, ThemeSettingTarget, IWorkbenchColorTheme, IWorkbenchFileIconTheme, IWorkbenchProductIconTheme, ThemeSettings } from 'vs/workbench/services/themes/common/workbenchThemeService';
|
||||
import { VIEWLET_ID, IExtensionsViewPaneContainer } from 'vs/workbench/contrib/extensions/common/extensions';
|
||||
import { IExtensionGalleryService, IExtensionManagementService, IGalleryExtension } from 'vs/platform/extensionManagement/common/extensionManagement';
|
||||
import { IColorRegistry, Extensions as ColorRegistryExtensions } from 'vs/platform/theme/common/colorRegistry';
|
||||
@@ -34,6 +34,7 @@ import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiati
|
||||
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||
import { FileIconThemeData } from 'vs/workbench/services/themes/browser/fileIconThemeData';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
|
||||
export const manageExtensionIcon = registerIcon('theme-selection-manage-extension', Codicon.gear, localize('manageExtensionIcon', 'Icon for the \'Manage\' action in the theme selection quick pick.'));
|
||||
|
||||
@@ -583,6 +584,51 @@ registerAction2(class extends Action2 {
|
||||
}
|
||||
});
|
||||
|
||||
const toggleLightDarkThemesCommandId = 'workbench.action.toggleLightDarkThemes';
|
||||
|
||||
registerAction2(class extends Action2 {
|
||||
|
||||
constructor() {
|
||||
super({
|
||||
id: toggleLightDarkThemesCommandId,
|
||||
title: { value: localize('toggleLightDarkThemes.label', "Toggle between Light/Dark Themes"), original: 'Toggle between Light/Dark Themes' },
|
||||
category: CATEGORIES.Preferences,
|
||||
f1: true,
|
||||
});
|
||||
}
|
||||
|
||||
override async run(accessor: ServicesAccessor) {
|
||||
const themeService = accessor.get(IWorkbenchThemeService);
|
||||
const configurationService = accessor.get(IConfigurationService);
|
||||
|
||||
const currentTheme = themeService.getColorTheme();
|
||||
let newSettingsId: string = ThemeSettings.PREFERRED_DARK_THEME;
|
||||
switch (currentTheme.type) {
|
||||
case ColorScheme.LIGHT:
|
||||
newSettingsId = ThemeSettings.PREFERRED_DARK_THEME;
|
||||
break;
|
||||
case ColorScheme.DARK:
|
||||
newSettingsId = ThemeSettings.PREFERRED_LIGHT_THEME;
|
||||
break;
|
||||
case ColorScheme.HIGH_CONTRAST_LIGHT:
|
||||
newSettingsId = ThemeSettings.PREFERRED_HC_DARK_THEME;
|
||||
break;
|
||||
case ColorScheme.HIGH_CONTRAST_DARK:
|
||||
newSettingsId = ThemeSettings.PREFERRED_HC_LIGHT_THEME;
|
||||
break;
|
||||
}
|
||||
|
||||
const themeSettingId: string = configurationService.getValue(newSettingsId);
|
||||
|
||||
if (themeSettingId && typeof themeSettingId === 'string') {
|
||||
const theme = (await themeService.getColorThemes()).find(t => t.settingsId === themeSettingId);
|
||||
if (theme) {
|
||||
themeService.setColorTheme(theme.id, 'auto');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.MenubarPreferencesMenu, {
|
||||
group: '4_themes',
|
||||
command: {
|
||||
@@ -610,7 +656,6 @@ MenuRegistry.appendMenuItem(MenuId.MenubarPreferencesMenu, {
|
||||
order: 3
|
||||
});
|
||||
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.GlobalActivity, {
|
||||
group: '4_themes',
|
||||
command: {
|
||||
|
||||
Reference in New Issue
Block a user