- Notifications
You must be signed in to change notification settings - Fork 440
/
Copy pathapplication-shell.ts
149 lines (139 loc) · 4.78 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
import{
ApplicationShellasTheiaApplicationShell,
DockPanel,
DockPanelRendererasTheiaDockPanelRenderer,
Panel,
SaveOptions,
SHELL_TABBAR_CONTEXT_MENU,
TabBar,
Widget,
}from'@theia/core/lib/browser';
import{nls}from'@theia/core/lib/common/nls';
import{MessageService}from'@theia/core/lib/common/message-service';
import{inject,injectable}from'@theia/core/shared/inversify';
import{ApplicationConnectionStatusContribution}from'./connection-status-service';
import{ToolbarAwareTabBar}from'./tab-bars';
import{find}from'@theia/core/shared/@phosphor/algorithm';
import{OutputWidget}from'@theia/output/lib/browser/output-widget';
@injectable()
exportclassApplicationShellextendsTheiaApplicationShell{
@inject(MessageService)
privatereadonlymessageService: MessageService;
@inject(ApplicationConnectionStatusContribution)
privatereadonlyconnectionStatusService: ApplicationConnectionStatusContribution;
overrideasyncaddWidget(
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;
}
letref: Widget|undefined=options.ref;
constarea: TheiaApplicationShell.Area=options.area||'main';
if(!ref&&(area==='main'||area==='bottom')){
consttabBar=this.getTabBarFor(area);
if(tabBar){
constlast=tabBar.titles[tabBar.titles.length-1];
if(last){
ref=last.owner;
}
}
}
returnsuper.addWidget(widget,{ ...options, ref });
}
overridedoRevealWidget(id: string): Widget|undefined{
letwidget=find(this.mainPanel.widgets(),(w)=>w.id===id);
if(!widget){
widget=find(this.bottomPanel.widgets(),(w)=>w.id===id);
if(widget){
this.expandBottomPanel();
}
}
if(widget){
consttabBar=this.getTabBarFor(widget);
if(tabBar){
tabBar.currentTitle=widget.title;
}
}
if(!widget){
widget=this.leftPanelHandler.expand(id);
}
if(!widget){
widget=this.rightPanelHandler.expand(id);
}
if(widget){
// Prevent focusing the output widget when is updated
// See https://github.com/arduino/arduino-ide/issues/2679
if(!(widgetinstanceofOutputWidget)){
this.windowService.focus();
}
returnwidget;
}else{
returnthis.secondaryWindowHandler.revealWidget(id);
}
}
overridehandleEvent(): boolean{
// NOOP, dragging has been disabled
returnfalse;
}
// Avoid hiding top panel as we use it for arduino toolbar
protectedoverridecreateTopPanel(): Panel{
consttopPanel=super.createTopPanel();
topPanel.show();
returntopPanel;
}
overrideasyncsaveAll(options?: SaveOptions): Promise<void>{
// When there is no connection between the IDE2 frontend and backend.
if(this.connectionStatusService.offlineStatus==='backend'){
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
}
returnsuper.saveAll(options);
}
}
exportclassDockPanelRendererextendsTheiaDockPanelRenderer{
overridecreateTabBar(): TabBar<Widget>{
constrenderer=this.tabBarRendererFactory();
// `ToolbarAwareTabBar` is from IDE2 and not from Theia. Check the imports.
consttabBar=newToolbarAwareTabBar(
this.tabBarToolbarRegistry,
this.tabBarToolbarFactory,
this.breadcrumbsRendererFactory,
{
renderer,
// Scroll bar options
handlers: ['drag-thumb','keyboard','wheel','touch'],
useBothWheelAxes: true,
scrollXMarginOffset: 4,
suppressScrollY: true,
}
);
this.tabBarClasses.forEach((c)=>tabBar.addClass(c));
renderer.tabBar=tabBar;
tabBar.disposed.connect(()=>renderer.dispose());
renderer.contextMenuPath=SHELL_TABBAR_CONTEXT_MENU;
tabBar.currentChanged.connect(this.onCurrentTabChanged,this);
returntabBar;
}
}
constoriginalHandleEvent=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);
};