Skip to content

Commit 396896e

Browse files
authored
Adopt import and export features (microsoft#153379)
1 parent b129227 commit 396896e

File tree

7 files changed

+70
-215
lines changed

7 files changed

+70
-215
lines changed

src/vs/workbench/contrib/userDataProfile/browser/userDataProfile.contribution.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { workbenchConfigurationNodeBase } from 'vs/workbench/common/configuratio
1111
import { IWorkbenchContributionsRegistry, Extensions } from 'vs/workbench/common/contributions';
1212
import { UserDataProfilesWorkbenchContribution } from 'vs/workbench/contrib/userDataProfile/browser/userDataProfile';
1313
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
14-
import '../common/profileActions';
1514
import '../common/userDataProfileActions';
1615

1716
if (!isWeb) {

src/vs/workbench/contrib/userDataProfile/common/profileActions.ts

Lines changed: 0 additions & 136 deletions
This file was deleted.

src/vs/workbench/contrib/userDataProfile/common/userDataProfileActions.ts

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation
1414
import { INotificationService } from 'vs/platform/notification/common/notification';
1515
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
1616
import { asJson, asText, IRequestService } from 'vs/platform/request/common/request';
17-
import { IUserDataProfileTemplate, isUserDataProfileTemplate, IUserDataProfileManagementService, IUserDataProfileWorkbenchService, PROFILES_CATEGORY, PROFILE_EXTENSION, PROFILE_FILTER, ManageProfilesSubMenu, IUserDataProfileService, PROFILES_ENABLEMENT_CONTEXT } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
17+
import { IUserDataProfileTemplate, isUserDataProfileTemplate, IUserDataProfileManagementService, IUserDataProfileImportExportService, PROFILES_CATEGORY, PROFILE_EXTENSION, PROFILE_FILTER, ManageProfilesSubMenu, IUserDataProfileService, PROFILES_ENABLEMENT_CONTEXT } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
1818
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
1919
import { IUserDataProfile, IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
2020
import { CATEGORIES } from 'vs/workbench/common/actions';
@@ -25,7 +25,7 @@ registerAction2(class CreateFromCurrentProfileAction extends Action2 {
2525
super({
2626
id: 'workbench.profiles.actions.createFromCurrentProfile',
2727
title: {
28-
value: localize('save profile as', "Create from Current Profile..."),
28+
value: localize('save profile as', "Create from Current Settings Profile..."),
2929
original: 'Create from Current Profile...'
3030
},
3131
category: PROFILES_CATEGORY,
@@ -47,7 +47,7 @@ registerAction2(class CreateFromCurrentProfileAction extends Action2 {
4747
const userDataProfileManagementService = accessor.get(IUserDataProfileManagementService);
4848
const name = await quickInputService.input({
4949
placeHolder: localize('name', "Profile name"),
50-
title: localize('save profile as', "Create from Current Profile..."),
50+
title: localize('save profile as', "Create from Current Settings Profile..."),
5151
});
5252
if (name) {
5353
await userDataProfileManagementService.createAndEnterProfile(name, undefined, true);
@@ -60,7 +60,7 @@ registerAction2(class CreateEmptyProfileAction extends Action2 {
6060
super({
6161
id: 'workbench.profiles.actions.createProfile',
6262
title: {
63-
value: localize('create profile', "Create an Empty Profile..."),
63+
value: localize('create profile', "Create an Empty Settings Profile..."),
6464
original: 'Create an Empty Profile...'
6565
},
6666
category: PROFILES_CATEGORY,
@@ -95,7 +95,7 @@ registerAction2(class RemoveProfileAction extends Action2 {
9595
super({
9696
id: 'workbench.profiles.actions.removeProfile',
9797
title: {
98-
value: localize('remove profile', "Remove Profile..."),
98+
value: localize('remove profile', "Remove Settings Profile..."),
9999
original: 'Remove Profile...'
100100
},
101101
category: PROFILES_CATEGORY,
@@ -132,8 +132,8 @@ registerAction2(class SwitchProfileAction extends Action2 {
132132
super({
133133
id: 'workbench.profiles.actions.switchProfile',
134134
title: {
135-
value: localize('switch profile', "Switch Settings Profile"),
136-
original: 'Switch Settings Profile'
135+
value: localize('switch profile', "Switch Settings Profile..."),
136+
original: 'Switch Settings Profile...'
137137
},
138138
category: PROFILES_CATEGORY,
139139
f1: true,
@@ -167,7 +167,7 @@ registerAction2(class CleanupProfilesAction extends Action2 {
167167
super({
168168
id: 'workbench.profiles.actions.cleanupProfiles',
169169
title: {
170-
value: localize('cleanup profile', "Cleanup Profiles"),
170+
value: localize('cleanup profile', "Cleanup Settings Profiles"),
171171
original: 'Cleanup Profiles'
172172
},
173173
category: CATEGORIES.Developer,
@@ -190,21 +190,29 @@ registerAction2(class CleanupProfilesAction extends Action2 {
190190
registerAction2(class ExportProfileAction extends Action2 {
191191
constructor() {
192192
super({
193-
id: 'workbench.profiles.actions.exportProfile2',
193+
id: 'workbench.profiles.actions.exportProfile',
194194
title: {
195-
value: localize('export profile', "Export Settings as a Profile (2)..."),
196-
original: 'Export Settings as a Profile as a Profile (2)...'
195+
value: localize('export profile', "Export Settings Profile..."),
196+
original: 'Export Settings Profile...'
197197
},
198198
category: PROFILES_CATEGORY,
199199
f1: true,
200200
precondition: PROFILES_ENABLEMENT_CONTEXT,
201+
menu: [
202+
{
203+
id: ManageProfilesSubMenu,
204+
group: '3_import_export_profiles',
205+
when: PROFILES_ENABLEMENT_CONTEXT,
206+
order: 1
207+
}
208+
]
201209
});
202210
}
203211

204212
async run(accessor: ServicesAccessor) {
205213
const textFileService = accessor.get(ITextFileService);
206214
const fileDialogService = accessor.get(IFileDialogService);
207-
const profileService = accessor.get(IUserDataProfileWorkbenchService);
215+
const userDataProfileImportExportService = accessor.get(IUserDataProfileImportExportService);
208216
const notificationService = accessor.get(INotificationService);
209217

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

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

223231
notificationService.info(localize('export success', "{0}: Exported successfully.", PROFILES_CATEGORY));
@@ -227,14 +235,22 @@ registerAction2(class ExportProfileAction extends Action2 {
227235
registerAction2(class ImportProfileAction extends Action2 {
228236
constructor() {
229237
super({
230-
id: 'workbench.profiles.actions.importProfile2',
238+
id: 'workbench.profiles.actions.importProfile',
231239
title: {
232-
value: localize('import profile', "Import Settings from a Profile (2)..."),
233-
original: 'Import Settings from a Profile (2)...'
240+
value: localize('import profile', "Import Settings Profile..."),
241+
original: 'Import Settings Profile...'
234242
},
235243
category: PROFILES_CATEGORY,
236244
f1: true,
237245
precondition: PROFILES_ENABLEMENT_CONTEXT,
246+
menu: [
247+
{
248+
id: ManageProfilesSubMenu,
249+
group: '3_import_export_profiles',
250+
when: PROFILES_ENABLEMENT_CONTEXT,
251+
order: 2
252+
}
253+
]
238254
});
239255
}
240256

@@ -243,7 +259,7 @@ registerAction2(class ImportProfileAction extends Action2 {
243259
const quickInputService = accessor.get(IQuickInputService);
244260
const fileService = accessor.get(IFileService);
245261
const requestService = accessor.get(IRequestService);
246-
const userDataProfileMangementService = accessor.get(IUserDataProfileManagementService);
262+
const userDataProfileImportExportService = accessor.get(IUserDataProfileImportExportService);
247263

248264
const disposables = new DisposableStore();
249265
const quickPick = disposables.add(quickInputService.createQuickPick());
@@ -262,13 +278,7 @@ registerAction2(class ImportProfileAction extends Action2 {
262278
quickPick.hide();
263279
const profile = quickPick.selectedItems[0].description ? await this.getProfileFromURL(quickPick.value, requestService) : await this.getProfileFromFileSystem(fileDialogService, fileService);
264280
if (profile) {
265-
const name = await quickInputService.input({
266-
placeHolder: localize('name', "Profile name"),
267-
title: localize('save profile as', "Create from Current Profile..."),
268-
});
269-
if (name) {
270-
await userDataProfileMangementService.createAndEnterProfileFromTemplate(name, profile);
271-
}
281+
await userDataProfileImportExportService.importProfile(profile);
272282
}
273283
}));
274284
disposables.add(quickPick.onDidHide(() => disposables.dispose()));

src/vs/workbench/services/userDataProfile/browser/userDataProfileManagement.ts

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { VSBuffer } from 'vs/base/common/buffer';
76
import { Disposable } from 'vs/base/common/lifecycle';
87
import { joinPath } from 'vs/base/common/resources';
98
import { URI } from 'vs/base/common/uri';
@@ -14,15 +13,13 @@ import { IExtensionsProfileScannerService } from 'vs/platform/extensionManagemen
1413
import { ExtensionType } from 'vs/platform/extensions/common/extensions';
1514
import { IFileService } from 'vs/platform/files/common/files';
1615
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
17-
import { ILogService } from 'vs/platform/log/common/log';
18-
import { IProgressService, ProgressLocation } from 'vs/platform/progress/common/progress';
1916
import { EXTENSIONS_RESOURCE_NAME, IUserDataProfile, IUserDataProfilesService, UseDefaultProfileFlags, WorkspaceIdentifier } from 'vs/platform/userDataProfile/common/userDataProfile';
2017
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
2118
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
2219
import { IExtensionManagementServerService, IWorkbenchExtensionManagementService } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
2320
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
2421
import { IHostService } from 'vs/workbench/services/host/browser/host';
25-
import { IUserDataProfileManagementService, IUserDataProfileService, IUserDataProfileTemplate, PROFILES_CATEGORY } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
22+
import { IUserDataProfileManagementService, IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
2623

2724
export class UserDataProfileManagementService extends Disposable implements IUserDataProfileManagementService {
2825
readonly _serviceBrand: undefined;
@@ -36,11 +33,9 @@ export class UserDataProfileManagementService extends Disposable implements IUse
3633
@IExtensionsProfileScannerService private readonly extensionsProfileScannerService: IExtensionsProfileScannerService,
3734
@IHostService private readonly hostService: IHostService,
3835
@IDialogService private readonly dialogService: IDialogService,
39-
@IProgressService private readonly progressService: IProgressService,
4036
@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
4137
@IExtensionService private readonly extensionService: IExtensionService,
4238
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
43-
@ILogService logService: ILogService
4439
) {
4540
super();
4641
}
@@ -56,7 +51,7 @@ export class UserDataProfileManagementService extends Disposable implements IUse
5651
throw new Error('Invalid Profile');
5752
}
5853

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

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

108-
async createAndEnterProfileFromTemplate(name: string, template: IUserDataProfileTemplate, useDefaultFlags: UseDefaultProfileFlags): Promise<void> {
109-
const workspaceIdentifier = this.getWorkspaceIdentifier();
110-
const profile = await this.progressService.withProgress({
111-
location: ProgressLocation.Notification,
112-
title: localize('profiles.creating', "{0}: Creating...", PROFILES_CATEGORY),
113-
}, async progress => {
114-
const promises: Promise<any>[] = [];
115-
const newProfile = this.userDataProfilesService.newProfile(name, useDefaultFlags);
116-
await this.fileService.createFolder(newProfile.location);
117-
if (template.globalState) {
118-
// todo: create global state
119-
}
120-
if (template.settings) {
121-
promises.push(this.fileService.writeFile(newProfile.settingsResource, VSBuffer.fromString(template.settings)));
122-
}
123-
if (template.extensions && newProfile.extensionsResource) {
124-
promises.push(this.fileService.writeFile(newProfile.extensionsResource, VSBuffer.fromString(template.extensions)));
125-
}
126-
await Promise.allSettled(promises);
127-
return this.userDataProfilesService.createProfile(newProfile, workspaceIdentifier);
128-
});
129-
await this.enterProfile(profile, false);
130-
}
131-
132104
private getWorkspaceIdentifier(): WorkspaceIdentifier {
133105
const workspace = this.workspaceContextService.getWorkspace();
134106
switch (this.workspaceContextService.getWorkbenchState()) {

0 commit comments

Comments
 (0)