Skip to content

Commit 7a2d479

Browse files
authored
implement feedback (microsoft#187841)
1 parent 5284fb5 commit 7a2d479

File tree

4 files changed

+68
-113
lines changed

4 files changed

+68
-113
lines changed

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

Lines changed: 26 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,16 @@ import { IRequestService, asJson } from 'vs/platform/request/common/request';
3131
import { CancellationToken } from 'vs/base/common/cancellation';
3232
import { ILogService } from 'vs/platform/log/common/log';
3333

34+
const CREATE_EMPTY_PROFILE_ACTION_ID = 'workbench.profiles.actions.createEmptyProfile';
35+
const CREATE_EMPTY_PROFILE_ACTION_TITLE = {
36+
value: localize('create empty profile', "Create an Empty Profile..."),
37+
original: 'Create an Empty Profile...'
38+
};
39+
3440
const CREATE_FROM_CURRENT_PROFILE_ACTION_ID = 'workbench.profiles.actions.createFromCurrentProfile';
3541
const CREATE_FROM_CURRENT_PROFILE_ACTION_TITLE = {
36-
value: localize('save profile as', "Create from Current Profile..."),
37-
original: 'Create from Current Profile...'
42+
value: localize('save profile as', "Save Current Profile As..."),
43+
original: 'Save Current Profile As...'
3844
};
3945

4046
const CREATE_NEW_PROFILE_ACTION_ID = 'workbench.profiles.actions.createNewProfile';
@@ -113,7 +119,6 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
113119
this.registerCreateNewProfileAction();
114120
this.registerCreateProfileAction();
115121
this.registerDeleteProfileAction();
116-
this.registerCreateProfileFromTemplatesAction();
117122

118123
this.registerHelpAction();
119124
}
@@ -445,11 +450,8 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
445450
this._register(registerAction2(class CreateEmptyProfileAction extends Action2 {
446451
constructor() {
447452
super({
448-
id: 'workbench.profiles.actions.createEmptyProfile',
449-
title: {
450-
value: localize('create empty profile', "Create an Empty Profile..."),
451-
original: 'Create an Empty Profile...'
452-
},
453+
id: CREATE_EMPTY_PROFILE_ACTION_ID,
454+
title: CREATE_EMPTY_PROFILE_ACTION_TITLE,
453455
category: PROFILES_CATEGORY,
454456
f1: true,
455457
precondition: PROFILES_ENABLEMENT_CONTEXT
@@ -480,7 +482,7 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
480482
return;
481483
}
482484
try {
483-
await this.userDataProfileImportExportService.createFromCurrentProfile(name);
485+
await this.userDataProfileImportExportService.SaveCurrentProfileAs(name);
484486
} catch (error) {
485487
this.notificationService.error(error);
486488
}
@@ -489,13 +491,8 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
489491
private async createNewProfile(): Promise<void> {
490492
const title = localize('create new profle', "Create New Profile...");
491493

492-
const name = await this.getNameForProfile(title);
493-
if (!name) {
494-
return;
495-
}
496-
497494
const settings: IQuickPickItem = { id: ProfileResourceType.Settings, label: localize('settings', "Settings"), picked: true };
498-
const keybindings: IQuickPickItem = { id: ProfileResourceType.Keybindings, label: localize('keybindings', "Keyboard Shortcuts"), picked: false };
495+
const keybindings: IQuickPickItem = { id: ProfileResourceType.Keybindings, label: localize('keybindings', "Keyboard Shortcuts"), picked: true };
499496
const snippets: IQuickPickItem = { id: ProfileResourceType.Snippets, label: localize('snippets', "User Snippets"), picked: true };
500497
const tasks: IQuickPickItem = { id: ProfileResourceType.Tasks, label: localize('tasks', "User Tasks"), picked: true };
501498
const extensions: IQuickPickItem = { id: ProfileResourceType.Extensions, label: localize('extensions', "Extensions"), picked: true };
@@ -510,7 +507,7 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
510507
quickPick.hideCheckAll = true;
511508
quickPick.ignoreFocusOut = true;
512509
quickPick.customLabel = localize('create', "Create Profile");
513-
quickPick.description = localize('customise the profile', "Choose the data that should be scoped to the new profile.");
510+
quickPick.description = localize('customise the profile', "Unselect to link to the Default Profile");
514511

515512
const disposables = new DisposableStore();
516513
const update = () => {
@@ -523,7 +520,7 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
523520
let needUpdate = false;
524521
for (const resource of resources) {
525522
resource.picked = items.includes(resource);
526-
const description = resource.picked ? undefined : localize('use default profile', "From Default Profile");
523+
const description = resource.picked ? undefined : localize('use default profile', "Default Profile");
527524
if (resource.description !== description) {
528525
resource.description = description;
529526
needUpdate = true;
@@ -554,6 +551,11 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
554551
return;
555552
}
556553

554+
const name = await this.getNameForProfile(title);
555+
if (!name) {
556+
return;
557+
}
558+
557559
try {
558560
const useDefaultFlags: UseDefaultProfileFlags | undefined = result.length !== resources.length ? {
559561
settings: !result.includes(settings),
@@ -609,11 +611,16 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
609611
const commandService = accessor.get(ICommandService);
610612
const userDataProfileImportExportService = accessor.get(IUserDataProfileImportExportService);
611613
const quickPickItems: QuickPickItem[] = [{
614+
id: CREATE_EMPTY_PROFILE_ACTION_ID,
615+
label: localize('empty profile', "Empty Profile..."),
616+
}, {
612617
id: CREATE_NEW_PROFILE_ACTION_ID,
613618
label: localize('new profile', "New Profile..."),
619+
}, {
620+
type: 'separator',
614621
}, {
615622
id: CREATE_FROM_CURRENT_PROFILE_ACTION_ID,
616-
label: localize('using current', "From Current Profile..."),
623+
label: localize('using current', "Save Current Profile As..."),
617624
}];
618625
const profileTemplateQuickPickItems = await that.getProfileTemplatesQuickPickItems();
619626
if (profileTemplateQuickPickItems.length) {
@@ -643,7 +650,7 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
643650
};
644651
that.telemetryService.publicLog2<ProfileCreationFromTemplateActionEvent, ProfileCreationFromTemplateActionClassification>('profileCreationAction:builtinTemplate', { profileName: (<IProfileTemplateQuickPickItem>pick).name });
645652
const uri = URI.parse((<IProfileTemplateQuickPickItem>pick).url);
646-
return userDataProfileImportExportService.importProfile(uri);
653+
return userDataProfileImportExportService.importProfile(uri, { mode: 'apply' });
647654
}
648655
}
649656
}
@@ -705,44 +712,6 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
705712
});
706713
}
707714

708-
private registerCreateProfileFromTemplatesAction(): void {
709-
const that = this;
710-
this._register(registerAction2(class CreateProfileFromTemplatesAction extends Action2 {
711-
constructor() {
712-
super({
713-
id: 'workbench.profiles.actions.createProfileFromTemplates',
714-
title: {
715-
value: localize('create profile from templates', "Create Profile from Templates..."),
716-
original: 'Create Profile from Templates...'
717-
},
718-
category: PROFILES_CATEGORY,
719-
precondition: PROFILES_ENABLEMENT_CONTEXT,
720-
});
721-
}
722-
723-
async run(accessor: ServicesAccessor) {
724-
const quickInputService = accessor.get(IQuickInputService);
725-
const userDataProfileImportExportService = accessor.get(IUserDataProfileImportExportService);
726-
const notificationService = accessor.get(INotificationService);
727-
const profileTemplateQuickPickItems = await that.getProfileTemplatesQuickPickItems();
728-
if (profileTemplateQuickPickItems.length) {
729-
const pick = await quickInputService.pick(profileTemplateQuickPickItems,
730-
{
731-
hideInput: true,
732-
canPickMany: false,
733-
title: localize('create profile from template title', "{0}: Create...", PROFILES_CATEGORY.value)
734-
});
735-
if ((<IProfileTemplateQuickPickItem>pick)?.url) {
736-
const uri = URI.parse((<IProfileTemplateQuickPickItem>pick).url);
737-
return userDataProfileImportExportService.importProfile(uri);
738-
}
739-
} else {
740-
notificationService.info(localize('no templates', "There are no templates to create from"));
741-
}
742-
}
743-
}));
744-
}
745-
746715
private registerHelpAction(): void {
747716
this._register(registerAction2(class HelpAction extends Action2 {
748717
constructor() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class UserDataProfilePreviewContribution extends Disposable implements IW
2020
) {
2121
super();
2222
if (environmentService.options?.profileToPreview) {
23-
userDataProfileImportExportService.importProfile(URI.revive(environmentService.options.profileToPreview), { preview: true })
23+
userDataProfileImportExportService.importProfile(URI.revive(environmentService.options.profileToPreview), { mode: 'preview' })
2424
.then(null, error => logService.error('Error while previewing the profile', getErrorMessage(error)));
2525
}
2626
}

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

Lines changed: 39 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -199,18 +199,21 @@ export class UserDataProfileImportExportService extends Disposable implements IU
199199
disposables.add(toDisposable(() => this.isProfileImportInProgressContextKey.set(false)));
200200

201201
try {
202+
const mode = options?.mode ?? 'preview';
202203
const profileTemplate = await this.progressService.withProgress({
203204
location: ProgressLocation.Window,
204205
command: showWindowLogActionId,
205-
title: localize('resolving uri', "{0}: Resolving profile content...", options?.preview ? localize('preview profile', "Preview Profile") : localize('import profile', "Create Profile")),
206+
title: localize('resolving uri', "{0}: Resolving profile content...", options?.mode ? localize('preview profile', "Preview Profile") : localize('import profile', "Create Profile")),
206207
}, () => this.resolveProfileTemplate(uri));
207208
if (!profileTemplate) {
208209
return;
209210
}
210-
if (options?.preview) {
211-
await this.previewProfile(uri, profileTemplate);
212-
} else {
213-
await this.doImportProfile(profileTemplate);
211+
if (mode === 'preview') {
212+
await this.previewProfile(profileTemplate);
213+
} else if (mode === 'apply') {
214+
await this.createAndSwitch(profileTemplate, false, true, localize('create profile', "Create Profile"));
215+
} else if (mode === 'both') {
216+
await this.importAndPreviewProfile(uri, profileTemplate);
214217
}
215218
} finally {
216219
disposables.dispose();
@@ -246,11 +249,11 @@ export class UserDataProfileImportExportService extends Disposable implements IU
246249
}
247250
}
248251

249-
async createFromCurrentProfile(name: string): Promise<void> {
252+
async SaveCurrentProfileAs(name: string): Promise<void> {
250253
const userDataProfilesExportState = this.instantiationService.createInstance(UserDataProfileExportState, this.userDataProfileService.currentProfile);
251254
try {
252255
const profileTemplate = await userDataProfilesExportState.getProfileTemplate(name, undefined);
253-
await this.doImportProfile(profileTemplate);
256+
await this.createAndSwitch(profileTemplate, false, true, localize('save profile as', "Save Profile As"));
254257
} finally {
255258
userDataProfilesExportState.dispose();
256259
}
@@ -266,7 +269,7 @@ export class UserDataProfileImportExportService extends Disposable implements IU
266269
sticky: true,
267270
}, async progress => {
268271
const reportProgress = (message: string) => progress.report({ message: localize('troubleshoot profile progress', "Setting up Troubleshoot Profile: {0}", message) });
269-
const profile = await this.importWithProgress(profileTemplate, true, false, reportProgress);
272+
const profile = await this.createProfile(profileTemplate, true, false, reportProgress);
270273
if (profile) {
271274
reportProgress(localize('progress extensions', "Applying Extensions..."));
272275
await this.instantiationService.createInstance(ExtensionsResource).copy(this.userDataProfileService.currentProfile, profile, true);
@@ -359,21 +362,21 @@ export class UserDataProfileImportExportService extends Disposable implements IU
359362
return profileTemplate;
360363
}
361364

362-
private async previewProfile(uri: URI, profileTemplate: IUserDataProfileTemplate): Promise<void> {
365+
private async importAndPreviewProfile(uri: URI, profileTemplate: IUserDataProfileTemplate): Promise<void> {
363366
const disposables = new DisposableStore();
364367

365368
try {
366369
const userDataProfileImportState = disposables.add(this.instantiationService.createInstance(UserDataProfileImportState, profileTemplate));
367370
profileTemplate = await userDataProfileImportState.getProfileTemplateToImport();
368371

369-
const importedProfile = await this.importAndSwitch(profileTemplate, true, false, localize('preview profile', "Preview Profile"));
372+
const importedProfile = await this.createAndSwitch(profileTemplate, true, false, localize('preview profile', "Preview Profile"));
370373

371374
if (!importedProfile) {
372375
return;
373376
}
374377

375378
const barrier = new Barrier();
376-
const importAction = this.getImportAction(barrier, userDataProfileImportState);
379+
const importAction = this.getCreateAction(barrier, userDataProfileImportState);
377380
const primaryAction = isWeb
378381
? new Action('importInDesktop', localize('import in desktop', "Create Profile in {0}", this.productService.nameLong), undefined, true, async () => this.openerService.open(uri, { openExternal: true }))
379382
: importAction;
@@ -432,69 +435,52 @@ export class UserDataProfileImportExportService extends Disposable implements IU
432435
}
433436
}
434437

435-
private async doImportProfile(profileTemplate: IUserDataProfileTemplate): Promise<void> {
438+
private async previewProfile(profileTemplate: IUserDataProfileTemplate): Promise<void> {
436439
const disposables = new DisposableStore();
437440
try {
438441
const userDataProfileImportState = disposables.add(this.instantiationService.createInstance(UserDataProfileImportState, profileTemplate));
439-
const barrier = new Barrier();
440-
const importAction = this.getImportAction(barrier, userDataProfileImportState);
441442
if (userDataProfileImportState.isEmpty()) {
442-
await importAction.run();
443+
await this.createAndSwitch(profileTemplate, false, true, localize('create profile', "Create Profile"));
443444
} else {
445+
const barrier = new Barrier();
446+
const importAction = this.getCreateAction(barrier, userDataProfileImportState);
444447
await this.showProfilePreviewView(IMPORT_PROFILE_PREVIEW_VIEW, profileTemplate.name, importAction, new BarrierAction(barrier, new Action('cancel', localize('cancel', "Cancel")), this.notificationService), false, userDataProfileImportState);
448+
await barrier.wait();
449+
await this.hideProfilePreviewView(IMPORT_PROFILE_PREVIEW_VIEW);
445450
}
446-
await barrier.wait();
447-
await this.hideProfilePreviewView(IMPORT_PROFILE_PREVIEW_VIEW);
448451
} finally {
449452
disposables.dispose();
450453
}
451454
}
452455

453-
private getImportAction(barrier: Barrier, userDataProfileImportState: UserDataProfileImportState): IAction {
454-
const title = localize('import', "Create Profile", userDataProfileImportState.profile.name);
455-
const importAction = new BarrierAction(barrier, new Action('import', title, undefined, true, () => {
456-
const importProfileFn = async () => {
457-
importAction.enabled = false;
458-
const profileTemplate = await userDataProfileImportState.getProfileTemplateToImport();
459-
const importedProfile = await this.importAndSwitch(profileTemplate, false, true, title);
460-
if (!importedProfile) {
461-
return;
462-
}
463-
};
464-
if (userDataProfileImportState.isEmpty()) {
465-
return importProfileFn();
466-
} else {
467-
return this.progressService.withProgress({
468-
location: IMPORT_PROFILE_PREVIEW_VIEW,
469-
}, () => importProfileFn());
470-
}
456+
private getCreateAction(barrier: Barrier, userDataProfileImportState: UserDataProfileImportState): IAction {
457+
const importAction = new BarrierAction(barrier, new Action('title', localize('import', "Create Profile"), undefined, true, async () => {
458+
importAction.enabled = false;
459+
const profileTemplate = await userDataProfileImportState.getProfileTemplateToImport();
460+
return this.createAndSwitch(profileTemplate, false, true, localize('create profile', "Create Profile"));
471461
}), this.notificationService);
472462
return importAction;
473463
}
474464

475-
private async importAndSwitch(profileTemplate: IUserDataProfileTemplate, temporaryProfile: boolean, extensions: boolean, title: string): Promise<IUserDataProfile | undefined> {
465+
private async createAndSwitch(profileTemplate: IUserDataProfileTemplate, temporaryProfile: boolean, extensions: boolean, title: string): Promise<IUserDataProfile | undefined> {
476466
return this.progressService.withProgress({
477-
location: ProgressLocation.Window,
478-
command: showWindowLogActionId,
467+
location: ProgressLocation.Notification,
468+
delay: 500,
469+
sticky: true,
479470
}, async (progress) => {
480-
progress.report({ message: localize('Importing profile', "{0} ({1})...", title, profileTemplate.name) });
481-
return this.importAndSwitchWithProgress(profileTemplate, temporaryProfile, extensions, message => progress.report({ message: `${title} (${profileTemplate.name}): ${message}` }));
471+
title = `${title} (${profileTemplate.name})`;
472+
progress.report({ message: title });
473+
const reportProgress = (message: string) => progress.report({ message: `${title}: ${message}` });
474+
const profile = await this.createProfile(profileTemplate, temporaryProfile, extensions, reportProgress);
475+
if (profile) {
476+
reportProgress(localize('switching profile', "Switching Profile..."));
477+
await this.userDataProfileManagementService.switchProfile(profile);
478+
}
479+
return profile;
482480
});
483481
}
484482

485-
private async importAndSwitchWithProgress(profileTemplate: IUserDataProfileTemplate, temporaryProfile: boolean, extensions: boolean, progress: (message: string) => void): Promise<IUserDataProfile | undefined> {
486-
const profile = await this.importWithProgress(profileTemplate, temporaryProfile, extensions, progress);
487-
488-
if (!profile) {
489-
return;
490-
}
491-
492-
progress(localize('switching profile', "Switching Profile..."));
493-
await this.userDataProfileManagementService.switchProfile(profile);
494-
return profile;
495-
}
496-
497-
private async importWithProgress(profileTemplate: IUserDataProfileTemplate, temporaryProfile: boolean, extensions: boolean, progress: (message: string) => void): Promise<IUserDataProfile | undefined> {
483+
private async createProfile(profileTemplate: IUserDataProfileTemplate, temporaryProfile: boolean, extensions: boolean, progress: (message: string) => void): Promise<IUserDataProfile | undefined> {
498484
const profile = await this.getProfileToImport(profileTemplate, temporaryProfile);
499485
if (!profile) {
500486
return undefined;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export function toUserDataProfileUri(path: string, productService: IProductServi
7474
}
7575

7676
export interface IProfileImportOptions {
77-
readonly preview?: boolean;
77+
readonly mode?: 'preview' | 'apply' | 'both';
7878
}
7979

8080
export const IUserDataProfileImportExportService = createDecorator<IUserDataProfileImportExportService>('IUserDataProfileImportExportService');
@@ -87,7 +87,7 @@ export interface IUserDataProfileImportExportService {
8787
exportProfile(): Promise<void>;
8888
importProfile(uri: URI, options?: IProfileImportOptions): Promise<void>;
8989
showProfileContents(): Promise<void>;
90-
createFromCurrentProfile(name: string): Promise<void>;
90+
SaveCurrentProfileAs(name: string): Promise<void>;
9191
createTroubleshootProfile(): Promise<void>;
9292
setProfile(profile: IUserDataProfileTemplate): Promise<void>;
9393
}

0 commit comments

Comments
 (0)