mirror of
https://github.com/Microsoft/vscode
synced 2024-10-06 03:17:00 +00:00
fix canceling (#214519)
This commit is contained in:
parent
3ea3162dd4
commit
bf11c6cd52
|
@ -823,7 +823,7 @@ export class UserDataProfilesEditorModel extends EditorModel {
|
||||||
() => this.previewNewProfile(cancellationTokenSource.token)
|
() => this.previewNewProfile(cancellationTokenSource.token)
|
||||||
));
|
));
|
||||||
this.newProfileElement = disposables.add(this.instantiationService.createInstance(NewProfileElement,
|
this.newProfileElement = disposables.add(this.instantiationService.createInstance(NewProfileElement,
|
||||||
localize('untitled', "Untitled"),
|
copyFrom ? '' : localize('untitled', "Untitled"),
|
||||||
copyFrom,
|
copyFrom,
|
||||||
[[createAction], [previewProfileAction, cancelAction]],
|
[[createAction], [previewProfileAction, cancelAction]],
|
||||||
[[], []],
|
[[], []],
|
||||||
|
@ -911,7 +911,7 @@ export class UserDataProfilesEditorModel extends EditorModel {
|
||||||
const template = await this.newProfileElement.resolveTemplate(copyFrom);
|
const template = await this.newProfileElement.resolveTemplate(copyFrom);
|
||||||
if (template) {
|
if (template) {
|
||||||
this.telemetryService.publicLog2<CreateProfileInfoEvent, CreateProfileInfoClassification>('userDataProfile.createFromTemplate', createProfileTelemetryData);
|
this.telemetryService.publicLog2<CreateProfileInfoEvent, CreateProfileInfoClassification>('userDataProfile.createFromTemplate', createProfileTelemetryData);
|
||||||
await this.userDataProfileImportExportService.createProfileFromTemplate(
|
profile = await this.userDataProfileImportExportService.createProfileFromTemplate(
|
||||||
template,
|
template,
|
||||||
{
|
{
|
||||||
name,
|
name,
|
||||||
|
@ -925,7 +925,7 @@ export class UserDataProfilesEditorModel extends EditorModel {
|
||||||
}
|
}
|
||||||
} else if (isUserDataProfile(copyFrom)) {
|
} else if (isUserDataProfile(copyFrom)) {
|
||||||
this.telemetryService.publicLog2<CreateProfileInfoEvent, CreateProfileInfoClassification>('userDataProfile.createFromProfile', createProfileTelemetryData);
|
this.telemetryService.publicLog2<CreateProfileInfoEvent, CreateProfileInfoClassification>('userDataProfile.createFromProfile', createProfileTelemetryData);
|
||||||
await this.userDataProfileImportExportService.createFromProfile(
|
profile = await this.userDataProfileImportExportService.createFromProfile(
|
||||||
copyFrom,
|
copyFrom,
|
||||||
{
|
{
|
||||||
name,
|
name,
|
||||||
|
@ -938,10 +938,8 @@ export class UserDataProfilesEditorModel extends EditorModel {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.telemetryService.publicLog2<CreateProfileInfoEvent, CreateProfileInfoClassification>('userDataProfile.createEmptyProfile', createProfileTelemetryData);
|
this.telemetryService.publicLog2<CreateProfileInfoEvent, CreateProfileInfoClassification>('userDataProfile.createEmptyProfile', createProfileTelemetryData);
|
||||||
await this.userDataProfileManagementService.createProfile(name, { useDefaultFlags, icon, transient });
|
profile = await this.userDataProfileManagementService.createProfile(name, { useDefaultFlags, icon, transient });
|
||||||
}
|
}
|
||||||
|
|
||||||
profile = this.userDataProfilesService.profiles.find(p => p.name === name);
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (this.newProfileElement) {
|
if (this.newProfileElement) {
|
||||||
|
|
|
@ -241,7 +241,14 @@ export class UserDataProfileImportExportService extends Disposable implements IU
|
||||||
creationPromise = createCancelablePromise(async token => {
|
creationPromise = createCancelablePromise(async token => {
|
||||||
const userDataProfilesExportState = disposables.add(this.instantiationService.createInstance(UserDataProfileExportState, from, { ...options?.resourceTypeFlags, extensions: false }));
|
const userDataProfilesExportState = disposables.add(this.instantiationService.createInstance(UserDataProfileExportState, from, { ...options?.resourceTypeFlags, extensions: false }));
|
||||||
const profileTemplate = await userDataProfilesExportState.getProfileTemplate(options.name ?? from.name, options?.icon);
|
const profileTemplate = await userDataProfilesExportState.getProfileTemplate(options.name ?? from.name, options?.icon);
|
||||||
profile = await this.doCreateProfile2(profileTemplate, options, reportProgress, token);
|
profile = await this.getProfileToImport({ ...profileTemplate, name: options.name ?? profileTemplate.name }, !!options.transient, options);
|
||||||
|
if (!profile) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (token.isCancellationRequested) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await this.applyProfileTemplate(profileTemplate, profile, options, reportProgress, token);
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await creationPromise;
|
await creationPromise;
|
||||||
|
@ -252,6 +259,7 @@ export class UserDataProfileImportExportService extends Disposable implements IU
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (profile) {
|
if (profile) {
|
||||||
await this.userDataProfilesService.removeProfile(profile);
|
await this.userDataProfilesService.removeProfile(profile);
|
||||||
|
profile = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return profile;
|
return profile;
|
||||||
|
@ -272,27 +280,28 @@ export class UserDataProfileImportExportService extends Disposable implements IU
|
||||||
}, async progress => {
|
}, async progress => {
|
||||||
const reportProgress = (message: string) => progress.report({ message: localize('create from profile', "Create Profile: {0}", message) });
|
const reportProgress = (message: string) => progress.report({ message: localize('create from profile', "Create Profile: {0}", message) });
|
||||||
creationPromise = createCancelablePromise(async token => {
|
creationPromise = createCancelablePromise(async token => {
|
||||||
profile = await this.doCreateProfile2(profileTemplate, options, reportProgress, token);
|
profile = await this.getProfileToImport({ ...profileTemplate, name: options.name ?? profileTemplate.name }, !!options.transient, options);
|
||||||
|
if (!profile) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (token.isCancellationRequested) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await this.applyProfileTemplate(profileTemplate, profile, options, reportProgress, token);
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await creationPromise;
|
await creationPromise;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (profile) {
|
if (profile) {
|
||||||
await this.userDataProfilesService.removeProfile(profile);
|
await this.userDataProfilesService.removeProfile(profile);
|
||||||
|
profile = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return profile;
|
return profile;
|
||||||
}, () => creationPromise.cancel()).finally(() => disposables.dispose());
|
}, () => creationPromise.cancel()).finally(() => disposables.dispose());
|
||||||
}
|
}
|
||||||
|
|
||||||
private async doCreateProfile2(profileTemplate: IUserDataProfileTemplate, options: IUserDataProfileCreateOptions, reportProgress: (message: string) => void, token: CancellationToken): Promise<IUserDataProfile | undefined> {
|
private async applyProfileTemplate(profileTemplate: IUserDataProfileTemplate, profile: IUserDataProfile, options: IUserDataProfileCreateOptions, reportProgress: (message: string) => void, token: CancellationToken): Promise<void> {
|
||||||
const profile = await this.getProfileToImport({ ...profileTemplate, name: options.name ?? profileTemplate.name }, !!options.transient, options);
|
|
||||||
if (!profile) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (token.isCancellationRequested) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (profileTemplate.settings && (options.resourceTypeFlags?.settings ?? true) && !profile.useDefaultFlags?.settings) {
|
if (profileTemplate.settings && (options.resourceTypeFlags?.settings ?? true) && !profile.useDefaultFlags?.settings) {
|
||||||
reportProgress(localize('creating settings', "Creating Settings..."));
|
reportProgress(localize('creating settings', "Creating Settings..."));
|
||||||
await this.instantiationService.createInstance(SettingsResource).apply(profileTemplate.settings, profile);
|
await this.instantiationService.createInstance(SettingsResource).apply(profileTemplate.settings, profile);
|
||||||
|
@ -332,7 +341,6 @@ export class UserDataProfileImportExportService extends Disposable implements IU
|
||||||
reportProgress(localize('installing extensions', "Installing Extensions..."));
|
reportProgress(localize('installing extensions', "Installing Extensions..."));
|
||||||
await this.instantiationService.createInstance(ExtensionsResource).apply(profileTemplate.extensions, profile, reportProgress, token);
|
await this.instantiationService.createInstance(ExtensionsResource).apply(profileTemplate.extensions, profile, reportProgress, token);
|
||||||
}
|
}
|
||||||
return profile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private saveProfile(profile: IUserDataProfile): Promise<void>;
|
private saveProfile(profile: IUserDataProfile): Promise<void>;
|
||||||
|
|
Loading…
Reference in a new issue