From 449d27a5aed40bcb3c7d1f02d053632cbdb6c16f Mon Sep 17 00:00:00 2001 From: Aditya Bist Date: Tue, 19 Apr 2022 20:26:22 -0700 Subject: [PATCH] Add confirmation dialog before closing app (#19139) * added confirmation dialog before closing app * only one prompt for multiple open table designers --- .../browser/tableDesignerService.ts | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/sql/workbench/services/tableDesigner/browser/tableDesignerService.ts b/src/sql/workbench/services/tableDesigner/browser/tableDesignerService.ts index 212d1c2f91..bfabcb7e23 100644 --- a/src/sql/workbench/services/tableDesigner/browser/tableDesignerService.ts +++ b/src/sql/workbench/services/tableDesigner/browser/tableDesignerService.ts @@ -3,6 +3,7 @@ * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import { localize } from 'vs/nls'; import { TableDesignerProvider, ITableDesignerService } from 'sql/workbench/services/tableDesigner/common/interface'; import { invalidProvider } from 'sql/base/common/errors'; import * as azdata from 'azdata'; @@ -11,16 +12,38 @@ import { TableDesignerInput } from 'sql/workbench/browser/editor/tableDesigner/t import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IAdsTelemetryService, ITelemetryEventProperties } from 'sql/platform/telemetry/common/telemetry'; import { TelemetryAction, TelemetryView } from 'sql/platform/telemetry/common/telemetryKeys'; +import { IDialogService } from 'vs/platform/dialogs/common/dialogs'; +import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle'; export class TableDesignerService implements ITableDesignerService { constructor(@IEditorService private _editorService: IEditorService, @IInstantiationService private _instantiationService: IInstantiationService, - @IAdsTelemetryService private _adsTelemetryService: IAdsTelemetryService) { } + @IAdsTelemetryService private _adsTelemetryService: IAdsTelemetryService, + @ILifecycleService private _lifecycleService: ILifecycleService, + @IDialogService private _dialogService: IDialogService) { + this._lifecycleService.onBeforeShutdown(async (event) => { + event.veto(this.confirmBeforeExit(), 'veto.tableDesigner'); + }); + } public _serviceBrand: undefined; private _providers = new Map(); + private async confirmBeforeExit(): Promise { + let openTableDesignerEditors = this._editorService.editors.filter(e => e instanceof TableDesignerInput); + let dirtyEditors = openTableDesignerEditors.find(e => e.isDirty()); + if (dirtyEditors) { + let result = await this._dialogService.confirm({ + message: localize('TableDesigner.saveBeforeExit', 'There are unsaved changes in Table Designer that will be lost if you close the application. Do you want to close the application?'), + primaryButton: localize({ key: 'TableDesigner.closeApplication', comment: ['&& denotes a mnemonic'] }, "&&Close Application"), + type: 'question' + }); + return !result.confirmed; + } + return false; + } + /** * Register a data grid provider */