2
2
import { injectable , inject } from 'inversify' ;
3
3
import { EditorWidget } from '@theia/editor/lib/browser' ;
4
4
import { CommandService } from '@theia/core/lib/common/command' ;
5
- import { PreferencesWidget } from '@theia/preferences/lib/browser/views/preference-widget' ;
6
5
import { ApplicationShell as TheiaApplicationShell , Widget } from '@theia/core/lib/browser' ;
6
+ import { Sketch } from '../../../common/protocol' ;
7
7
import { EditorMode } from '../../editor-mode' ;
8
8
import { SaveAsSketch } from '../../contributions/save-as-sketch' ;
9
+ import { SketchesServiceClientImpl } from '../../../common/protocol/sketches-service-client-impl' ;
9
10
10
11
@injectable ( )
11
12
export class ApplicationShell extends TheiaApplicationShell {
@@ -16,26 +17,33 @@ export class ApplicationShell extends TheiaApplicationShell {
16
17
@inject ( CommandService )
17
18
protected readonly commandService : CommandService ;
18
19
19
- protected track ( widget : Widget ) : void {
20
- super . track ( widget ) ;
21
- if ( ! this . editorMode . proMode ) {
22
- if ( widget instanceof EditorWidget ) {
23
- // Always allow closing the whitelisted files.
24
- // TODO: It would be better to blacklist the sketch files only.
25
- if ( [ 'tasks.json' ,
26
- 'launch.json' ,
27
- 'settings.json' ,
28
- 'arduino-cli.yaml' ] . some ( fileName => widget . editor . uri . toString ( ) . endsWith ( fileName ) ) ) {
29
- return ;
30
- }
31
- }
32
- if ( widget instanceof PreferencesWidget ) {
33
- return ;
20
+ @inject ( SketchesServiceClientImpl )
21
+ protected readonly sketchesServiceClient : SketchesServiceClientImpl ;
22
+
23
+ protected sketch ?: Sketch ;
24
+
25
+ async addWidget ( widget : Widget , options : Readonly < TheiaApplicationShell . WidgetOptions > = { } ) : Promise < void > {
26
+ // Get the current sketch before adding a widget. This wil trigger an update.
27
+ this . sketch = await this . sketchesServiceClient . currentSketch ( ) ;
28
+ super . addWidget ( widget , options ) ;
29
+ }
30
+
31
+ async setLayoutData ( layoutData : TheiaApplicationShell . LayoutData ) : Promise < void > {
32
+ // I could not find other ways to get sketch in async fashion for sync `track`.
33
+ this . sketch = await this . sketchesServiceClient . currentSketch ( ) ;
34
+ super . setLayoutData ( layoutData ) ;
35
+ }
36
+
37
+ track ( widget : Widget ) : void {
38
+ if ( ! this . editorMode . proMode && this . sketch && widget instanceof EditorWidget ) {
39
+ if ( Sketch . isInSketch ( widget . editor . uri , this . sketch ) ) {
40
+ widget . title . closable = false ;
34
41
}
35
- widget . title . closable = false ;
36
42
}
43
+ super . track ( widget ) ;
37
44
}
38
45
46
+
39
47
async saveAll ( ) : Promise < void > {
40
48
await super . saveAll ( ) ;
41
49
await this . commandService . executeCommand ( SaveAsSketch . Commands . SAVE_AS_SKETCH . id , { execOnlyIfTemp : true , openAfterMove : true } ) ;
0 commit comments