Skip to content

Commit

Permalink
Add confirmation message for debug exit (debug.confirmOnExit) (#11546)
Browse files Browse the repository at this point in the history
* Add confirmation message for debug exit
* Use veto system for WorkspaceService.close()
  • Loading branch information
colin-grant-work authored Oct 5, 2022
1 parent c1a3f0b commit fb11a22
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -380,7 +382,8 @@ export namespace DebugBreakpointWidgetCommands {
}

@injectable()
export class DebugFrontendApplicationContribution extends AbstractViewContribution<DebugWidget> implements TabBarToolbarContribution, ColorContribution {
export class DebugFrontendApplicationContribution extends AbstractViewContribution<DebugWidget>
implements TabBarToolbarContribution, ColorContribution, FrontendApplicationContribution {

@inject(DebugService)
protected readonly debug: DebugService;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -403,13 +403,7 @@ export class WorkspaceFrontendContribution implements CommandContribution, Keybi
}

protected async closeWorkspace(): Promise<void> {
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();
}

/**
Expand Down
12 changes: 8 additions & 4 deletions packages/workspace/src/browser/workspace-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -464,11 +465,14 @@ export class WorkspaceService implements FrontendApplicationContribution {
* Clears current workspace root.
*/
async close(): Promise<void> {
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();
}
}

/**
Expand Down

0 comments on commit fb11a22

Please sign in to comment.