File tree 2 files changed +72
-0
lines changed
arduino-ide-extension/src
electron-browser/theia/core
2 files changed +72
-0
lines changed Original file line number Diff line number Diff line change @@ -17,9 +17,11 @@ import {
17
17
DisposableCollection ,
18
18
} from '@theia/core' ;
19
19
import {
20
+ Dialog ,
20
21
FrontendApplication ,
21
22
FrontendApplicationContribution ,
22
23
LocalStorageService ,
24
+ OnWillStopAction ,
23
25
SaveableWidget ,
24
26
StatusBar ,
25
27
StatusBarAlignment ,
@@ -659,4 +661,51 @@ export class ArduinoFrontendContribution
659
661
}
660
662
) ;
661
663
}
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
+ }
662
711
}
Original file line number Diff line number Diff line change @@ -11,6 +11,29 @@ import { MainMenuManager } from '../../../common/main-menu-manager';
11
11
import { ElectronWindowService } from '../../electron-window-service' ;
12
12
import { ElectronMainMenuFactory } from './electron-main-menu-factory' ;
13
13
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
+ } ) ;
14
37
15
38
export default new ContainerModule ( ( bind , unbind , isBound , rebind ) => {
16
39
bind ( ElectronMenuContribution ) . toSelf ( ) . inSingletonScope ( ) ;
You can’t perform that action at this time.
0 commit comments