diff --git a/src/vs/workbench/contrib/themes/browser/themes.contribution.ts b/src/vs/workbench/contrib/themes/browser/themes.contribution.ts index 45243cdcf21..f245ba5a9bc 100644 --- a/src/vs/workbench/contrib/themes/browser/themes.contribution.ts +++ b/src/vs/workbench/contrib/themes/browser/themes.contribution.ts @@ -662,6 +662,55 @@ registerAction2(class extends Action2 { } }); +const browseColorThemesInMarketplaceCommandId = 'workbench.action.browseColorThemesInMarketplace'; + +registerAction2(class extends Action2 { + + constructor() { + super({ + id: browseColorThemesInMarketplaceCommandId, + title: { value: localize('browseColorThemeInMarketPlace.label', "Browse Color Themes in Marketplace"), original: 'Browse Color Themes in Marketplace' }, + category: Categories.Preferences, + f1: true, + }); + } + + override async run(accessor: ServicesAccessor) { + const marketplaceTag = 'category:themes'; + const themeService = accessor.get(IWorkbenchThemeService); + const extensionGalleryService = accessor.get(IExtensionGalleryService); + const extensionResourceLoaderService = accessor.get(IExtensionResourceLoaderService); + const instantiationService = accessor.get(IInstantiationService); + + if (!extensionGalleryService.isEnabled() || !extensionResourceLoaderService.supportsExtensionGalleryResources) { + return; + } + const currentTheme = themeService.getColorTheme(); + const getMarketplaceColorThemes = (publisher: string, name: string, version: string) => themeService.getMarketplaceColorThemes(publisher, name, version); + + let selectThemeTimeout: number | undefined; + + const selectTheme = (theme: IWorkbenchTheme | undefined, applyTheme: boolean) => { + if (selectThemeTimeout) { + clearTimeout(selectThemeTimeout); + } + selectThemeTimeout = window.setTimeout(() => { + selectThemeTimeout = undefined; + const newTheme = (theme ?? currentTheme) as IWorkbenchTheme; + themeService.setColorTheme(newTheme as IWorkbenchColorTheme, applyTheme ? 'auto' : 'preview').then(undefined, + err => { + onUnexpectedError(err); + themeService.setColorTheme(currentTheme, undefined); + } + ); + }, applyTheme ? 0 : 200); + }; + + const marketplaceThemePicker = instantiationService.createInstance(MarketplaceThemesPicker, getMarketplaceColorThemes, marketplaceTag); + await marketplaceThemePicker.openQuickPick('', themeService.getColorTheme(), selectTheme).then(undefined, onUnexpectedError); + } +}); + const ThemesSubMenu = new MenuId('ThemesSubMenu'); MenuRegistry.appendMenuItem(MenuId.GlobalActivity, { title: localize('themes', "Themes"),