Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command to browse marketplace color themes #192269

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/vs/workbench/contrib/themes/browser/themes.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, <ISubmenuItem>{
title: localize('themes', "Themes"),
Expand Down