Skip to content

Commit 9ee5fc0

Browse files
author
Akos Kitta
committed
fixed closeable state.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent f375202 commit 9ee5fc0

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

arduino-ide-extension/src/browser/theia/core/application-shell.ts

+12-20
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,24 @@ export class ApplicationShell extends TheiaApplicationShell {
2020
@inject(SketchesServiceClientImpl)
2121
protected readonly sketchesServiceClient: SketchesServiceClientImpl;
2222

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-
3723
protected 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;
41-
}
42-
}
4324
super.track(widget);
25+
if (!this.editorMode.proMode && widget instanceof EditorWidget) {
26+
// Make the editor un-closeable asynchronously.
27+
this.sketchesServiceClient.currentSketch().then(sketch => {
28+
if (sketch) {
29+
if (Sketch.isInSketch(widget.editor.uri, sketch)) {
30+
widget.title.closable = false;
31+
}
32+
}
33+
});
34+
}
4435
}
4536

4637
async saveAll(): Promise<void> {
4738
await super.saveAll();
48-
await this.commandService.executeCommand(SaveAsSketch.Commands.SAVE_AS_SKETCH.id, { execOnlyIfTemp: true, openAfterMove: true });
39+
const options = { execOnlyIfTemp: true, openAfterMove: true };
40+
await this.commandService.executeCommand(SaveAsSketch.Commands.SAVE_AS_SKETCH.id, options);
4941
}
5042

5143
}

arduino-ide-extension/src/common/protocol/sketches-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export namespace Sketch {
6464
}
6565
export function isInSketch(uri: string | URI, sketch: Sketch): boolean {
6666
const { mainFileUri, otherSketchFileUris, additionalFileUris } = sketch;
67-
return [mainFileUri, ...otherSketchFileUris, additionalFileUris].indexOf(uri.toString()) !== -1;
67+
return [mainFileUri, ...otherSketchFileUris, ...additionalFileUris].indexOf(uri.toString()) !== -1;
6868
}
6969
}
7070

0 commit comments

Comments
 (0)