-
-
Notifications
You must be signed in to change notification settings - Fork 435
/
Copy pathapplication-shell.ts
151 lines (138 loc) · 4.85 KB
/
application-shell.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import { injectable, inject } from '@theia/core/shared/inversify';
import { EditorWidget } from '@theia/editor/lib/browser';
import { CommandService } from '@theia/core/lib/common/command';
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 {
ApplicationShell as TheiaApplicationShell,
DockPanel,
Panel,
Widget,
} from '@theia/core/lib/browser';
import { Sketch } from '../../../common/protocol';
import { SaveAsSketch } from '../../contributions/save-as-sketch';
import {
CurrentSketch,
SketchesServiceClientImpl,
} from '../../../common/protocol/sketches-service-client-impl';
import { nls } from '@theia/core/lib/common';
import { SketchbookWidget } from '../../widgets/sketchbook/sketchbook-widget';
import URI from '@theia/core/lib/common/uri';
@injectable()
export class ApplicationShell extends TheiaApplicationShell {
@inject(CommandService)
protected readonly commandService: CommandService;
@inject(MessageService)
protected readonly messageService: MessageService;
@inject(SketchesServiceClientImpl)
protected readonly sketchesServiceClient: SketchesServiceClientImpl;
@inject(ConnectionStatusService)
protected readonly connectionStatusService: ConnectionStatusService;
override async setLayoutData(
layoutData: TheiaApplicationShell.LayoutData
): Promise<void> {
if (typeof layoutData.activeWidgetId !== 'undefined') {
layoutData.activeWidgetId = SketchbookWidget.ID;
layoutData.leftPanel?.items?.forEach((item) => {
if (item?.widget?.id === SketchbookWidget.ID) item.expanded = true;
else item.expanded = false;
});
}
super.setLayoutData(layoutData);
}
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(
widget: Widget,
options: Readonly<TheiaApplicationShell.WidgetOptions> = {}
): Promise<void> {
// By default, Theia open a widget **next** to the currently active in the target area.
// Instead of this logic, we want to open the new widget after the last of the target area.
if (!widget.id) {
console.error(
'Widgets added to the application shell must have a unique id property.'
);
return;
}
let ref: Widget | undefined = options.ref;
const area: TheiaApplicationShell.Area = options.area || 'main';
if (!ref && (area === 'main' || area === 'bottom')) {
const tabBar = this.getTabBarFor(area);
if (tabBar) {
const last = tabBar.titles[tabBar.titles.length - 1];
if (last) {
ref = last.owner;
}
}
}
return super.addWidget(widget, { ...options, ref });
}
override handleEvent(): boolean {
// NOOP, dragging has been disabled
return false;
}
// Avoid hiding top panel as we use it for arduino toolbar
protected override createTopPanel(): Panel {
const topPanel = super.createTopPanel();
topPanel.show();
return topPanel;
}
override async saveAll(): Promise<void> {
if (
this.connectionStatusService.currentStatus === ConnectionStatus.OFFLINE
) {
this.messageService.error(
nls.localize(
'theia/core/couldNotSave',
'Could not save the sketch. Please copy your unsaved work into your favorite text editor, and restart the IDE.'
)
);
return; // Theia does not reject on failed save: https://github.com/eclipse-theia/theia/pull/8803
}
await super.saveAll();
const options = { execOnlyIfTemp: true, openAfterMove: true };
await this.commandService.executeCommand(
SaveAsSketch.Commands.SAVE_AS_SKETCH.id,
options
);
}
}
const originalHandleEvent = DockPanel.prototype.handleEvent;
DockPanel.prototype.handleEvent = function (event) {
switch (event.type) {
case 'p-dragenter':
case 'p-dragleave':
case 'p-dragover':
case 'p-drop':
return;
}
originalHandleEvent.bind(this)(event);
};