fixed closeable state.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta 2020-08-01 17:07:20 +02:00
parent f375202c5d
commit 9ee5fc097c
2 changed files with 13 additions and 21 deletions

View File

@ -20,32 +20,24 @@ export class ApplicationShell extends TheiaApplicationShell {
@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);
}
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<void> {
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);
}
}

View File

@ -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;
}
}