- Notifications
You must be signed in to change notification settings - Fork 440
/
Copy pathwidget-manager.ts
73 lines (68 loc) · 2.4 KB
/
widget-manager.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
importtype{Widget}from'@theia/core/lib/browser';
import{WidgetManagerasTheiaWidgetManager}from'@theia/core/lib/browser/widget-manager';
import{
inject,
injectable,
postConstruct,
}from'@theia/core/shared/inversify';
import{EditorWidget}from'@theia/editor/lib/browser';
import{OutputWidget}from'@theia/output/lib/browser/output-widget';
import{
CurrentSketch,
SketchesServiceClientImpl,
}from'../../sketches-service-client-impl';
@injectable()
exportclassWidgetManagerextendsTheiaWidgetManager{
@inject(SketchesServiceClientImpl)
privatereadonlysketchesServiceClient: SketchesServiceClientImpl;
@postConstruct()
protectedinit(): void{
this.sketchesServiceClient.onCurrentSketchDidChange((sketch)=>
this.maybeSetWidgetUncloseable(
sketch,
...Array.from(this.widgets.values())
)
);
}
overridegetOrCreateWidget<TextendsWidget>(
factoryId: string,
options?: unknown
): Promise<T>{
constunresolvedWidget=super.getOrCreateWidget<T>(factoryId,options);
unresolvedWidget.then(async(widget)=>{
constsketch=awaitthis.sketchesServiceClient.currentSketch();
this.maybeSetWidgetUncloseable(sketch,widget);
});
returnunresolvedWidget;
}
privatemaybeSetWidgetUncloseable(
sketch: CurrentSketch,
...widgets: Widget[]
): void{
constsketchFileUris=
CurrentSketch.isValid(sketch)&&
newSet([sketch.mainFileUri, ...sketch.rootFolderFileUris]);
for(constwidgetofwidgets){
if(widgetinstanceofOutputWidget){
this.setWidgetUncloseable(widget);// TODO: https://arduino.slack.com/archives/C01698YT7S4/p1598011990133700
}elseif(widgetinstanceofEditorWidget){
// Make the editor un-closeable asynchronously.
consturi=widget.editor.uri.toString();
if(!!sketchFileUris&&sketchFileUris.has(uri)){
this.setWidgetUncloseable(widget);
}
}
}
}
privatesetWidgetUncloseable(widget: Widget): void{
const{ title }=widget;
if(title.closable){
title.closable=false;
}
// Show the dirty indicator on uncloseable widgets when hovering over the title. Instead of showing the `X` for close.
constuncloseableClass='a-mod-uncloseable';
if(!title.className.includes(uncloseableClass)){
title.className+=title.className+` ${uncloseableClass}`;
}
}
}