From fb11a223d0da1ac591189c6a21eeb87c17fd102f Mon Sep 17 00:00:00 2001 From: colin-grant-work Date: Wed, 5 Oct 2022 07:54:28 -0600 Subject: [PATCH] Add confirmation message for debug exit (debug.confirmOnExit) (#11546) * Add confirmation message for debug exit * Use veto system for WorkspaceService.close() --- ...debug-frontend-application-contribution.ts | 30 ++++++++++++++++--- .../workspace-frontend-contribution.ts | 10 ++----- .../src/browser/workspace-service.ts | 12 +++++--- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/packages/debug/src/browser/debug-frontend-application-contribution.ts b/packages/debug/src/browser/debug-frontend-application-contribution.ts index c423322445897..4e90f9f699abf 100644 --- a/packages/debug/src/browser/debug-frontend-application-contribution.ts +++ b/packages/debug/src/browser/debug-frontend-application-contribution.ts @@ -14,7 +14,9 @@ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 // ***************************************************************************** -import { AbstractViewContribution, KeybindingRegistry, Widget, CompositeTreeNode, LabelProvider, codicon } from '@theia/core/lib/browser'; +import { + AbstractViewContribution, KeybindingRegistry, Widget, CompositeTreeNode, LabelProvider, codicon, OnWillStopAction, FrontendApplicationContribution, ConfirmDialog, Dialog +} from '@theia/core/lib/browser'; import { injectable, inject } from '@theia/core/shared/inversify'; import * as monaco from '@theia/monaco-editor-core'; import { MenuModelRegistry, CommandRegistry, MAIN_MENU_BAR, Command, Emitter, Mutable } from '@theia/core/lib/common'; @@ -380,7 +382,8 @@ export namespace DebugBreakpointWidgetCommands { } @injectable() -export class DebugFrontendApplicationContribution extends AbstractViewContribution implements TabBarToolbarContribution, ColorContribution { +export class DebugFrontendApplicationContribution extends AbstractViewContribution + implements TabBarToolbarContribution, ColorContribution, FrontendApplicationContribution { @inject(DebugService) protected readonly debug: DebugService; @@ -473,8 +476,27 @@ export class DebugFrontendApplicationContribution extends AbstractViewContributi this.watchManager.save(); } - onWillStop(): boolean { - return this.preference['debug.confirmOnExit'] === 'always' && !!this.manager.currentSession; + onWillStop(): OnWillStopAction | undefined { + if (this.preference['debug.confirmOnExit'] === 'always' && this.manager.currentSession) { + return { + reason: 'active-debug-sessions', + action: async () => { + if (this.manager.currentSession) { + const msg = this.manager.sessions.length === 1 + ? nls.localize('theia/debug/debugSessionActive', 'There is an active debug session, are you sure you want to stop it?') + : nls.localize('theia/debug/debugSessionActiveMultiple', 'There are active debug sessions, are you sure you want to stop them?'); + const safeToExit = await new ConfirmDialog({ + title: '', + msg, + ok: nls.localizeByDefault('Stop Debugging'), + cancel: Dialog.CANCEL, + }).open(); + return safeToExit === true; + } + return true; + }, + }; + } } override registerMenus(menus: MenuModelRegistry): void { diff --git a/packages/workspace/src/browser/workspace-frontend-contribution.ts b/packages/workspace/src/browser/workspace-frontend-contribution.ts index 81c5f05b4c08e..02379668d7b5a 100644 --- a/packages/workspace/src/browser/workspace-frontend-contribution.ts +++ b/packages/workspace/src/browser/workspace-frontend-contribution.ts @@ -18,7 +18,7 @@ import { injectable, inject } from '@theia/core/shared/inversify'; import { CommandContribution, CommandRegistry, MenuContribution, MenuModelRegistry, MessageService, isWindows, MaybeArray } from '@theia/core/lib/common'; import { isOSX, environment, OS } from '@theia/core'; import { - open, OpenerService, CommonMenus, ConfirmDialog, KeybindingRegistry, KeybindingContribution, + open, OpenerService, CommonMenus, KeybindingRegistry, KeybindingContribution, FrontendApplicationContribution, SHELL_TABBAR_CONTEXT_COPY, OnWillStopAction, Navigatable, SaveableSource, Widget } from '@theia/core/lib/browser'; import { FileDialogService, OpenFileDialogProps, FileDialogTreeFilters } from '@theia/filesystem/lib/browser'; @@ -403,13 +403,7 @@ export class WorkspaceFrontendContribution implements CommandContribution, Keybi } protected async closeWorkspace(): Promise { - const dialog = new ConfirmDialog({ - title: WorkspaceCommands.CLOSE.label!, - msg: nls.localize('theia/workspace/closeWorkspace', 'Do you really want to close the workspace?') - }); - if (await dialog.open()) { - await this.workspaceService.close(); - } + await this.workspaceService.close(); } /** diff --git a/packages/workspace/src/browser/workspace-service.ts b/packages/workspace/src/browser/workspace-service.ts index 656ba40c14b14..269049dd5e065 100644 --- a/packages/workspace/src/browser/workspace-service.ts +++ b/packages/workspace/src/browser/workspace-service.ts @@ -34,6 +34,7 @@ import { WindowTitleService } from '@theia/core/lib/browser/window/window-title- import { FileSystemPreferences } from '@theia/filesystem/lib/browser'; import { workspaceSchema, WorkspaceSchemaUpdater } from './workspace-schema-updater'; import { IJSONSchema } from '@theia/core/lib/common/json-schema'; +import { StopReason } from '@theia/core/lib/common/frontend-application-state'; /** * The workspace service. @@ -464,11 +465,14 @@ export class WorkspaceService implements FrontendApplicationContribution { * Clears current workspace root. */ async close(): Promise { - this._workspace = undefined; - this._roots.length = 0; + if (await this.windowService.isSafeToShutDown(StopReason.Reload)) { + this.windowService.setSafeToShutDown(); + this._workspace = undefined; + this._roots.length = 0; - await this.server.setMostRecentlyUsedWorkspace(''); - this.reloadWindow(); + await this.server.setMostRecentlyUsedWorkspace(''); + this.reloadWindow(); + } } /**