Skip to content

Commit 1c82e25

Browse files
committed
Use normal OnWillStop event
1 parent 522a5c6 commit 1c82e25

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

+49
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ import {
1717
DisposableCollection,
1818
} from '@theia/core';
1919
import {
20+
Dialog,
2021
FrontendApplication,
2122
FrontendApplicationContribution,
2223
LocalStorageService,
24+
OnWillStopAction,
2325
SaveableWidget,
2426
StatusBar,
2527
StatusBarAlignment,
@@ -659,4 +661,51 @@ export class ArduinoFrontendContribution
659661
}
660662
);
661663
}
664+
665+
onWillStop(): OnWillStopAction {
666+
return {
667+
reason: 'temp-sketch',
668+
action: () => {
669+
return this.showTempSketchDialog();
670+
}
671+
}
672+
}
673+
674+
private async showTempSketchDialog(): Promise<boolean> {
675+
const sketch = await this.sketchServiceClient.currentSketch();
676+
if (!sketch) {
677+
return true;
678+
}
679+
const isTemp = await this.sketchService.isTemp(sketch);
680+
if (!isTemp) {
681+
return true;
682+
}
683+
const messageBoxResult = await remote.dialog.showMessageBox(
684+
remote.getCurrentWindow(),
685+
{
686+
message: nls.localize('arduino/sketch/saveTempSketch', 'Save your sketch to open it again later.'),
687+
title: nls.localize('theia/core/quitTitle', 'Are you sure you want to quit?'),
688+
type: 'question',
689+
buttons: [
690+
Dialog.CANCEL,
691+
nls.localizeByDefault('Save As...'),
692+
nls.localizeByDefault("Don't Save"),
693+
],
694+
}
695+
)
696+
const result = messageBoxResult.response;
697+
if (result === 2) {
698+
return true;
699+
} else if (result === 1) {
700+
return !!(await this.commandRegistry.executeCommand(
701+
SaveAsSketch.Commands.SAVE_AS_SKETCH.id,
702+
{
703+
execOnlyIfTemp: false,
704+
openAfterMove: false,
705+
wipeOriginal: true
706+
}
707+
));
708+
}
709+
return false
710+
}
662711
}

arduino-ide-extension/src/electron-browser/theia/core/electron-menu-module.ts

+23
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,29 @@ import { MainMenuManager } from '../../../common/main-menu-manager';
1111
import { ElectronWindowService } from '../../electron-window-service';
1212
import { ElectronMainMenuFactory } from './electron-main-menu-factory';
1313
import { ElectronMenuContribution } from './electron-menu-contribution';
14+
import { nls } from '@theia/core/lib/common/nls';
15+
16+
import * as remote from '@theia/core/electron-shared/@electron/remote';
17+
import * as dialogs from '@theia/core/lib/browser/dialogs';
18+
19+
20+
Object.assign(dialogs, {
21+
confirmExit: async () => {
22+
const messageBoxResult = await remote.dialog.showMessageBox(
23+
remote.getCurrentWindow(),
24+
{
25+
message: nls.localize('theia/core/quitMessage', 'Any unsaved changes will not be saved.'),
26+
title: nls.localize('theia/core/quitTitle', 'Are you sure you want to quit?'),
27+
type: 'question',
28+
buttons: [
29+
dialogs.Dialog.CANCEL,
30+
dialogs.Dialog.YES,
31+
],
32+
}
33+
)
34+
return messageBoxResult.response === 1;
35+
}
36+
});
1437

1538
export default new ContainerModule((bind, unbind, isBound, rebind) => {
1639
bind(ElectronMenuContribution).toSelf().inSingletonScope();

0 commit comments

Comments
 (0)