Skip to content

Commit 07962e8

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
Moved uncloseable widget tracking to manager.
Signed-off-by: Akos Kitta <[email protected]>
1 parent 7857753 commit 07962e8

File tree

2 files changed

+51
-58
lines changed

2 files changed

+51
-58
lines changed

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

+8-47
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,30 @@
1-
import { injectable, inject } from '@theia/core/shared/inversify';
2-
import { EditorWidget } from '@theia/editor/lib/browser';
3-
import { MessageService } from '@theia/core/lib/common/message-service';
4-
import { OutputWidget } from '@theia/output/lib/browser/output-widget';
5-
import {
6-
ConnectionStatusService,
7-
ConnectionStatus,
8-
} from '@theia/core/lib/browser/connection-status-service';
91
import {
102
ApplicationShell as TheiaApplicationShell,
113
DockPanel,
124
DockPanelRenderer as TheiaDockPanelRenderer,
135
Panel,
6+
SaveOptions,
7+
SHELL_TABBAR_CONTEXT_MENU,
148
TabBar,
159
Widget,
16-
SHELL_TABBAR_CONTEXT_MENU,
17-
SaveOptions,
1810
} from '@theia/core/lib/browser';
19-
import { Sketch } from '../../../common/protocol';
2011
import {
21-
CurrentSketch,
22-
SketchesServiceClientImpl,
23-
} from '../../../common/protocol/sketches-service-client-impl';
24-
import { nls } from '@theia/core/lib/common';
25-
import URI from '@theia/core/lib/common/uri';
12+
ConnectionStatus,
13+
ConnectionStatusService,
14+
} from '@theia/core/lib/browser/connection-status-service';
15+
import { nls } from '@theia/core/lib/common/nls';
16+
import { MessageService } from '@theia/core/lib/common/message-service';
17+
import { inject, injectable } from '@theia/core/shared/inversify';
2618
import { ToolbarAwareTabBar } from './tab-bars';
2719

2820
@injectable()
2921
export class ApplicationShell extends TheiaApplicationShell {
3022
@inject(MessageService)
3123
private readonly messageService: MessageService;
3224

33-
@inject(SketchesServiceClientImpl)
34-
private readonly sketchesServiceClient: SketchesServiceClientImpl;
35-
3625
@inject(ConnectionStatusService)
3726
private readonly connectionStatusService: ConnectionStatusService;
3827

39-
protected override track(widget: Widget): void {
40-
super.track(widget);
41-
if (widget instanceof OutputWidget) {
42-
widget.title.closable = false; // TODO: https://arduino.slack.com/archives/C01698YT7S4/p1598011990133700
43-
}
44-
if (widget instanceof EditorWidget) {
45-
// Make the editor un-closeable asynchronously.
46-
this.sketchesServiceClient.currentSketch().then((sketch) => {
47-
if (CurrentSketch.isValid(sketch)) {
48-
if (!this.isSketchFile(widget.editor.uri, sketch.uri)) {
49-
return;
50-
}
51-
if (Sketch.isInSketch(widget.editor.uri, sketch)) {
52-
widget.title.closable = false;
53-
}
54-
}
55-
});
56-
}
57-
}
58-
59-
private isSketchFile(uri: URI, sketchUriString: string): boolean {
60-
const sketchUri = new URI(sketchUriString);
61-
if (uri.parent.isEqual(sketchUri)) {
62-
return true;
63-
}
64-
return false;
65-
}
66-
6728
override async addWidget(
6829
widget: Widget,
6930
options: Readonly<TheiaApplicationShell.WidgetOptions> = {}

Diff for: arduino-ide-extension/src/browser/theia/core/widget-manager.ts

+43-11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
postConstruct,
88
} from '@theia/core/shared/inversify';
99
import { EditorWidget } from '@theia/editor/lib/browser';
10+
import { OutputWidget } from '@theia/output/lib/browser/output-widget';
1011
import deepEqual = require('deep-equal');
1112
import {
1213
CurrentSketch,
@@ -21,19 +22,50 @@ export class WidgetManager extends TheiaWidgetManager {
2122

2223
@postConstruct()
2324
protected init(): void {
24-
this.sketchesServiceClient.onCurrentSketchDidChange((currentSketch) => {
25-
if (CurrentSketch.isValid(currentSketch)) {
26-
const sketchFileUris = new Set(Sketch.uris(currentSketch));
27-
for (const widget of this.widgets.values()) {
28-
if (widget instanceof EditorWidget) {
29-
const uri = widget.editor.uri.toString();
30-
if (sketchFileUris.has(uri)) {
31-
widget.title.closable = false;
32-
}
33-
}
25+
this.sketchesServiceClient.onCurrentSketchDidChange((sketch) =>
26+
this.maybeSetWidgetUncloseable(
27+
sketch,
28+
...Array.from(this.widgets.values())
29+
)
30+
);
31+
}
32+
33+
override getOrCreateWidget<T extends Widget>(
34+
factoryId: string,
35+
options?: unknown
36+
): Promise<T> {
37+
const unresolvedWidget = super.getOrCreateWidget<T>(factoryId, options);
38+
unresolvedWidget.then(async (widget) => {
39+
const sketch = await this.sketchesServiceClient.currentSketch();
40+
this.maybeSetWidgetUncloseable(sketch, widget);
41+
});
42+
return unresolvedWidget;
43+
}
44+
45+
private maybeSetWidgetUncloseable(
46+
sketch: CurrentSketch,
47+
...widgets: Widget[]
48+
): void {
49+
const sketchFileUris =
50+
CurrentSketch.isValid(sketch) && new Set(Sketch.uris(sketch));
51+
for (const widget of widgets) {
52+
if (widget instanceof OutputWidget) {
53+
this.setWidgetUncloseable(widget); // TODO: https://arduino.slack.com/archives/C01698YT7S4/p1598011990133700
54+
} else if (widget instanceof EditorWidget) {
55+
// Make the editor un-closeable asynchronously.
56+
const uri = widget.editor.uri.toString();
57+
if (!!sketchFileUris && sketchFileUris.has(uri)) {
58+
this.setWidgetUncloseable(widget);
3459
}
3560
}
36-
});
61+
}
62+
}
63+
64+
private setWidgetUncloseable(widget: Widget): void {
65+
const { title } = widget;
66+
if (title.closable) {
67+
title.closable = false;
68+
}
3769
}
3870

3971
/**

0 commit comments

Comments
 (0)