From 9bbed2c275d91e5da8fd5cda9b5f74c07550a099 Mon Sep 17 00:00:00 2001 From: Alan Ren Date: Wed, 7 Nov 2018 12:00:51 -0800 Subject: [PATCH] fix for issue 3157 (#3158) * fix for issue 3157 * use state instead of _state --- .../parts/profiler/editor/profilerInput.ts | 49 ++++++++++++------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/src/sql/parts/profiler/editor/profilerInput.ts b/src/sql/parts/profiler/editor/profilerInput.ts index 6d8e0d8bf6..2d3b00ed21 100644 --- a/src/sql/parts/profiler/editor/profilerInput.ts +++ b/src/sql/parts/profiler/editor/profilerInput.ts @@ -12,7 +12,7 @@ import * as sqlops from 'sqlops'; import * as nls from 'vs/nls'; import { TPromise } from 'vs/base/common/winjs.base'; -import { EditorInput } from 'vs/workbench/common/editor'; +import { EditorInput, ConfirmResult } from 'vs/workbench/common/editor'; import { IEditorModel } from 'vs/platform/editor/common/editor'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { INotificationService } from 'vs/platform/notification/common/notification'; @@ -22,6 +22,7 @@ import { IDialogService, IConfirmation, IConfirmationResult } from 'vs/platform/ import { escape } from 'sql/base/common/strings'; import * as types from 'vs/base/common/types'; import URI from 'vs/base/common/uri'; +import Severity from 'vs/base/common/severity'; export class ProfilerInput extends EditorInput implements IProfilerSession { @@ -72,23 +73,6 @@ export class ProfilerInput extends EditorInput implements IProfilerSession { return ret; }; this._data = new TableDataView(undefined, searchFn); - - this.onDispose(() => { - if (this._state.isRunning || this.state.isPaused) { - let confirm: IConfirmation = { - message: nls.localize('confirmStopProfilerSession', "Would you like to stop the running XEvent session?"), - primaryButton: nls.localize('profilerClosingActions.yes', 'Yes'), - secondaryButton: nls.localize('profilerClosingActions.no', 'No'), - type: 'question' - }; - - this._dialogService.confirm(confirm).then(result => { - if (result.confirmed) { - this._profilerService.stopSession(this.id); - } - }); - } - }); } public get providerType(): string { @@ -118,7 +102,7 @@ export class ProfilerInput extends EditorInput implements IProfilerSession { } public set sessionName(name: string) { - if (!this._state.isRunning || !this.state.isPaused) { + if (!this.state.isRunning || !this.state.isPaused) { this._sessionName = name; } } @@ -268,4 +252,31 @@ export class ProfilerInput extends EditorInput implements IProfilerSession { } } + + confirmSave(): TPromise { + if (this.state.isRunning || this.state.isPaused) { + return this._dialogService.show(Severity.Warning, + nls.localize('confirmStopProfilerSession', "Would you like to stop the running XEvent session?"), + [ + nls.localize('profilerClosingActions.yes', 'Yes'), + nls.localize('profilerClosingActions.no', 'No'), + nls.localize('profilerClosingActions.cancel', 'Cancel') + ]).then((selection: number) => { + if (selection === 0) { + this._profilerService.stopSession(this.id); + return ConfirmResult.DONT_SAVE; + } else if (selection === 1) { + return ConfirmResult.DONT_SAVE; + } else { + return ConfirmResult.CANCEL; + } + });; + } else { + return TPromise.wrap(ConfirmResult.DONT_SAVE); + } + } + + isDirty(): boolean { + return this.state.isRunning || this.state.isPaused; + } }