Skip to content

Commit 4219f23

Browse files
authored
Merge pull request microsoft#154024 from microsoft/sandy081/154020
Fix 154020
2 parents f4ab348 + 307fb16 commit 4219f23

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { CancellationToken } from 'vs/base/common/cancellation';
77
import { DisposableStore } from 'vs/base/common/lifecycle';
88
import { joinPath } from 'vs/base/common/resources';
99
import { localize } from 'vs/nls';
10-
import { Action2, registerAction2 } from 'vs/platform/actions/common/actions';
11-
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
10+
import { Action2, MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
11+
import { IDialogService, IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
1212
import { IFileService } from 'vs/platform/files/common/files';
1313
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
1414
import { INotificationService } from 'vs/platform/notification/common/notification';
@@ -19,6 +19,7 @@ import { ITextFileService } from 'vs/workbench/services/textfile/common/textfile
1919
import { IUserDataProfile, IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
2020
import { CATEGORIES } from 'vs/workbench/common/actions';
2121
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
22+
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
2223

2324
registerAction2(class CreateFromCurrentProfileAction extends Action2 {
2425
constructor() {
@@ -196,14 +197,14 @@ registerAction2(class ExportProfileAction extends Action2 {
196197
original: 'Export Settings Profile...'
197198
},
198199
category: PROFILES_CATEGORY,
199-
f1: true,
200-
precondition: PROFILES_ENABLEMENT_CONTEXT,
201200
menu: [
202201
{
203202
id: ManageProfilesSubMenu,
204203
group: '3_import_export_profiles',
205204
when: PROFILES_ENABLEMENT_CONTEXT,
206205
order: 1
206+
}, {
207+
id: MenuId.CommandPalette
207208
}
208209
]
209210
});
@@ -241,14 +242,14 @@ registerAction2(class ImportProfileAction extends Action2 {
241242
original: 'Import Settings Profile...'
242243
},
243244
category: PROFILES_CATEGORY,
244-
f1: true,
245-
precondition: PROFILES_ENABLEMENT_CONTEXT,
246245
menu: [
247246
{
248247
id: ManageProfilesSubMenu,
249248
group: '3_import_export_profiles',
250249
when: PROFILES_ENABLEMENT_CONTEXT,
251250
order: 2
251+
}, {
252+
id: MenuId.CommandPalette
252253
}
253254
]
254255
});
@@ -260,6 +261,19 @@ registerAction2(class ImportProfileAction extends Action2 {
260261
const fileService = accessor.get(IFileService);
261262
const requestService = accessor.get(IRequestService);
262263
const userDataProfileImportExportService = accessor.get(IUserDataProfileImportExportService);
264+
const dialogService = accessor.get(IDialogService);
265+
const contextKeyService = accessor.get(IContextKeyService);
266+
267+
const isSettingProfilesEnabled = contextKeyService.contextMatchesRules(PROFILES_ENABLEMENT_CONTEXT);
268+
269+
if (!isSettingProfilesEnabled) {
270+
if (!(await dialogService.confirm({
271+
title: localize('import profile title', "Import Settings from a Profile"),
272+
message: localize('confiirmation message', "This will replace your current settings. Are you sure you want to continue?"),
273+
})).confirmed) {
274+
return;
275+
}
276+
}
263277

264278
const disposables = new DisposableStore();
265279
const quickPick = disposables.add(quickInputService.createQuickPick());
@@ -278,7 +292,11 @@ registerAction2(class ImportProfileAction extends Action2 {
278292
quickPick.hide();
279293
const profile = quickPick.selectedItems[0].description ? await this.getProfileFromURL(quickPick.value, requestService) : await this.getProfileFromFileSystem(fileDialogService, fileService);
280294
if (profile) {
281-
await userDataProfileImportExportService.importProfile(profile);
295+
if (isSettingProfilesEnabled) {
296+
await userDataProfileImportExportService.importProfile(profile);
297+
} else {
298+
await userDataProfileImportExportService.setProfile(profile);
299+
}
282300
}
283301
}));
284302
disposables.add(quickPick.onDidHide(() => disposables.dispose()));

src/vs/workbench/services/userDataProfile/common/userDataProfile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export interface IUserDataProfileImportExportService {
6060

6161
exportProfile(options?: ProfileCreationOptions): Promise<IUserDataProfileTemplate>;
6262
importProfile(profile: IUserDataProfileTemplate): Promise<void>;
63+
setProfile(profile: IUserDataProfileTemplate): Promise<void>;
6364
}
6465

6566
export interface IResourceProfile {

src/vs/workbench/services/userDataProfile/common/userDataProfileImportExportService.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class UserDataProfileImportExportService implements IUserDataProfileImpor
5656

5757
await this.progressService.withProgress({
5858
location: ProgressLocation.Notification,
59-
title: localize('profiles.applying', "{0}: Importing...", PROFILES_CATEGORY),
59+
title: localize('profiles.importing', "{0}: Importing...", PROFILES_CATEGORY),
6060
}, async progress => {
6161
await this.userDataProfileManagementService.createAndEnterProfile(name);
6262
if (profileTemplate.settings) {
@@ -70,7 +70,25 @@ export class UserDataProfileImportExportService implements IUserDataProfileImpor
7070
}
7171
});
7272

73-
this.notificationService.info(localize('applied profile', "{0}: Imported successfully.", PROFILES_CATEGORY));
73+
this.notificationService.info(localize('imported profile', "{0}: Imported successfully.", PROFILES_CATEGORY));
74+
}
75+
76+
async setProfile(profile: IUserDataProfileTemplate): Promise<void> {
77+
await this.progressService.withProgress({
78+
location: ProgressLocation.Notification,
79+
title: localize('profiles.applying', "{0}: Applying...", PROFILES_CATEGORY),
80+
}, async progress => {
81+
if (profile.settings) {
82+
await this.settingsProfile.applyProfile(profile.settings);
83+
}
84+
if (profile.globalState) {
85+
await this.globalStateProfile.applyProfile(profile.globalState);
86+
}
87+
if (profile.extensions) {
88+
await this.extensionsProfile.applyProfile(profile.extensions);
89+
}
90+
});
91+
this.notificationService.info(localize('applied profile', "{0}: Applied successfully.", PROFILES_CATEGORY));
7492
}
7593

7694
}

0 commit comments

Comments
 (0)