add previewColorTheme command (for #137289)
This commit is contained in:
parent
1c1df5532d
commit
eecd0038f6
|
@ -32,6 +32,7 @@ import { Emitter } from 'vs/base/common/event';
|
||||||
import { IExtensionResourceLoaderService } from 'vs/workbench/services/extensionResourceLoader/common/extensionResourceLoader';
|
import { IExtensionResourceLoaderService } from 'vs/workbench/services/extensionResourceLoader/common/extensionResourceLoader';
|
||||||
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
|
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
|
||||||
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||||
|
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||||
|
|
||||||
export const manageExtensionIcon = registerIcon('theme-selection-manage-extension', Codicon.gear, localize('manageExtensionIcon', 'Icon for the \'Manage\' action in the theme selection quick pick.'));
|
export const manageExtensionIcon = registerIcon('theme-selection-manage-extension', Codicon.gear, localize('manageExtensionIcon', 'Icon for the \'Manage\' action in the theme selection quick pick.'));
|
||||||
|
|
||||||
|
@ -235,6 +236,7 @@ class MarketplaceThemesPicker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class InstalledThemesPicker {
|
class InstalledThemesPicker {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly installMessage: string,
|
private readonly installMessage: string,
|
||||||
|
@ -252,10 +254,10 @@ class InstalledThemesPicker {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async openQuickPick(picks: QuickPickInput<ThemeItem>[], currentTheme: IWorkbenchTheme) {
|
public async openQuickPick(picks: QuickPickInput<ThemeItem>[], currentTheme: IWorkbenchTheme) {
|
||||||
let marketplaceThemes: MarketplaceThemesPicker | undefined;
|
let marketplaceThemePicker: MarketplaceThemesPicker | undefined;
|
||||||
if (this.extensionGalleryService.isEnabled()) {
|
if (this.extensionGalleryService.isEnabled()) {
|
||||||
if (this.extensionResourceLoaderService.supportsExtensionGalleryResources) {
|
if (this.extensionResourceLoaderService.supportsExtensionGalleryResources) {
|
||||||
marketplaceThemes = this.instantiationService.createInstance(MarketplaceThemesPicker, this.getMarketplaceColorThemes.bind(this), this.marketplaceTag);
|
marketplaceThemePicker = this.instantiationService.createInstance(MarketplaceThemesPicker, this.getMarketplaceColorThemes.bind(this), this.marketplaceTag);
|
||||||
picks = [...configurationEntries(this.browseMessage), ...picks];
|
picks = [...configurationEntries(this.browseMessage), ...picks];
|
||||||
} else {
|
} else {
|
||||||
picks = [...picks, ...configurationEntries(this.installMessage)];
|
picks = [...picks, ...configurationEntries(this.installMessage)];
|
||||||
|
@ -264,7 +266,7 @@ class InstalledThemesPicker {
|
||||||
|
|
||||||
let selectThemeTimeout: number | undefined;
|
let selectThemeTimeout: number | undefined;
|
||||||
|
|
||||||
const selectTheme = (theme: ThemeItem | undefined, applyTheme: boolean) => {
|
const selectTheme = (theme: IWorkbenchTheme | undefined, applyTheme: boolean) => {
|
||||||
if (selectThemeTimeout) {
|
if (selectThemeTimeout) {
|
||||||
clearTimeout(selectThemeTimeout);
|
clearTimeout(selectThemeTimeout);
|
||||||
}
|
}
|
||||||
|
@ -294,8 +296,8 @@ class InstalledThemesPicker {
|
||||||
isCompleted = true;
|
isCompleted = true;
|
||||||
const theme = quickpick.selectedItems[0];
|
const theme = quickpick.selectedItems[0];
|
||||||
if (!theme || typeof theme.id === 'undefined') { // 'pick in marketplace' entry
|
if (!theme || typeof theme.id === 'undefined') { // 'pick in marketplace' entry
|
||||||
if (marketplaceThemes) {
|
if (marketplaceThemePicker) {
|
||||||
const res = await marketplaceThemes.openQuickPick(quickpick.value, currentTheme, selectTheme);
|
const res = await marketplaceThemePicker.openQuickPick(quickpick.value, currentTheme, selectTheme);
|
||||||
if (res === 'back') {
|
if (res === 'back') {
|
||||||
await pickInstalledThemes(undefined);
|
await pickInstalledThemes(undefined);
|
||||||
}
|
}
|
||||||
|
@ -303,13 +305,13 @@ class InstalledThemesPicker {
|
||||||
openExtensionViewlet(this.paneCompositeService, `${this.marketplaceTag} ${quickpick.value}`);
|
openExtensionViewlet(this.paneCompositeService, `${this.marketplaceTag} ${quickpick.value}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
selectTheme(theme, true);
|
selectTheme(theme.theme, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
quickpick.hide();
|
quickpick.hide();
|
||||||
s();
|
s();
|
||||||
});
|
});
|
||||||
quickpick.onDidChangeActive(themes => selectTheme(themes[0], false));
|
quickpick.onDidChangeActive(themes => selectTheme(themes[0].theme, false));
|
||||||
quickpick.onDidHide(() => {
|
quickpick.onDidHide(() => {
|
||||||
if (!isCompleted) {
|
if (!isCompleted) {
|
||||||
selectTheme(currentTheme, true);
|
selectTheme(currentTheme, true);
|
||||||
|
@ -332,7 +334,7 @@ class InstalledThemesPicker {
|
||||||
};
|
};
|
||||||
await pickInstalledThemes(currentTheme.id);
|
await pickInstalledThemes(currentTheme.id);
|
||||||
|
|
||||||
marketplaceThemes?.dispose();
|
marketplaceThemePicker?.dispose();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -451,6 +453,19 @@ registerAction2(class extends Action2 {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
CommandsRegistry.registerCommand('workbench.action.previewColorTheme', async function (accessor: ServicesAccessor, extension: { publisher: string, name: string, version: string }, themeSettingsId?: string) {
|
||||||
|
const themeService = accessor.get(IWorkbenchThemeService);
|
||||||
|
|
||||||
|
const themes = await themeService.getMarketplaceColorThemes(extension.publisher, extension.name, extension.version);
|
||||||
|
for (const theme of themes) {
|
||||||
|
if (!themeSettingsId || theme.settingsId === themeSettingsId) {
|
||||||
|
await themeService.setColorTheme(theme, 'preview');
|
||||||
|
return theme.settingsId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
});
|
||||||
|
|
||||||
function configurationEntries(label: string): QuickPickInput<ThemeItem>[] {
|
function configurationEntries(label: string): QuickPickInput<ThemeItem>[] {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue