-
-
Notifications
You must be signed in to change notification settings - Fork 439
/
Copy pathapplication-shell.ts
52 lines (40 loc) · 1.99 KB
/
application-shell.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { injectable, inject } from 'inversify';
import { EditorWidget } from '@theia/editor/lib/browser';
import { CommandService } from '@theia/core/lib/common/command';
import { ApplicationShell as TheiaApplicationShell, Widget } from '@theia/core/lib/browser';
import { Sketch } from '../../../common/protocol';
import { EditorMode } from '../../editor-mode';
import { SaveAsSketch } from '../../contributions/save-as-sketch';
import { SketchesServiceClientImpl } from '../../../common/protocol/sketches-service-client-impl';
@injectable()
export class ApplicationShell extends TheiaApplicationShell {
@inject(EditorMode)
protected readonly editorMode: EditorMode;
@inject(CommandService)
protected readonly commandService: CommandService;
@inject(SketchesServiceClientImpl)
protected readonly sketchesServiceClient: SketchesServiceClientImpl;
protected sketch?: Sketch;
async addWidget(widget: Widget, options: Readonly<TheiaApplicationShell.WidgetOptions> = {}): Promise<void> {
// Get the current sketch before adding a widget. This wil trigger an update.
this.sketch = await this.sketchesServiceClient.currentSketch();
super.addWidget(widget, options);
}
async setLayoutData(layoutData: TheiaApplicationShell.LayoutData): Promise<void> {
// I could not find other ways to get sketch in async fashion for sync `track`.
this.sketch = await this.sketchesServiceClient.currentSketch();
super.setLayoutData(layoutData);
}
track(widget: Widget): void {
if (!this.editorMode.proMode && this.sketch && widget instanceof EditorWidget) {
if (Sketch.isInSketch(widget.editor.uri, this.sketch)) {
widget.title.closable = false;
}
}
super.track(widget);
}
async saveAll(): Promise<void> {
await super.saveAll();
await this.commandService.executeCommand(SaveAsSketch.Commands.SAVE_AS_SKETCH.id, { execOnlyIfTemp: true, openAfterMove: true });
}
}