mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-13 14:26:37 +00:00
Moved uncloseable widget tracking to manager.
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
parent
785775327b
commit
07962e81d4
@ -1,28 +1,20 @@
|
|||||||
import { injectable, inject } from '@theia/core/shared/inversify';
|
|
||||||
import { EditorWidget } from '@theia/editor/lib/browser';
|
|
||||||
import { MessageService } from '@theia/core/lib/common/message-service';
|
|
||||||
import { OutputWidget } from '@theia/output/lib/browser/output-widget';
|
|
||||||
import {
|
|
||||||
ConnectionStatusService,
|
|
||||||
ConnectionStatus,
|
|
||||||
} from '@theia/core/lib/browser/connection-status-service';
|
|
||||||
import {
|
import {
|
||||||
ApplicationShell as TheiaApplicationShell,
|
ApplicationShell as TheiaApplicationShell,
|
||||||
DockPanel,
|
DockPanel,
|
||||||
DockPanelRenderer as TheiaDockPanelRenderer,
|
DockPanelRenderer as TheiaDockPanelRenderer,
|
||||||
Panel,
|
Panel,
|
||||||
|
SaveOptions,
|
||||||
|
SHELL_TABBAR_CONTEXT_MENU,
|
||||||
TabBar,
|
TabBar,
|
||||||
Widget,
|
Widget,
|
||||||
SHELL_TABBAR_CONTEXT_MENU,
|
|
||||||
SaveOptions,
|
|
||||||
} from '@theia/core/lib/browser';
|
} from '@theia/core/lib/browser';
|
||||||
import { Sketch } from '../../../common/protocol';
|
|
||||||
import {
|
import {
|
||||||
CurrentSketch,
|
ConnectionStatus,
|
||||||
SketchesServiceClientImpl,
|
ConnectionStatusService,
|
||||||
} from '../../../common/protocol/sketches-service-client-impl';
|
} from '@theia/core/lib/browser/connection-status-service';
|
||||||
import { nls } from '@theia/core/lib/common';
|
import { nls } from '@theia/core/lib/common/nls';
|
||||||
import URI from '@theia/core/lib/common/uri';
|
import { MessageService } from '@theia/core/lib/common/message-service';
|
||||||
|
import { inject, injectable } from '@theia/core/shared/inversify';
|
||||||
import { ToolbarAwareTabBar } from './tab-bars';
|
import { ToolbarAwareTabBar } from './tab-bars';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
@ -30,40 +22,9 @@ export class ApplicationShell extends TheiaApplicationShell {
|
|||||||
@inject(MessageService)
|
@inject(MessageService)
|
||||||
private readonly messageService: MessageService;
|
private readonly messageService: MessageService;
|
||||||
|
|
||||||
@inject(SketchesServiceClientImpl)
|
|
||||||
private readonly sketchesServiceClient: SketchesServiceClientImpl;
|
|
||||||
|
|
||||||
@inject(ConnectionStatusService)
|
@inject(ConnectionStatusService)
|
||||||
private readonly connectionStatusService: ConnectionStatusService;
|
private readonly connectionStatusService: ConnectionStatusService;
|
||||||
|
|
||||||
protected override track(widget: Widget): void {
|
|
||||||
super.track(widget);
|
|
||||||
if (widget instanceof OutputWidget) {
|
|
||||||
widget.title.closable = false; // TODO: https://arduino.slack.com/archives/C01698YT7S4/p1598011990133700
|
|
||||||
}
|
|
||||||
if (widget instanceof EditorWidget) {
|
|
||||||
// Make the editor un-closeable asynchronously.
|
|
||||||
this.sketchesServiceClient.currentSketch().then((sketch) => {
|
|
||||||
if (CurrentSketch.isValid(sketch)) {
|
|
||||||
if (!this.isSketchFile(widget.editor.uri, sketch.uri)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (Sketch.isInSketch(widget.editor.uri, sketch)) {
|
|
||||||
widget.title.closable = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private isSketchFile(uri: URI, sketchUriString: string): boolean {
|
|
||||||
const sketchUri = new URI(sketchUriString);
|
|
||||||
if (uri.parent.isEqual(sketchUri)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
override async addWidget(
|
override async addWidget(
|
||||||
widget: Widget,
|
widget: Widget,
|
||||||
options: Readonly<TheiaApplicationShell.WidgetOptions> = {}
|
options: Readonly<TheiaApplicationShell.WidgetOptions> = {}
|
||||||
|
@ -7,6 +7,7 @@ import {
|
|||||||
postConstruct,
|
postConstruct,
|
||||||
} from '@theia/core/shared/inversify';
|
} from '@theia/core/shared/inversify';
|
||||||
import { EditorWidget } from '@theia/editor/lib/browser';
|
import { EditorWidget } from '@theia/editor/lib/browser';
|
||||||
|
import { OutputWidget } from '@theia/output/lib/browser/output-widget';
|
||||||
import deepEqual = require('deep-equal');
|
import deepEqual = require('deep-equal');
|
||||||
import {
|
import {
|
||||||
CurrentSketch,
|
CurrentSketch,
|
||||||
@ -21,19 +22,50 @@ export class WidgetManager extends TheiaWidgetManager {
|
|||||||
|
|
||||||
@postConstruct()
|
@postConstruct()
|
||||||
protected init(): void {
|
protected init(): void {
|
||||||
this.sketchesServiceClient.onCurrentSketchDidChange((currentSketch) => {
|
this.sketchesServiceClient.onCurrentSketchDidChange((sketch) =>
|
||||||
if (CurrentSketch.isValid(currentSketch)) {
|
this.maybeSetWidgetUncloseable(
|
||||||
const sketchFileUris = new Set(Sketch.uris(currentSketch));
|
sketch,
|
||||||
for (const widget of this.widgets.values()) {
|
...Array.from(this.widgets.values())
|
||||||
if (widget instanceof EditorWidget) {
|
)
|
||||||
const uri = widget.editor.uri.toString();
|
);
|
||||||
if (sketchFileUris.has(uri)) {
|
|
||||||
widget.title.closable = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override getOrCreateWidget<T extends Widget>(
|
||||||
|
factoryId: string,
|
||||||
|
options?: unknown
|
||||||
|
): Promise<T> {
|
||||||
|
const unresolvedWidget = super.getOrCreateWidget<T>(factoryId, options);
|
||||||
|
unresolvedWidget.then(async (widget) => {
|
||||||
|
const sketch = await this.sketchesServiceClient.currentSketch();
|
||||||
|
this.maybeSetWidgetUncloseable(sketch, widget);
|
||||||
});
|
});
|
||||||
|
return unresolvedWidget;
|
||||||
|
}
|
||||||
|
|
||||||
|
private maybeSetWidgetUncloseable(
|
||||||
|
sketch: CurrentSketch,
|
||||||
|
...widgets: Widget[]
|
||||||
|
): void {
|
||||||
|
const sketchFileUris =
|
||||||
|
CurrentSketch.isValid(sketch) && new Set(Sketch.uris(sketch));
|
||||||
|
for (const widget of widgets) {
|
||||||
|
if (widget instanceof OutputWidget) {
|
||||||
|
this.setWidgetUncloseable(widget); // TODO: https://arduino.slack.com/archives/C01698YT7S4/p1598011990133700
|
||||||
|
} else if (widget instanceof EditorWidget) {
|
||||||
|
// Make the editor un-closeable asynchronously.
|
||||||
|
const uri = widget.editor.uri.toString();
|
||||||
|
if (!!sketchFileUris && sketchFileUris.has(uri)) {
|
||||||
|
this.setWidgetUncloseable(widget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private setWidgetUncloseable(widget: Widget): void {
|
||||||
|
const { title } = widget;
|
||||||
|
if (title.closable) {
|
||||||
|
title.closable = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user