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

Show builtin profile templates in import flow #188498

Merged
merged 2 commits into from
Jul 21, 2023
Merged
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
55 changes: 45 additions & 10 deletions src/vs/workbench/contrib/userDataProfile/browser/userDataProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { IUserDataProfile, IUserDataProfilesService, ProfileResourceType, UseDef
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { ILifecycleService, LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { CURRENT_PROFILE_CONTEXT, HAS_PROFILES_CONTEXT, IS_CURRENT_PROFILE_TRANSIENT_CONTEXT, IS_PROFILE_IMPORT_IN_PROGRESS_CONTEXT, IUserDataProfileImportExportService, IUserDataProfileManagementService, IUserDataProfileService, PROFILES_CATEGORY, PROFILE_FILTER, IS_PROFILE_EXPORT_IN_PROGRESS_CONTEXT, ProfilesMenu, PROFILES_ENABLEMENT_CONTEXT, PROFILES_TITLE } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
import { IQuickInputService, IQuickPickItem, IQuickPickSeparator } from 'vs/platform/quickinput/common/quickInput';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
import { URI } from 'vs/base/common/uri';
Expand All @@ -42,6 +42,8 @@ interface IProfileTemplateInfo {
readonly url: string;
}

type IProfileTemplateQuickPickItem = IQuickPickItem & IProfileTemplateInfo;

export class UserDataProfilesWorkbenchContribution extends Disposable implements IWorkbenchContribution {

private readonly currentProfileContext: IContextKey<string>;
Expand Down Expand Up @@ -308,6 +310,7 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
private registerImportProfileAction(): IDisposable {
const disposables = new DisposableStore();
const id = 'workbench.profiles.actions.importProfile';
const that = this;
disposables.add(registerAction2(class ImportProfileAction extends Action2 {
constructor() {
super({
Expand Down Expand Up @@ -340,21 +343,41 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements

const disposables = new DisposableStore();
const quickPick = disposables.add(quickInputService.createQuickPick());
const profileTemplateQuickPickItems = await that.getProfileTemplatesQuickPickItems();

const updateQuickPickItems = (value?: string) => {
const selectFromFileItem: IQuickPickItem = { label: localize('import from file', "Create from profile template file") };
quickPick.items = value ? [{ label: localize('import from url', "Create from profile template URL"), description: quickPick.value }, selectFromFileItem] : [selectFromFileItem];
const quickPickItems: (IQuickPickItem | IQuickPickSeparator)[] = [];
if (value) {
quickPickItems.push({ label: quickPick.value, description: localize('import from url', "Import from URL") });
}
quickPickItems.push({ label: localize('import from file', "Select File...") });
if (profileTemplateQuickPickItems.length) {
quickPickItems.push({
type: 'separator',
label: localize('templates', "Profile Templates")
}, ...profileTemplateQuickPickItems);
}
quickPick.items = quickPickItems;
};
quickPick.title = localize('import profile quick pick title', "Create Profile from Profile Template...");
quickPick.placeholder = localize('import profile placeholder', "Provide profile template URL or select profile template file");

quickPick.title = localize('import profile quick pick title', "Import from Profile Template...");
quickPick.placeholder = localize('import profile placeholder', "Provide Profile Template URL");
quickPick.ignoreFocusOut = true;
disposables.add(quickPick.onDidChangeValue(updateQuickPickItems));
updateQuickPickItems();
quickPick.matchOnLabel = false;
quickPick.matchOnDescription = false;
disposables.add(quickPick.onDidAccept(async () => {
quickPick.hide();
const selectedItem = quickPick.selectedItems[0];
if (!selectedItem) {
return;
}
try {
quickPick.hide();
const profile = quickPick.selectedItems[0].description ? URI.parse(quickPick.value) : await this.getProfileUriFromFileSystem(fileDialogService);
if ((<IProfileTemplateQuickPickItem>selectedItem).url) {
return await that.saveProfile(undefined, (<IProfileTemplateQuickPickItem>selectedItem).url);
}
const profile = selectedItem.label === quickPick.value ? URI.parse(quickPick.value) : await this.getProfileUriFromFileSystem(fileDialogService);
if (profile) {
await userDataProfileImportExportService.importProfile(profile);
}
Expand Down Expand Up @@ -541,18 +564,18 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
selectBox.render(append(domNode, $('.profile-type-select-container')));
quickPick.widget = domNode;

const updateOptions = () => {
const updateQuickpickInfo = () => {
const option = profileOptions[findOptionIndex()];
for (const resource of resources) {
resource.picked = option.source && !isString(option.source) ? !option.source?.useDefaultFlags?.[resource.id] : true;
}
update();
};

updateOptions();
updateQuickpickInfo();
disposables.add(selectBox.onDidSelect(({ index }) => {
source = profileOptions[index].source;
updateOptions();
updateQuickpickInfo();
}));
}

Expand Down Expand Up @@ -701,6 +724,18 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
}));
}

private async getProfileTemplatesQuickPickItems(): Promise<IProfileTemplateQuickPickItem[]> {
const quickPickItems: IProfileTemplateQuickPickItem[] = [];
const profileTemplates = await this.getProfileTemplatesFromProduct();
for (const template of profileTemplates) {
quickPickItems.push({
label: template.name,
...template
});
}
return quickPickItems;
}

private async getProfileTemplatesFromProduct(): Promise<IProfileTemplateInfo[]> {
if (this.productService.profileTemplatesUrl) {
try {
Expand Down