From 9ee5fc097cf5bd2338780d8dcd6d1d0113dcda7d Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Sat, 1 Aug 2020 17:07:20 +0200 Subject: [PATCH] fixed closeable state. Signed-off-by: Akos Kitta --- .../browser/theia/core/application-shell.ts | 32 +++++++------------ .../src/common/protocol/sketches-service.ts | 2 +- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/arduino-ide-extension/src/browser/theia/core/application-shell.ts b/arduino-ide-extension/src/browser/theia/core/application-shell.ts index aee7cb2c..1822c6db 100644 --- a/arduino-ide-extension/src/browser/theia/core/application-shell.ts +++ b/arduino-ide-extension/src/browser/theia/core/application-shell.ts @@ -20,32 +20,24 @@ export class ApplicationShell extends TheiaApplicationShell { @inject(SketchesServiceClientImpl) protected readonly sketchesServiceClient: SketchesServiceClientImpl; - protected sketch?: Sketch; - - async addWidget(widget: Widget, options: Readonly = {}): Promise { - // 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 { - // I could not find other ways to get sketch in async fashion for sync `track`. - this.sketch = await this.sketchesServiceClient.currentSketch(); - super.setLayoutData(layoutData); - } - protected 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); + if (!this.editorMode.proMode && widget instanceof EditorWidget) { + // Make the editor un-closeable asynchronously. + this.sketchesServiceClient.currentSketch().then(sketch => { + if (sketch) { + if (Sketch.isInSketch(widget.editor.uri, sketch)) { + widget.title.closable = false; + } + } + }); + } } async saveAll(): Promise { await super.saveAll(); - await this.commandService.executeCommand(SaveAsSketch.Commands.SAVE_AS_SKETCH.id, { execOnlyIfTemp: true, openAfterMove: true }); + const options = { execOnlyIfTemp: true, openAfterMove: true }; + await this.commandService.executeCommand(SaveAsSketch.Commands.SAVE_AS_SKETCH.id, options); } } diff --git a/arduino-ide-extension/src/common/protocol/sketches-service.ts b/arduino-ide-extension/src/common/protocol/sketches-service.ts index 8b8cbefe..0631bf19 100644 --- a/arduino-ide-extension/src/common/protocol/sketches-service.ts +++ b/arduino-ide-extension/src/common/protocol/sketches-service.ts @@ -64,7 +64,7 @@ export namespace Sketch { } export function isInSketch(uri: string | URI, sketch: Sketch): boolean { const { mainFileUri, otherSketchFileUris, additionalFileUris } = sketch; - return [mainFileUri, ...otherSketchFileUris, additionalFileUris].indexOf(uri.toString()) !== -1; + return [mainFileUri, ...otherSketchFileUris, ...additionalFileUris].indexOf(uri.toString()) !== -1; } }