Update currentSketch when files change.

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
Akos Kitta
2022-08-25 13:32:47 +02:00
committed by Akos Kitta
parent 5b79320302
commit 0c87fa9877
3 changed files with 84 additions and 9 deletions

View File

@@ -1,11 +1,41 @@
import type { MaybePromise } from '@theia/core';
import type { Widget } from '@theia/core/lib/browser';
import { WidgetManager as TheiaWidgetManager } from '@theia/core/lib/browser/widget-manager';
import { injectable } from '@theia/core/shared/inversify';
import {
inject,
injectable,
postConstruct,
} from '@theia/core/shared/inversify';
import { EditorWidget } from '@theia/editor/lib/browser';
import deepEqual = require('deep-equal');
import {
CurrentSketch,
SketchesServiceClientImpl,
} from '../../../common/protocol/sketches-service-client-impl';
import { Sketch } from '../../contributions/contribution';
@injectable()
export class WidgetManager extends TheiaWidgetManager {
@inject(SketchesServiceClientImpl)
private readonly sketchesServiceClient: SketchesServiceClientImpl;
@postConstruct()
protected init(): void {
this.sketchesServiceClient.onCurrentSketchDidChange((currentSketch) => {
if (CurrentSketch.isValid(currentSketch)) {
const sketchFileUris = new Set(Sketch.uris(currentSketch));
for (const widget of this.widgets.values()) {
if (widget instanceof EditorWidget) {
const uri = widget.editor.uri.toString();
if (sketchFileUris.has(uri)) {
widget.title.closable = false;
}
}
}
}
});
}
/**
* Customized to find any existing widget based on `options` deepEquals instead of string equals.
* See https://github.com/eclipse-theia/theia/issues/11309.