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

Adopt import and export features #153379

Merged
merged 1 commit into from Jun 27, 2022
Merged
Show file tree
Hide file tree
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
Expand Up @@ -11,7 +11,6 @@ import { workbenchConfigurationNodeBase } from 'vs/workbench/common/configuratio
import { IWorkbenchContributionsRegistry, Extensions } from 'vs/workbench/common/contributions';
import { UserDataProfilesWorkbenchContribution } from 'vs/workbench/contrib/userDataProfile/browser/userDataProfile';
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
import '../common/profileActions';
import '../common/userDataProfileActions';

if (!isWeb) {
Expand Down
136 changes: 0 additions & 136 deletions src/vs/workbench/contrib/userDataProfile/common/profileActions.ts

This file was deleted.

Expand Up @@ -14,7 +14,7 @@ import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
import { asJson, asText, IRequestService } from 'vs/platform/request/common/request';
import { IUserDataProfileTemplate, isUserDataProfileTemplate, IUserDataProfileManagementService, IUserDataProfileWorkbenchService, PROFILES_CATEGORY, PROFILE_EXTENSION, PROFILE_FILTER, ManageProfilesSubMenu, IUserDataProfileService, PROFILES_ENABLEMENT_CONTEXT } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
import { IUserDataProfileTemplate, isUserDataProfileTemplate, IUserDataProfileManagementService, IUserDataProfileImportExportService, PROFILES_CATEGORY, PROFILE_EXTENSION, PROFILE_FILTER, ManageProfilesSubMenu, IUserDataProfileService, PROFILES_ENABLEMENT_CONTEXT } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IUserDataProfile, IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
import { CATEGORIES } from 'vs/workbench/common/actions';
Expand All @@ -25,7 +25,7 @@ registerAction2(class CreateFromCurrentProfileAction extends Action2 {
super({
id: 'workbench.profiles.actions.createFromCurrentProfile',
title: {
value: localize('save profile as', "Create from Current Profile..."),
value: localize('save profile as', "Create from Current Settings Profile..."),
original: 'Create from Current Profile...'
},
category: PROFILES_CATEGORY,
Expand All @@ -47,7 +47,7 @@ registerAction2(class CreateFromCurrentProfileAction extends Action2 {
const userDataProfileManagementService = accessor.get(IUserDataProfileManagementService);
const name = await quickInputService.input({
placeHolder: localize('name', "Profile name"),
title: localize('save profile as', "Create from Current Profile..."),
title: localize('save profile as', "Create from Current Settings Profile..."),
});
if (name) {
await userDataProfileManagementService.createAndEnterProfile(name, undefined, true);
Expand All @@ -60,7 +60,7 @@ registerAction2(class CreateEmptyProfileAction extends Action2 {
super({
id: 'workbench.profiles.actions.createProfile',
title: {
value: localize('create profile', "Create an Empty Profile..."),
value: localize('create profile', "Create an Empty Settings Profile..."),
original: 'Create an Empty Profile...'
},
category: PROFILES_CATEGORY,
Expand Down Expand Up @@ -95,7 +95,7 @@ registerAction2(class RemoveProfileAction extends Action2 {
super({
id: 'workbench.profiles.actions.removeProfile',
title: {
value: localize('remove profile', "Remove Profile..."),
value: localize('remove profile', "Remove Settings Profile..."),
original: 'Remove Profile...'
},
category: PROFILES_CATEGORY,
Expand Down Expand Up @@ -132,8 +132,8 @@ registerAction2(class SwitchProfileAction extends Action2 {
super({
id: 'workbench.profiles.actions.switchProfile',
title: {
value: localize('switch profile', "Switch Settings Profile"),
original: 'Switch Settings Profile'
value: localize('switch profile', "Switch Settings Profile..."),
original: 'Switch Settings Profile...'
},
category: PROFILES_CATEGORY,
f1: true,
Expand Down Expand Up @@ -167,7 +167,7 @@ registerAction2(class CleanupProfilesAction extends Action2 {
super({
id: 'workbench.profiles.actions.cleanupProfiles',
title: {
value: localize('cleanup profile', "Cleanup Profiles"),
value: localize('cleanup profile', "Cleanup Settings Profiles"),
original: 'Cleanup Profiles'
},
category: CATEGORIES.Developer,
Expand All @@ -190,21 +190,29 @@ registerAction2(class CleanupProfilesAction extends Action2 {
registerAction2(class ExportProfileAction extends Action2 {
constructor() {
super({
id: 'workbench.profiles.actions.exportProfile2',
id: 'workbench.profiles.actions.exportProfile',
title: {
value: localize('export profile', "Export Settings as a Profile (2)..."),
original: 'Export Settings as a Profile as a Profile (2)...'
value: localize('export profile', "Export Settings Profile..."),
original: 'Export Settings Profile...'
},
category: PROFILES_CATEGORY,
f1: true,
precondition: PROFILES_ENABLEMENT_CONTEXT,
menu: [
{
id: ManageProfilesSubMenu,
group: '3_import_export_profiles',
when: PROFILES_ENABLEMENT_CONTEXT,
order: 1
}
]
});
}

async run(accessor: ServicesAccessor) {
const textFileService = accessor.get(ITextFileService);
const fileDialogService = accessor.get(IFileDialogService);
const profileService = accessor.get(IUserDataProfileWorkbenchService);
const userDataProfileImportExportService = accessor.get(IUserDataProfileImportExportService);
const notificationService = accessor.get(INotificationService);

const profileLocation = await fileDialogService.showSaveDialog({
Expand All @@ -217,7 +225,7 @@ registerAction2(class ExportProfileAction extends Action2 {
return;
}

const profile = await profileService.createProfile({ skipComments: true });
const profile = await userDataProfileImportExportService.exportProfile({ skipComments: true });
await textFileService.create([{ resource: profileLocation, value: JSON.stringify(profile), options: { overwrite: true } }]);

notificationService.info(localize('export success', "{0}: Exported successfully.", PROFILES_CATEGORY));
Expand All @@ -227,14 +235,22 @@ registerAction2(class ExportProfileAction extends Action2 {
registerAction2(class ImportProfileAction extends Action2 {
constructor() {
super({
id: 'workbench.profiles.actions.importProfile2',
id: 'workbench.profiles.actions.importProfile',
title: {
value: localize('import profile', "Import Settings from a Profile (2)..."),
original: 'Import Settings from a Profile (2)...'
value: localize('import profile', "Import Settings Profile..."),
original: 'Import Settings Profile...'
},
category: PROFILES_CATEGORY,
f1: true,
precondition: PROFILES_ENABLEMENT_CONTEXT,
menu: [
{
id: ManageProfilesSubMenu,
group: '3_import_export_profiles',
when: PROFILES_ENABLEMENT_CONTEXT,
order: 2
}
]
});
}

Expand All @@ -243,7 +259,7 @@ registerAction2(class ImportProfileAction extends Action2 {
const quickInputService = accessor.get(IQuickInputService);
const fileService = accessor.get(IFileService);
const requestService = accessor.get(IRequestService);
const userDataProfileMangementService = accessor.get(IUserDataProfileManagementService);
const userDataProfileImportExportService = accessor.get(IUserDataProfileImportExportService);

const disposables = new DisposableStore();
const quickPick = disposables.add(quickInputService.createQuickPick());
Expand All @@ -262,13 +278,7 @@ registerAction2(class ImportProfileAction extends Action2 {
quickPick.hide();
const profile = quickPick.selectedItems[0].description ? await this.getProfileFromURL(quickPick.value, requestService) : await this.getProfileFromFileSystem(fileDialogService, fileService);
if (profile) {
const name = await quickInputService.input({
placeHolder: localize('name', "Profile name"),
title: localize('save profile as', "Create from Current Profile..."),
});
if (name) {
await userDataProfileMangementService.createAndEnterProfileFromTemplate(name, profile);
}
await userDataProfileImportExportService.importProfile(profile);
}
}));
disposables.add(quickPick.onDidHide(() => disposables.dispose()));
Expand Down
Expand Up @@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { VSBuffer } from 'vs/base/common/buffer';
import { Disposable } from 'vs/base/common/lifecycle';
import { joinPath } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
Expand All @@ -14,15 +13,13 @@ import { IExtensionsProfileScannerService } from 'vs/platform/extensionManagemen
import { ExtensionType } from 'vs/platform/extensions/common/extensions';
import { IFileService } from 'vs/platform/files/common/files';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { ILogService } from 'vs/platform/log/common/log';
import { IProgressService, ProgressLocation } from 'vs/platform/progress/common/progress';
import { EXTENSIONS_RESOURCE_NAME, IUserDataProfile, IUserDataProfilesService, UseDefaultProfileFlags, WorkspaceIdentifier } from 'vs/platform/userDataProfile/common/userDataProfile';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { IExtensionManagementServerService, IWorkbenchExtensionManagementService } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { IHostService } from 'vs/workbench/services/host/browser/host';
import { IUserDataProfileManagementService, IUserDataProfileService, IUserDataProfileTemplate, PROFILES_CATEGORY } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
import { IUserDataProfileManagementService, IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile';

export class UserDataProfileManagementService extends Disposable implements IUserDataProfileManagementService {
readonly _serviceBrand: undefined;
Expand All @@ -36,11 +33,9 @@ export class UserDataProfileManagementService extends Disposable implements IUse
@IExtensionsProfileScannerService private readonly extensionsProfileScannerService: IExtensionsProfileScannerService,
@IHostService private readonly hostService: IHostService,
@IDialogService private readonly dialogService: IDialogService,
@IProgressService private readonly progressService: IProgressService,
@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
@IExtensionService private readonly extensionService: IExtensionService,
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
@ILogService logService: ILogService
) {
super();
}
Expand All @@ -56,7 +51,7 @@ export class UserDataProfileManagementService extends Disposable implements IUse
throw new Error('Invalid Profile');
}

async createAndEnterProfile(name: string, useDefaultFlags?: UseDefaultProfileFlags, fromExisting?: boolean): Promise<void> {
async createAndEnterProfile(name: string, useDefaultFlags?: UseDefaultProfileFlags, fromExisting?: boolean): Promise<IUserDataProfile> {
const workspaceIdentifier = this.getWorkspaceIdentifier();
const promises: Promise<any>[] = [];
const newProfile = this.userDataProfilesService.newProfile(name, useDefaultFlags);
Expand All @@ -74,6 +69,7 @@ export class UserDataProfileManagementService extends Disposable implements IUse
await Promise.allSettled(promises);
const createdProfile = await this.userDataProfilesService.createProfile(newProfile, workspaceIdentifier);
await this.enterProfile(createdProfile, !!fromExisting);
return createdProfile;
}

async removeProfile(profile: IUserDataProfile): Promise<void> {
Expand Down Expand Up @@ -105,30 +101,6 @@ export class UserDataProfileManagementService extends Disposable implements IUse
await this.enterProfile(profile, false);
}

async createAndEnterProfileFromTemplate(name: string, template: IUserDataProfileTemplate, useDefaultFlags: UseDefaultProfileFlags): Promise<void> {
const workspaceIdentifier = this.getWorkspaceIdentifier();
const profile = await this.progressService.withProgress({
location: ProgressLocation.Notification,
title: localize('profiles.creating', "{0}: Creating...", PROFILES_CATEGORY),
}, async progress => {
const promises: Promise<any>[] = [];
const newProfile = this.userDataProfilesService.newProfile(name, useDefaultFlags);
await this.fileService.createFolder(newProfile.location);
if (template.globalState) {
// todo: create global state
}
if (template.settings) {
promises.push(this.fileService.writeFile(newProfile.settingsResource, VSBuffer.fromString(template.settings)));
}
if (template.extensions && newProfile.extensionsResource) {
promises.push(this.fileService.writeFile(newProfile.extensionsResource, VSBuffer.fromString(template.extensions)));
}
await Promise.allSettled(promises);
return this.userDataProfilesService.createProfile(newProfile, workspaceIdentifier);
});
await this.enterProfile(profile, false);
}

private getWorkspaceIdentifier(): WorkspaceIdentifier {
const workspace = this.workspaceContextService.getWorkspace();
switch (this.workspaceContextService.getWorkbenchState()) {
Expand Down