From 425b1e86047b9adb7f7f8383b345ecaa519f0cfb Mon Sep 17 00:00:00 2001 From: Colin Grant Date: Wed, 1 Dec 2021 01:01:19 +0100 Subject: [PATCH] update UI if user cancels --- .../abstract-resource-preference-provider.ts | 16 +++++++++++----- .../views/components/preference-node-renderer.ts | 14 +++++++++++++- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/packages/preferences/src/browser/abstract-resource-preference-provider.ts b/packages/preferences/src/browser/abstract-resource-preference-provider.ts index 2e2637412e09a..3ab08079a4b6d 100644 --- a/packages/preferences/src/browser/abstract-resource-preference-provider.ts +++ b/packages/preferences/src/browser/abstract-resource-preference-provider.ts @@ -30,7 +30,7 @@ import { MonacoEditorModel } from '@theia/monaco/lib/browser/monaco-editor-model import { MonacoWorkspace } from '@theia/monaco/lib/browser/monaco-workspace'; import { Deferred } from '@theia/core/lib/common/promise-util'; import { FileService } from '@theia/filesystem/lib/browser/file-service'; -import { nls } from '@theia/core'; +import { CancellationError, nls } from '@theia/core'; import { EditorManager } from '@theia/editor/lib/browser'; export interface FilePreferenceProviderLocks { @@ -141,14 +141,14 @@ export abstract class AbstractResourcePreferenceProvider extends PreferenceProvi return false; } if (!locks) { // Action cancelled by user. Consider it complete. - return true; + throw new CancellationError(); } if (shouldSave) { if (this.model.dirty) { shouldSave = await this.handleDirtyEditor(); } - if (!shouldSave) { // Action cancelled by user. Consider it complete. - return true; + if (!shouldSave) { + throw new CancellationError(); } } const editOperations = this.getEditOperations(path, value); @@ -157,6 +157,9 @@ export abstract class AbstractResourcePreferenceProvider extends PreferenceProvi } return this.pendingTransaction.promise; } catch (e) { + if (e instanceof CancellationError) { + throw e; + } const message = `Failed to update the value of '${key}' in '${this.getUri()}'.`; this.messageService.error(`${message} Please check if it is corrupted.`); console.error(`${message}`, e); @@ -203,6 +206,7 @@ export abstract class AbstractResourcePreferenceProvider extends PreferenceProvi } else { // User cancelled the operation. this.singleChangeLock.cancel(); locks.releaseTransaction!(); + this.pendingTransaction.resolve(false); } } locks?.releaseChange(); @@ -342,7 +346,9 @@ export abstract class AbstractResourcePreferenceProvider extends PreferenceProvi const saveAndRetry = nls.localizeByDefault('Save and Retry'); const open = nls.localizeByDefault('Open File'); const msg = await this.messageService.error( - nls.localizeByDefault('Unable to write preference change because the settings file is dirty. Please save the file and try again.'), + nls.localizeByDefault('Unable to write into {0} settings because the file has unsaved changes. Please save the {0} settings file first and then try again.', + nls.localizeByDefault(PreferenceScope[this.getScope()].toLocaleLowerCase()) + ), saveAndRetry, open); if (this.model) { diff --git a/packages/preferences/src/browser/views/components/preference-node-renderer.ts b/packages/preferences/src/browser/views/components/preference-node-renderer.ts index 46453e91448b4..9c3e821da5ab5 100644 --- a/packages/preferences/src/browser/views/components/preference-node-renderer.ts +++ b/packages/preferences/src/browser/views/components/preference-node-renderer.ts @@ -403,7 +403,8 @@ export abstract class PreferenceLeafNodeRenderer { - return this.preferenceService.set(this.id, value, this.scopeTracker.currentScope.scope, this.scopeTracker.currentScope.uri); + return this.preferenceService.set(this.id, value, this.scopeTracker.currentScope.scope, this.scopeTracker.currentScope.uri) + .catch(() => this.handleValueChange()); } handleSearchChange(isFiltered = this.model.isFiltered): void { @@ -420,7 +421,18 @@ export abstract class PreferenceLeafNodeRenderer