-
-
Notifications
You must be signed in to change notification settings - Fork 436
/
Copy pathsketchbook-widget.tsx
95 lines (82 loc) · 2.9 KB
/
sketchbook-widget.tsx
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
import { inject, injectable, postConstruct } from 'inversify';
import { toArray } from '@phosphor/algorithm';
import { IDragEvent } from '@phosphor/dragdrop';
import { DockPanel, Widget } from '@phosphor/widgets';
import { Message, MessageLoop } from '@phosphor/messaging';
import { Disposable } from '@theia/core/lib/common/disposable';
import { BaseWidget } from '@theia/core/lib/browser/widgets/widget';
import { SketchbookTreeWidget } from './sketchbook-tree-widget';
import { nls } from '@theia/core/lib/browser/nls';
@injectable()
export class SketchbookWidget extends BaseWidget {
static LABEL = nls.localize('arduino/sketch/titleSketchbook', 'Sketchbook');
@inject(SketchbookTreeWidget)
protected readonly localSketchbookTreeWidget: SketchbookTreeWidget;
protected readonly sketchbookTreesContainer: DockPanel;
constructor() {
super();
this.id = 'arduino-sketchbook-widget';
this.title.caption = SketchbookWidget.LABEL;
this.title.label = SketchbookWidget.LABEL;
this.title.iconClass = 'fa fa-arduino-folder';
this.title.closable = true;
this.node.tabIndex = 0;
this.sketchbookTreesContainer = this.createTreesContainer();
}
@postConstruct()
protected init(): void {
this.sketchbookTreesContainer.addWidget(this.localSketchbookTreeWidget);
}
protected onAfterAttach(message: Message): void {
super.onAfterAttach(message);
Widget.attach(this.sketchbookTreesContainer, this.node);
this.toDisposeOnDetach.push(
Disposable.create(() => Widget.detach(this.sketchbookTreesContainer))
);
}
getTreeWidget(): SketchbookTreeWidget {
return this.localSketchbookTreeWidget;
}
protected onActivateRequest(message: Message): void {
super.onActivateRequest(message);
// TODO: focus the active sketchbook
// if (this.editor) {
// this.editor.focus();
// } else {
// }
this.node.focus();
}
protected onResize(message: Widget.ResizeMessage): void {
super.onResize(message);
MessageLoop.sendMessage(
this.sketchbookTreesContainer,
Widget.ResizeMessage.UnknownSize
);
for (const widget of toArray(this.sketchbookTreesContainer.widgets())) {
MessageLoop.sendMessage(widget, Widget.ResizeMessage.UnknownSize);
}
}
protected onAfterShow(msg: Message): void {
super.onAfterShow(msg);
this.onResize(Widget.ResizeMessage.UnknownSize);
}
protected createTreesContainer(): DockPanel {
const panel = new NoopDragOverDockPanel({
spacing: 0,
mode: 'single-document',
});
panel.addClass('sketchbook-trees-container');
panel.node.tabIndex = -1;
return panel;
}
}
export class NoopDragOverDockPanel extends DockPanel {
constructor(options?: DockPanel.IOptions) {
super(options);
NoopDragOverDockPanel.prototype['_evtDragOver'] = (event: IDragEvent) => {
event.preventDefault();
event.stopPropagation();
event.dropAction = 'none';
};
}
}