1
1
import { inject , injectable } from '@theia/core/shared/inversify' ;
2
- import { toArray } from '@theia/core/shared/@phosphor/algorithm' ;
3
2
import * as remote from '@theia/core/electron-shared/@electron/remote' ;
4
3
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor' ;
5
4
import { EditorManager } from '@theia/editor/lib/browser/editor-manager' ;
6
5
import { ApplicationShell } from '@theia/core/lib/browser/shell/application-shell' ;
7
6
import { FrontendApplication } from '@theia/core/lib/browser/frontend-application' ;
8
7
import { ArduinoMenus } from '../menu/arduino-menus' ;
9
- import { SaveAsSketch } from './save-as-sketch' ;
10
8
import {
11
9
SketchContribution ,
12
10
Command ,
@@ -33,76 +31,7 @@ export class Close extends SketchContribution {
33
31
34
32
registerCommands ( registry : CommandRegistry ) : void {
35
33
registry . registerCommand ( Close . Commands . CLOSE , {
36
- execute : async ( ) => {
37
- // Close current editor if closeable.
38
- const { currentEditor } = this . editorManager ;
39
- if ( currentEditor && currentEditor . title . closable ) {
40
- currentEditor . close ( ) ;
41
- return ;
42
- }
43
-
44
- // Close current widget from the main area if possible.
45
- const { currentWidget } = this . shell ;
46
- if ( currentWidget ) {
47
- const currentWidgetInMain = toArray (
48
- this . shell . mainPanel . widgets ( )
49
- ) . find ( ( widget ) => widget === currentWidget ) ;
50
- if ( currentWidgetInMain && currentWidgetInMain . title . closable ) {
51
- return currentWidgetInMain . close ( ) ;
52
- }
53
- }
54
-
55
- // Close the sketch (window).
56
- const sketch = await this . sketchServiceClient . currentSketch ( ) ;
57
- if ( ! sketch ) {
58
- return ;
59
- }
60
- const isTemp = await this . sketchService . isTemp ( sketch ) ;
61
- const uri = await this . sketchServiceClient . currentSketchFile ( ) ;
62
- if ( ! uri ) {
63
- return ;
64
- }
65
- if ( isTemp && ( await this . wasTouched ( uri ) ) ) {
66
- const { response } = await remote . dialog . showMessageBox ( {
67
- type : 'question' ,
68
- buttons : [
69
- nls . localize (
70
- 'vscode/abstractTaskService/saveBeforeRun.dontSave' ,
71
- "Don't Save"
72
- ) ,
73
- nls . localize ( 'vscode/issueMainService/cancel' , 'Cancel' ) ,
74
- nls . localize (
75
- 'vscode/abstractTaskService/saveBeforeRun.save' ,
76
- 'Save'
77
- ) ,
78
- ] ,
79
- message : nls . localize (
80
- 'arduino/common/saveChangesToSketch' ,
81
- 'Do you want to save changes to this sketch before closing?'
82
- ) ,
83
- detail : nls . localize (
84
- 'arduino/common/loseChanges' ,
85
- "If you don't save, your changes will be lost."
86
- ) ,
87
- } ) ;
88
- if ( response === 1 ) {
89
- // Cancel
90
- return ;
91
- }
92
- if ( response === 2 ) {
93
- // Save
94
- const saved = await this . commandService . executeCommand (
95
- SaveAsSketch . Commands . SAVE_AS_SKETCH . id ,
96
- { openAfterMove : false , execOnlyIfTemp : true }
97
- ) ;
98
- if ( ! saved ) {
99
- // If it was not saved, do bail the close.
100
- return ;
101
- }
102
- }
103
- }
104
- window . close ( ) ;
105
- } ,
34
+ execute : ( ) => remote . getCurrentWindow ( ) . close ( )
106
35
} ) ;
107
36
}
108
37
0 commit comments