Skip to content

Commit

Permalink
#156144 feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Jul 17, 2023
1 parent 4dd562c commit 6a94f6f
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions src/vs/workbench/contrib/userDataProfile/browser/userDataProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,11 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
const disposables = new DisposableStore();
const title = profile ? localize('save profile', "Edit Profile...") : localize('create new profle', "Create New Profile...");

const settings: IQuickPickItem & { id: ProfileResourceType } = { id: ProfileResourceType.Settings, label: localize('settings', "Settings"), picked: profile?.useDefaultFlags?.settings };
const keybindings: IQuickPickItem & { id: ProfileResourceType } = { id: ProfileResourceType.Keybindings, label: localize('keybindings', "Keyboard Shortcuts"), picked: profile?.useDefaultFlags?.keybindings };
const snippets: IQuickPickItem & { id: ProfileResourceType } = { id: ProfileResourceType.Snippets, label: localize('snippets', "User Snippets"), picked: profile?.useDefaultFlags?.snippets };
const tasks: IQuickPickItem & { id: ProfileResourceType } = { id: ProfileResourceType.Tasks, label: localize('tasks', "User Tasks"), picked: profile?.useDefaultFlags?.tasks };
const extensions: IQuickPickItem & { id: ProfileResourceType } = { id: ProfileResourceType.Extensions, label: localize('extensions', "Extensions"), picked: profile?.useDefaultFlags?.extensions };
const settings: IQuickPickItem & { id: ProfileResourceType } = { id: ProfileResourceType.Settings, label: localize('settings', "Settings"), picked: !profile?.useDefaultFlags?.settings };
const keybindings: IQuickPickItem & { id: ProfileResourceType } = { id: ProfileResourceType.Keybindings, label: localize('keybindings', "Keyboard Shortcuts"), picked: !profile?.useDefaultFlags?.keybindings };
const snippets: IQuickPickItem & { id: ProfileResourceType } = { id: ProfileResourceType.Snippets, label: localize('snippets', "User Snippets"), picked: !profile?.useDefaultFlags?.snippets };
const tasks: IQuickPickItem & { id: ProfileResourceType } = { id: ProfileResourceType.Tasks, label: localize('tasks', "User Tasks"), picked: !profile?.useDefaultFlags?.tasks };
const extensions: IQuickPickItem & { id: ProfileResourceType } = { id: ProfileResourceType.Extensions, label: localize('extensions', "Extensions"), picked: !profile?.useDefaultFlags?.extensions };
const resources = [settings, keybindings, snippets, tasks, extensions];

const quickPick = this.quickInputService.createQuickPick();
Expand All @@ -450,22 +450,23 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
quickPick.hideCheckAll = true;
quickPick.ignoreFocusOut = true;
quickPick.customLabel = profile ? localize('save', "Save") : localize('create', "Create");
quickPick.description = localize('customise the profile', "Select configurations to share from the Default profile:");
quickPick.description = localize('customise the profile', "Choose what to configure in your Profile:");
quickPick.items = [...resources];

const updateSelection = () => {
const update = () => {
quickPick.items = resources;
quickPick.selectedItems = resources.filter(item => item.picked);
};
updateSelection();
update();

const validate = () => {
if (!profile && this.userDataProfilesService.profiles.some(p => p.name === quickPick.value)) {
quickPick.validationMessage = localize('profileExists', "Profile with name {0} already exists.", quickPick.value);
quickPick.severity = Severity.Error;
return;
}
if (resources.every(resource => resource.picked)) {
quickPick.validationMessage = localize('cannot share all', "Cannot share all configurations from the Default Profile.");
if (resources.every(resource => !resource.picked)) {
quickPick.validationMessage = localize('invalid configurations', "The profile should contain at least one configuration.");
quickPick.severity = Severity.Error;
return;
}
Expand All @@ -474,8 +475,17 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
};

disposables.add(quickPick.onDidChangeSelection(items => {
let needUpdate = false;
for (const resource of resources) {
resource.picked = items.includes(resource);
const description = resource.picked ? undefined : localize('use default profile', "Use Default Profile");
if (resource.description !== description) {
resource.description = description;
needUpdate = true;
}
}
if (needUpdate) {
update();
}
validate();
}));
Expand Down Expand Up @@ -541,7 +551,7 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
for (const resource of resources) {
resource.picked = option.source?.useDefaultFlags?.[resource.id];
}
updateSelection();
update();
}
};

Expand Down Expand Up @@ -569,13 +579,15 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
this.telemetryService.publicLog2<{}, CreateProfileInfoClassification>('userDataProfile.successCreate');

try {
const useDefaultFlags: UseDefaultProfileFlags | undefined = result.items.length ? {
settings: result.items.includes(settings),
keybindings: result.items.includes(keybindings),
snippets: result.items.includes(snippets),
tasks: result.items.includes(tasks),
extensions: result.items.includes(extensions)
} : undefined;
const useDefaultFlags: UseDefaultProfileFlags | undefined = result.items.length === resources.length
? undefined
: {
settings: !result.items.includes(settings),
keybindings: !result.items.includes(keybindings),
snippets: !result.items.includes(snippets),
tasks: !result.items.includes(tasks),
extensions: !result.items.includes(extensions)
};
if (profile) {
await this.userDataProfileManagementService.updateProfile(profile, { name: result.name, useDefaultFlags: profile.useDefaultFlags && !useDefaultFlags ? {} : useDefaultFlags });
} else {
Expand Down

0 comments on commit 6a94f6f

Please sign in to comment.