Skip to content

Commit

Permalink
Apply extension to all profiles #157492
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Jul 12, 2023
1 parent 4529b4a commit fdaef28
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,24 @@ class ExtensionsContributions extends Disposable implements IWorkbenchContributi
}
});

this.registerExtensionAction({
id: 'workbench.extensions.action.toggleApplyToAllProfiles',
title: { value: localize('workbench.extensions.action.toggleApplyToAllProfiles', "Apply this Extension to all Profiles"), original: `Apply this Extension to all Profiles` },
toggled: ContextKeyExpr.has('isApplicationScopedExtension'),
menu: {
id: MenuId.ExtensionContext,
group: '2_configure',
when: ContextKeyExpr.and(ContextKeyExpr.equals('extensionStatus', 'installed'), ContextKeyExpr.has('isDefaultApplicationScopedExtension').negate()),
order: 4
},
run: async (accessor: ServicesAccessor, id: string) => {
const extension = this.extensionsWorkbenchService.local.find(e => areSameExtensions({ id }, e.identifier));
if (extension) {
return this.extensionsWorkbenchService.toggleApplyExtensionToAllProfiles(extension);
}
}
});

this.registerExtensionAction({
id: 'workbench.extensions.action.ignoreRecommendation',
title: { value: localize('workbench.extensions.action.ignoreRecommendation', "Ignore Recommendation"), original: `Ignore Recommendation` },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { IGalleryExtension, IExtensionGalleryService, ILocalExtension, InstallOp
import { IWorkbenchExtensionEnablementService, EnablementState, IExtensionManagementServerService, IExtensionManagementServer } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
import { ExtensionRecommendationReason, IExtensionIgnoredRecommendationsService, IExtensionRecommendationsService } from 'vs/workbench/services/extensionRecommendations/common/extensionRecommendations';
import { areSameExtensions, getExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { ExtensionType, ExtensionIdentifier, IExtensionDescription, IExtensionManifest, isLanguagePackExtension, getWorkspaceSupportTypeMessage, TargetPlatform } from 'vs/platform/extensions/common/extensions';
import { ExtensionType, ExtensionIdentifier, IExtensionDescription, IExtensionManifest, isLanguagePackExtension, getWorkspaceSupportTypeMessage, TargetPlatform, isApplicationScopedExtension } from 'vs/platform/extensions/common/extensions';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IFileService, IFileContent } from 'vs/platform/files/common/files';
import { IWorkspaceContextService, WorkbenchState, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
Expand Down Expand Up @@ -1010,6 +1010,8 @@ async function getContextMenuActionsGroups(extension: IExtension | undefined | n
if (extension) {
cksOverlay.push(['extension', extension.identifier.id]);
cksOverlay.push(['isBuiltinExtension', extension.isBuiltin]);
cksOverlay.push(['isDefaultApplicationScopedExtension', extension.local && isApplicationScopedExtension(extension.local.manifest)]);
cksOverlay.push(['isApplicationScopedExtension', extension.local && extension.local.isApplicationScoped]);
cksOverlay.push(['extensionHasConfiguration', extension.local && !!extension.local.manifest.contributes && !!extension.local.manifest.contributes.configuration]);
cksOverlay.push(['extensionHasKeybindings', extension.local && !!extension.local.manifest.contributes && !!extension.local.manifest.contributes.keybindings]);
cksOverlay.push(['extensionHasCommands', extension.local && !!extension.local.manifest.contributes && !!extension.local.manifest.contributes?.commands]);
Expand Down Expand Up @@ -1179,6 +1181,8 @@ export class MenuItemExtensionAction extends ExtensionAction {
}
if (this.action.id === TOGGLE_IGNORE_EXTENSION_ACTION_ID) {
this.checked = !this.extensionsWorkbenchService.isExtensionIgnoredToSync(this.extension);
} else {
this.checked = this.action.checked;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import * as resources from 'vs/base/common/resources';
import { CancellationToken } from 'vs/base/common/cancellation';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IFileService } from 'vs/platform/files/common/files';
import { IExtensionManifest, ExtensionType, IExtension as IPlatformExtension, TargetPlatform, ExtensionIdentifier, IExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { IExtensionManifest, ExtensionType, IExtension as IPlatformExtension, TargetPlatform, ExtensionIdentifier, IExtensionIdentifier, IExtensionDescription, isApplicationScopedExtension } from 'vs/platform/extensions/common/extensions';
import { ILanguageService } from 'vs/editor/common/languages/language';
import { IProductService } from 'vs/platform/product/common/productService';
import { FileAccess } from 'vs/base/common/network';
Expand All @@ -50,6 +50,7 @@ import { getLocale } from 'vs/platform/languagePacks/common/languagePacks';
import { ILocaleService } from 'vs/workbench/services/localization/common/locale';
import { TelemetryTrustedValue } from 'vs/platform/telemetry/common/telemetryUtils';
import { ILifecycleService, LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';

interface IExtensionStateProvider<T> {
(extension: Extension): T;
Expand Down Expand Up @@ -774,6 +775,7 @@ export class ExtensionsWorkbenchService extends Disposable implements IExtension
@ILocaleService private readonly localeService: ILocaleService,
@ILifecycleService private readonly lifecycleService: ILifecycleService,
@IFileService private readonly fileService: IFileService,
@IUserDataProfilesService private readonly userDataProfilesService: IUserDataProfilesService,
) {
super();
const preferPreReleasesValue = configurationService.getValue('_extensions.preferPreReleases');
Expand Down Expand Up @@ -1619,6 +1621,12 @@ export class ExtensionsWorkbenchService extends Disposable implements IExtension
await this.userDataAutoSyncService.triggerSync(['IgnoredExtensionsUpdated'], false, false);
}

async toggleApplyExtensionToAllProfiles(extension: IExtension): Promise<void> {
if (extension.local && !isApplicationScopedExtension(extension.local.manifest)) {
await this.extensionManagementService.updateMetadata(extension.local, { isApplicationScoped: !extension.local.isApplicationScoped }, this.userDataProfilesService.defaultProfile.extensionsResource);
}
}

private isInstalledExtensionSynced(extension: ILocalExtension): boolean {
if (extension.isMachineScoped) {
return false;
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/extensions/common/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export interface IExtensionsWorkbenchService {
// Sync APIs
isExtensionIgnoredToSync(extension: IExtension): boolean;
toggleExtensionIgnoredToSync(extension: IExtension): Promise<void>;
toggleApplyExtensionToAllProfiles(extension: IExtension): Promise<void>;
}

export const enum ExtensionEditorTab {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ export class ExtensionManagementService extends Disposable implements IWorkbench
return Promise.reject(`Invalid location ${extension.location.toString()}`);
}

updateMetadata(extension: ILocalExtension, metadata: Partial<Metadata>): Promise<ILocalExtension> {
updateMetadata(extension: ILocalExtension, metadata: Partial<Metadata>, profileLocation?: URI): Promise<ILocalExtension> {
const server = this.getServer(extension);
if (server) {
return server.extensionManagementService.updateMetadata(extension, metadata);
return server.extensionManagementService.updateMetadata(extension, metadata, profileLocation);
}
return Promise.reject(`Invalid location ${extension.location.toString()}`);
}
Expand Down

0 comments on commit fdaef28

Please sign in to comment.