@theia/core 1.53.0-next.55 → 1.53.0-next.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (581) hide show
  1. package/README.md +6 -6
  2. package/i18n/nls.cs.json +582 -582
  3. package/i18n/nls.de.json +582 -582
  4. package/i18n/nls.es.json +582 -582
  5. package/i18n/nls.fr.json +582 -582
  6. package/i18n/nls.hu.json +582 -582
  7. package/i18n/nls.it.json +582 -582
  8. package/i18n/nls.ja.json +582 -582
  9. package/i18n/nls.json +582 -582
  10. package/i18n/nls.ko.json +582 -582
  11. package/i18n/nls.pl.json +582 -582
  12. package/i18n/nls.pt-br.json +582 -582
  13. package/i18n/nls.ru.json +582 -582
  14. package/i18n/nls.tr.json +582 -582
  15. package/i18n/nls.zh-cn.json +582 -582
  16. package/i18n/nls.zh-tw.json +582 -582
  17. package/lib/browser/catalog.json +54 -6
  18. package/lib/browser/common-frontend-contribution.js +3 -3
  19. package/lib/browser/common-styling-participants.js +166 -166
  20. package/lib/browser/progress-location-service.spec.js +7 -7
  21. package/lib/browser/storage-service.js +3 -3
  22. package/lib/browser/tree/tree.spec.js +75 -75
  23. package/lib/node/process-utils.spec.js +8 -8
  24. package/package.json +4 -4
  25. package/shared/ajv/index.d.ts +2 -2
  26. package/shared/markdown-it.d.ts +2 -2
  27. package/shared/markdown-it.js +1 -1
  28. package/shared/reflect-metadata/index.d.ts +1 -1
  29. package/shared/reflect-metadata/index.js +1 -1
  30. package/shared/vscode-languageserver-types/index.d.ts +1 -1
  31. package/src/browser/about-dialog.tsx +137 -137
  32. package/src/browser/authentication-service.ts +467 -467
  33. package/src/browser/breadcrumbs/breadcrumb-popup-container.ts +101 -101
  34. package/src/browser/breadcrumbs/breadcrumb-renderer.tsx +41 -41
  35. package/src/browser/breadcrumbs/breadcrumbs-constants.ts +79 -79
  36. package/src/browser/breadcrumbs/breadcrumbs-renderer.tsx +185 -185
  37. package/src/browser/breadcrumbs/breadcrumbs-service.ts +108 -108
  38. package/src/browser/breadcrumbs/index.ts +21 -21
  39. package/src/browser/browser-clipboard-service.ts +122 -122
  40. package/src/browser/browser.ts +239 -239
  41. package/src/browser/clipboard-service.ts +23 -23
  42. package/src/browser/color-application-contribution.ts +110 -110
  43. package/src/browser/color-registry.ts +60 -60
  44. package/src/browser/command-open-handler.ts +54 -54
  45. package/src/browser/common-frontend-contribution.ts +2680 -2680
  46. package/src/browser/common-styling-participants.ts +361 -361
  47. package/src/browser/connection-status-service.spec.ts +200 -200
  48. package/src/browser/connection-status-service.ts +216 -216
  49. package/src/browser/context-key-service.ts +142 -142
  50. package/src/browser/context-menu-renderer.ts +124 -124
  51. package/src/browser/core-preferences.ts +343 -343
  52. package/src/browser/credentials-service.ts +106 -106
  53. package/src/browser/decoration-style.ts +65 -65
  54. package/src/browser/decorations-service.ts +209 -209
  55. package/src/browser/dialogs/react-dialog.tsx +56 -56
  56. package/src/browser/dialogs.ts +534 -534
  57. package/src/browser/diff-uris.ts +117 -117
  58. package/src/browser/encoding-registry.ts +97 -97
  59. package/src/browser/endpoint.spec.ts +148 -148
  60. package/src/browser/endpoint.ts +136 -136
  61. package/src/browser/external-uri-service.ts +79 -79
  62. package/src/browser/file-icons-js.d.ts +20 -20
  63. package/src/browser/frontend-application-bindings.ts +62 -62
  64. package/src/browser/frontend-application-config-provider.spec.ts +45 -45
  65. package/src/browser/frontend-application-config-provider.ts +50 -50
  66. package/src/browser/frontend-application-contribution.ts +110 -110
  67. package/src/browser/frontend-application-module.ts +474 -474
  68. package/src/browser/frontend-application-state.ts +74 -74
  69. package/src/browser/frontend-application.ts +326 -326
  70. package/src/browser/hover-service.ts +218 -218
  71. package/src/browser/http-open-handler.ts +49 -49
  72. package/src/browser/i18n/i18n-frontend-module.ts +27 -27
  73. package/src/browser/i18n/language-quick-pick-service.ts +130 -130
  74. package/src/browser/icon-registry.ts +87 -87
  75. package/src/browser/icon-theme-contribution.ts +64 -64
  76. package/src/browser/icon-theme-service.ts +217 -217
  77. package/src/browser/icons/CollapseAll.svg +7 -7
  78. package/src/browser/icons/CollapseAll_inverse.svg +7 -7
  79. package/src/browser/icons/Refresh.svg +7 -7
  80. package/src/browser/icons/Refresh_inverse.svg +7 -7
  81. package/src/browser/icons/add-inverse.svg +4 -4
  82. package/src/browser/icons/add.svg +4 -4
  83. package/src/browser/icons/arrow-down-bright.svg +6 -6
  84. package/src/browser/icons/arrow-down-dark.svg +6 -6
  85. package/src/browser/icons/arrow-up-bright.svg +6 -6
  86. package/src/browser/icons/arrow-up-dark.svg +6 -6
  87. package/src/browser/icons/case-sensitive-dark.svg +16 -16
  88. package/src/browser/icons/case-sensitive.svg +16 -16
  89. package/src/browser/icons/chevron-right-dark.svg +5 -5
  90. package/src/browser/icons/chevron-right-light.svg +6 -6
  91. package/src/browser/icons/circle-bright.svg +7 -7
  92. package/src/browser/icons/circle-dark.svg +7 -7
  93. package/src/browser/icons/clear-search-results-dark.svg +7 -7
  94. package/src/browser/icons/clear-search-results.svg +7 -7
  95. package/src/browser/icons/close-all-bright.svg +7 -7
  96. package/src/browser/icons/close-all-dark.svg +7 -7
  97. package/src/browser/icons/close-bright.svg +7 -7
  98. package/src/browser/icons/close-dark.svg +7 -7
  99. package/src/browser/icons/collapse.svg +4 -4
  100. package/src/browser/icons/edit-json-dark.svg +6 -6
  101. package/src/browser/icons/edit-json.svg +6 -6
  102. package/src/browser/icons/expand.svg +4 -4
  103. package/src/browser/icons/loading-dark.svg +6 -6
  104. package/src/browser/icons/loading-light.svg +6 -6
  105. package/src/browser/icons/open-change-bright.svg +3 -3
  106. package/src/browser/icons/open-change-dark.svg +4 -4
  107. package/src/browser/icons/open-file-bright.svg +4 -4
  108. package/src/browser/icons/open-file-dark.svg +4 -4
  109. package/src/browser/icons/preview-bright.svg +3 -3
  110. package/src/browser/icons/preview-dark.svg +3 -3
  111. package/src/browser/icons/regex-dark.svg +10 -10
  112. package/src/browser/icons/regex.svg +10 -10
  113. package/src/browser/icons/remove-all-inverse.svg +4 -4
  114. package/src/browser/icons/remove-all.svg +4 -4
  115. package/src/browser/icons/replace-all-inverse.svg +13 -13
  116. package/src/browser/icons/replace-all.svg +13 -13
  117. package/src/browser/icons/replace-inverse.svg +15 -15
  118. package/src/browser/icons/replace.svg +15 -15
  119. package/src/browser/icons/whole-word-dark.svg +19 -19
  120. package/src/browser/icons/whole-word.svg +19 -19
  121. package/src/browser/index.ts +50 -50
  122. package/src/browser/json-schema-store.ts +118 -118
  123. package/src/browser/keybinding.spec.ts +554 -554
  124. package/src/browser/keybinding.ts +759 -759
  125. package/src/browser/keyboard/browser-keyboard-frontend-contribution.ts +108 -108
  126. package/src/browser/keyboard/browser-keyboard-layout-provider.spec.ts +171 -171
  127. package/src/browser/keyboard/browser-keyboard-layout-provider.ts +469 -469
  128. package/src/browser/keyboard/browser-keyboard-module.ts +30 -30
  129. package/src/browser/keyboard/index.ts +20 -20
  130. package/src/browser/keyboard/keyboard-layout-service.spec.ts +121 -121
  131. package/src/browser/keyboard/keyboard-layout-service.ts +455 -455
  132. package/src/browser/keyboard/keys.spec.ts +258 -258
  133. package/src/browser/keyboard/keys.ts +20 -20
  134. package/src/browser/keys.ts +21 -21
  135. package/src/browser/label-parser.spec.ts +165 -165
  136. package/src/browser/label-parser.ts +108 -108
  137. package/src/browser/label-provider.spec.ts +62 -62
  138. package/src/browser/label-provider.ts +385 -385
  139. package/src/browser/language-icon-provider.ts +55 -55
  140. package/src/browser/language-service.ts +77 -77
  141. package/src/browser/logger-frontend-module.ts +65 -65
  142. package/src/browser/markdown-rendering/markdown-renderer.ts +98 -98
  143. package/src/browser/menu/browser-context-menu-renderer.ts +48 -48
  144. package/src/browser/menu/browser-menu-module.ts +28 -28
  145. package/src/browser/menu/browser-menu-plugin.ts +491 -491
  146. package/src/browser/menu/context-menu-context.ts +41 -41
  147. package/src/browser/messaging/connection-source.ts +26 -26
  148. package/src/browser/messaging/frontend-id-provider.ts +37 -37
  149. package/src/browser/messaging/index.ts +18 -18
  150. package/src/browser/messaging/messaging-frontend-module.ts +41 -41
  151. package/src/browser/messaging/service-connection-provider.ts +140 -140
  152. package/src/browser/messaging/ws-connection-provider.ts +49 -49
  153. package/src/browser/messaging/ws-connection-source.ts +230 -230
  154. package/src/browser/mime-service.ts +30 -30
  155. package/src/browser/navigatable-types.ts +81 -81
  156. package/src/browser/navigatable.ts +39 -39
  157. package/src/browser/open-with-service.ts +140 -140
  158. package/src/browser/opener-service.spec.ts +49 -49
  159. package/src/browser/opener-service.ts +169 -169
  160. package/src/browser/performance/frontend-stopwatch.ts +65 -65
  161. package/src/browser/performance/index.ts +18 -18
  162. package/src/browser/performance/measurement-frontend-bindings.ts +31 -31
  163. package/src/browser/preferences/index.ts +23 -23
  164. package/src/browser/preferences/injectable-preference-proxy.ts +283 -283
  165. package/src/browser/preferences/preference-configurations.ts +82 -82
  166. package/src/browser/preferences/preference-contribution.ts +436 -436
  167. package/src/browser/preferences/preference-language-override-service.ts +111 -111
  168. package/src/browser/preferences/preference-provider.spec.ts +36 -36
  169. package/src/browser/preferences/preference-provider.ts +277 -277
  170. package/src/browser/preferences/preference-proxy.spec.ts +367 -367
  171. package/src/browser/preferences/preference-proxy.ts +367 -367
  172. package/src/browser/preferences/preference-schema-provider.spec.ts +130 -130
  173. package/src/browser/preferences/preference-scope.ts +18 -18
  174. package/src/browser/preferences/preference-service.spec.ts +613 -613
  175. package/src/browser/preferences/preference-service.ts +594 -594
  176. package/src/browser/preferences/preference-validation-service.spec.ts +334 -334
  177. package/src/browser/preferences/preference-validation-service.ts +358 -358
  178. package/src/browser/preferences/test/index.ts +19 -19
  179. package/src/browser/preferences/test/mock-preference-provider.ts +50 -50
  180. package/src/browser/preferences/test/mock-preference-proxy.ts +48 -48
  181. package/src/browser/preferences/test/mock-preference-service.ts +63 -63
  182. package/src/browser/preload/i18n-preload-contribution.ts +50 -50
  183. package/src/browser/preload/os-preload-contribution.ts +37 -37
  184. package/src/browser/preload/preload-module.ts +45 -45
  185. package/src/browser/preload/preloader.ts +37 -37
  186. package/src/browser/preload/theme-preload-contribution.ts +31 -31
  187. package/src/browser/progress-bar-factory.ts +29 -29
  188. package/src/browser/progress-bar.ts +76 -76
  189. package/src/browser/progress-client.ts +53 -53
  190. package/src/browser/progress-location-service.spec.ts +50 -50
  191. package/src/browser/progress-location-service.ts +96 -96
  192. package/src/browser/progress-status-bar-item.ts +83 -83
  193. package/src/browser/quick-input/index.ts +23 -23
  194. package/src/browser/quick-input/quick-access.ts +75 -75
  195. package/src/browser/quick-input/quick-command-frontend-contribution.ts +89 -89
  196. package/src/browser/quick-input/quick-command-service.ts +246 -246
  197. package/src/browser/quick-input/quick-help-service.ts +87 -87
  198. package/src/browser/quick-input/quick-input-frontend-contribution.ts +33 -33
  199. package/src/browser/quick-input/quick-input-service.spec.ts +176 -176
  200. package/src/browser/quick-input/quick-input-service.ts +17 -17
  201. package/src/browser/quick-input/quick-pick-service-impl.ts +69 -69
  202. package/src/browser/quick-input/quick-view-service.ts +83 -83
  203. package/src/browser/request/browser-request-module.ts +23 -23
  204. package/src/browser/request/browser-request-service.ts +172 -172
  205. package/src/browser/resource-context-key.ts +77 -77
  206. package/src/browser/saveable-service.ts +332 -332
  207. package/src/browser/saveable.ts +395 -395
  208. package/src/browser/secondary-window-handler.ts +211 -211
  209. package/src/browser/shell/additional-views-menu-widget.tsx +71 -71
  210. package/src/browser/shell/application-shell-mouse-tracker.ts +103 -103
  211. package/src/browser/shell/application-shell.ts +2271 -2271
  212. package/src/browser/shell/current-widget-command-adapter.ts +57 -57
  213. package/src/browser/shell/index.ts +23 -23
  214. package/src/browser/shell/shell-layout-restorer.ts +399 -399
  215. package/src/browser/shell/side-panel-handler.ts +794 -794
  216. package/src/browser/shell/side-panel-toolbar.ts +111 -111
  217. package/src/browser/shell/sidebar-bottom-menu-widget.tsx +39 -39
  218. package/src/browser/shell/sidebar-menu-widget.tsx +183 -183
  219. package/src/browser/shell/sidebar-top-menu-widget.tsx +26 -26
  220. package/src/browser/shell/split-panels.ts +191 -191
  221. package/src/browser/shell/tab-bar-decorator.ts +106 -106
  222. package/src/browser/shell/tab-bar-toolbar/index.ts +19 -19
  223. package/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar-menu-adapters.ts +31 -31
  224. package/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar-registry.ts +242 -242
  225. package/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar-types.ts +149 -149
  226. package/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar.spec.ts +62 -62
  227. package/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar.tsx +443 -443
  228. package/src/browser/shell/tab-bars.spec.ts +63 -63
  229. package/src/browser/shell/tab-bars.ts +1468 -1468
  230. package/src/browser/shell/theia-dock-panel.ts +265 -265
  231. package/src/browser/shell/view-column-service.ts +125 -125
  232. package/src/browser/shell/view-contribution.ts +178 -178
  233. package/src/browser/source-tree/index.ts +19 -19
  234. package/src/browser/source-tree/source-tree-widget.tsx +107 -107
  235. package/src/browser/source-tree/source-tree.ts +146 -146
  236. package/src/browser/source-tree/tree-source.ts +73 -73
  237. package/src/browser/status-bar/index.ts +29 -29
  238. package/src/browser/status-bar/status-bar-types.ts +97 -97
  239. package/src/browser/status-bar/status-bar-view-model.ts +209 -209
  240. package/src/browser/status-bar/status-bar.tsx +189 -189
  241. package/src/browser/storage-service.spec.ts +76 -76
  242. package/src/browser/storage-service.ts +129 -129
  243. package/src/browser/style/about.css +36 -36
  244. package/src/browser/style/alert-messages.css +62 -62
  245. package/src/browser/style/ansi.css +88 -88
  246. package/src/browser/style/breadcrumbs.css +130 -130
  247. package/src/browser/style/dialog.css +126 -126
  248. package/src/browser/style/dockpanel.css +76 -76
  249. package/src/browser/style/hover-service.css +101 -101
  250. package/src/browser/style/icons.css +61 -61
  251. package/src/browser/style/index.css +353 -353
  252. package/src/browser/style/materialcolors.css +278 -278
  253. package/src/browser/style/menus.css +230 -230
  254. package/src/browser/style/notification.css +39 -39
  255. package/src/browser/style/os.css +87 -87
  256. package/src/browser/style/progress-bar.css +43 -43
  257. package/src/browser/style/quick-title-bar.css +45 -45
  258. package/src/browser/style/scrollbars.css +172 -172
  259. package/src/browser/style/search-box.css +123 -123
  260. package/src/browser/style/select-component.css +107 -107
  261. package/src/browser/style/sidepanel.css +367 -367
  262. package/src/browser/style/split-widget.css +38 -38
  263. package/src/browser/style/status-bar.css +127 -127
  264. package/src/browser/style/tabs.css +647 -647
  265. package/src/browser/style/tooltip.css +28 -28
  266. package/src/browser/style/tree-decorators.css +81 -81
  267. package/src/browser/style/tree.css +232 -232
  268. package/src/browser/style/view-container.css +187 -187
  269. package/src/browser/style/widget.css +19 -19
  270. package/src/browser/styling-service.ts +96 -96
  271. package/src/browser/supported-encodings.ts +262 -262
  272. package/src/browser/test/jsdom.ts +69 -69
  273. package/src/browser/test/mock-connection-status-service.ts +33 -33
  274. package/src/browser/test/mock-env-variables-server.ts +47 -47
  275. package/src/browser/test/mock-opener-service.ts +34 -34
  276. package/src/browser/test/mock-storage-service.ts +49 -49
  277. package/src/browser/theming.ts +206 -206
  278. package/src/browser/tooltip-service.tsx +96 -96
  279. package/src/browser/tree/fuzzy-search.spec.ts +99 -99
  280. package/src/browser/tree/fuzzy-search.ts +136 -136
  281. package/src/browser/tree/index.ts +29 -29
  282. package/src/browser/tree/search-box-debounce.ts +96 -96
  283. package/src/browser/tree/search-box.ts +355 -355
  284. package/src/browser/tree/test/mock-selectable-tree-model.ts +109 -109
  285. package/src/browser/tree/test/mock-tree-model.ts +136 -136
  286. package/src/browser/tree/test/tree-test-container.ts +50 -50
  287. package/src/browser/tree/tree-compression/compressed-tree-expansion-service.ts +46 -46
  288. package/src/browser/tree/tree-compression/compressed-tree-model.ts +88 -88
  289. package/src/browser/tree/tree-compression/compressed-tree-widget.tsx +203 -203
  290. package/src/browser/tree/tree-compression/index.ts +20 -20
  291. package/src/browser/tree/tree-compression/tree-compression-service.ts +125 -125
  292. package/src/browser/tree/tree-compression/tree-compression.css +28 -28
  293. package/src/browser/tree/tree-consistency.spec.ts +105 -105
  294. package/src/browser/tree/tree-container.spec.ts +45 -45
  295. package/src/browser/tree/tree-container.ts +155 -155
  296. package/src/browser/tree/tree-decorator.spec.ts +162 -162
  297. package/src/browser/tree/tree-decorator.ts +238 -238
  298. package/src/browser/tree/tree-expansion.spec.ts +173 -173
  299. package/src/browser/tree/tree-expansion.ts +165 -165
  300. package/src/browser/tree/tree-focus-service.ts +55 -55
  301. package/src/browser/tree/tree-iterator.spec.ts +170 -170
  302. package/src/browser/tree/tree-iterator.ts +256 -256
  303. package/src/browser/tree/tree-label-provider.ts +40 -40
  304. package/src/browser/tree/tree-model.ts +562 -562
  305. package/src/browser/tree/tree-navigation.ts +58 -58
  306. package/src/browser/tree/tree-preference.ts +50 -50
  307. package/src/browser/tree/tree-search.ts +128 -128
  308. package/src/browser/tree/tree-selectable.spec.ts +152 -152
  309. package/src/browser/tree/tree-selection-impl.ts +176 -176
  310. package/src/browser/tree/tree-selection-state.spec.ts +462 -462
  311. package/src/browser/tree/tree-selection-state.ts +245 -245
  312. package/src/browser/tree/tree-selection.ts +159 -159
  313. package/src/browser/tree/tree-view-welcome-widget.tsx +263 -263
  314. package/src/browser/tree/tree-widget-selection.ts +45 -45
  315. package/src/browser/tree/tree-widget.tsx +1591 -1591
  316. package/src/browser/tree/tree.spec.ts +241 -241
  317. package/src/browser/tree/tree.ts +425 -425
  318. package/src/browser/undo-redo-handler.ts +85 -85
  319. package/src/browser/user-working-directory-provider.ts +77 -77
  320. package/src/browser/view-container.ts +1640 -1640
  321. package/src/browser/widget-decoration.ts +358 -358
  322. package/src/browser/widget-manager.spec.ts +102 -102
  323. package/src/browser/widget-manager.ts +318 -318
  324. package/src/browser/widget-open-handler.ts +168 -168
  325. package/src/browser/widgets/alert-message.tsx +56 -56
  326. package/src/browser/widgets/enhanced-preview-widget.ts +27 -27
  327. package/src/browser/widgets/extractable-widget.ts +33 -33
  328. package/src/browser/widgets/index.ts +21 -21
  329. package/src/browser/widgets/previewable-widget.ts +31 -31
  330. package/src/browser/widgets/react-renderer.tsx +53 -53
  331. package/src/browser/widgets/react-widget.tsx +51 -51
  332. package/src/browser/widgets/select-component.tsx +367 -367
  333. package/src/browser/widgets/split-widget.ts +163 -163
  334. package/src/browser/widgets/widget.ts +406 -406
  335. package/src/browser/window/browser-window-module.ts +32 -32
  336. package/src/browser/window/default-secondary-window-service.ts +189 -189
  337. package/src/browser/window/default-window-service.spec.ts +78 -78
  338. package/src/browser/window/default-window-service.ts +171 -171
  339. package/src/browser/window/secondary-window-service.ts +39 -39
  340. package/src/browser/window/test/mock-window-service.ts +29 -29
  341. package/src/browser/window/window-service.ts +78 -78
  342. package/src/browser/window/window-title-service.ts +107 -107
  343. package/src/browser/window/window-title-updater.ts +95 -95
  344. package/src/browser/window-contribution.ts +64 -64
  345. package/src/browser-only/frontend-only-application-module.ts +116 -116
  346. package/src/browser-only/i18n/i18n-frontend-only-module.ts +37 -37
  347. package/src/browser-only/logger-frontend-only-module.ts +63 -63
  348. package/src/browser-only/messaging/frontend-only-service-connection-provider.ts +39 -39
  349. package/src/browser-only/messaging/messaging-frontend-only-module.ts +42 -42
  350. package/src/browser-only/preload/frontend-only-preload-module.ts +49 -49
  351. package/src/common/accessibility.ts +33 -33
  352. package/src/common/application-error.spec.ts +27 -27
  353. package/src/common/application-error.ts +76 -76
  354. package/src/common/application-protocol.ts +42 -42
  355. package/src/common/array-utils.ts +129 -129
  356. package/src/common/buffer.ts +228 -228
  357. package/src/common/cancellation.ts +163 -163
  358. package/src/common/char-code.ts +438 -438
  359. package/src/common/collections.ts +125 -125
  360. package/src/common/color.ts +103 -103
  361. package/src/common/command.spec.ts +208 -208
  362. package/src/common/command.ts +489 -489
  363. package/src/common/contribution-filter/contribution-filter-registry.ts +79 -79
  364. package/src/common/contribution-filter/contribution-filter.ts +64 -64
  365. package/src/common/contribution-filter/filter.ts +23 -23
  366. package/src/common/contribution-filter/index.ts +19 -19
  367. package/src/common/contribution-provider.ts +96 -96
  368. package/src/common/disposable.spec.ts +94 -94
  369. package/src/common/disposable.ts +188 -188
  370. package/src/common/encoding-service.ts +380 -380
  371. package/src/common/encodings.ts +24 -24
  372. package/src/common/env-variables/env-variables-protocol.ts +38 -38
  373. package/src/common/env-variables/index.ts +17 -17
  374. package/src/common/event.spec.ts +32 -32
  375. package/src/common/event.ts +493 -493
  376. package/src/common/file-uri.ts +61 -61
  377. package/src/common/frontend-application-state.ts +38 -38
  378. package/src/common/glob.ts +741 -741
  379. package/src/common/hash.ts +85 -85
  380. package/src/common/i18n/localization-server.ts +25 -25
  381. package/src/common/i18n/localization.ts +80 -80
  382. package/src/common/i18n/nls.metadata.json +34112 -34112
  383. package/src/common/index.ts +51 -51
  384. package/src/common/json-schema.ts +108 -108
  385. package/src/common/key-store.ts +26 -26
  386. package/src/common/keybinding.ts +152 -152
  387. package/src/common/keyboard/keyboard-layout-provider.ts +51 -51
  388. package/src/common/keys.ts +694 -694
  389. package/src/common/label-protocol.ts +35 -35
  390. package/src/common/logger-protocol.ts +119 -119
  391. package/src/common/logger-watcher.ts +48 -48
  392. package/src/common/logger.spec.ts +46 -46
  393. package/src/common/logger.ts +389 -389
  394. package/src/common/lsp-types.ts +34 -34
  395. package/src/common/markdown-rendering/icon-utilities.ts +30 -30
  396. package/src/common/markdown-rendering/index.ts +18 -18
  397. package/src/common/markdown-rendering/markdown-string.ts +152 -152
  398. package/src/common/menu/action-menu-node.ts +65 -65
  399. package/src/common/menu/composite-menu-node.spec.ts +67 -67
  400. package/src/common/menu/composite-menu-node.ts +114 -114
  401. package/src/common/menu/index.ts +21 -21
  402. package/src/common/menu/menu-adapter.ts +103 -103
  403. package/src/common/menu/menu-model-registry.ts +374 -374
  404. package/src/common/menu/menu-types.ts +220 -220
  405. package/src/common/menu/menu.spec.ts +101 -101
  406. package/src/common/message-rpc/channel.spec.ts +88 -88
  407. package/src/common/message-rpc/channel.ts +300 -300
  408. package/src/common/message-rpc/index.ts +22 -22
  409. package/src/common/message-rpc/message-buffer.ts +105 -105
  410. package/src/common/message-rpc/msg-pack-extension-manager.ts +70 -70
  411. package/src/common/message-rpc/rpc-message-encoder.spec.ts +65 -65
  412. package/src/common/message-rpc/rpc-message-encoder.ts +190 -190
  413. package/src/common/message-rpc/rpc-protocol.ts +255 -255
  414. package/src/common/message-rpc/uint8-array-message-buffer.spec.ts +41 -41
  415. package/src/common/message-rpc/uint8-array-message-buffer.ts +213 -213
  416. package/src/common/message-service-protocol.ts +148 -148
  417. package/src/common/message-service.ts +226 -226
  418. package/src/common/messaging/connection-error-handler.ts +73 -73
  419. package/src/common/messaging/connection-management.ts +43 -43
  420. package/src/common/messaging/handler.ts +26 -26
  421. package/src/common/messaging/index.ts +19 -19
  422. package/src/common/messaging/proxy-factory.spec.ts +108 -108
  423. package/src/common/messaging/proxy-factory.ts +336 -336
  424. package/src/common/messaging/socket-write-buffer.ts +52 -52
  425. package/src/common/messaging/web-socket-channel.ts +76 -76
  426. package/src/common/nls.ts +151 -151
  427. package/src/common/numbers.ts +21 -21
  428. package/src/common/objects.spec.ts +112 -112
  429. package/src/common/objects.ts +123 -123
  430. package/src/common/os.ts +82 -82
  431. package/src/common/path.spec.ts +415 -415
  432. package/src/common/path.ts +334 -334
  433. package/src/common/paths.ts +250 -250
  434. package/src/common/performance/index.ts +19 -19
  435. package/src/common/performance/measurement-protocol.ts +104 -104
  436. package/src/common/performance/measurement.ts +130 -130
  437. package/src/common/performance/stopwatch.ts +183 -183
  438. package/src/common/preferences/preference-schema.ts +101 -101
  439. package/src/common/preferences/preference-scope.spec.ts +48 -48
  440. package/src/common/preferences/preference-scope.ts +68 -68
  441. package/src/common/prioritizeable.ts +58 -58
  442. package/src/common/progress-service-protocol.ts +35 -35
  443. package/src/common/progress-service.ts +82 -82
  444. package/src/common/promise-util.spec.ts +102 -102
  445. package/src/common/promise-util.ts +143 -143
  446. package/src/common/quick-pick-service.ts +353 -353
  447. package/src/common/reference.spec.ts +145 -145
  448. package/src/common/reference.ts +230 -230
  449. package/src/common/resource.ts +430 -430
  450. package/src/common/selection-command-handler.ts +101 -101
  451. package/src/common/selection-service.spec.ts +43 -43
  452. package/src/common/selection-service.ts +49 -49
  453. package/src/common/selection.ts +50 -50
  454. package/src/common/severity.ts +111 -111
  455. package/src/common/stream.ts +718 -718
  456. package/src/common/strings.ts +231 -231
  457. package/src/common/telemetry.ts +45 -45
  458. package/src/common/ternary-search-tree.ts +417 -417
  459. package/src/common/test/expect.ts +34 -34
  460. package/src/common/test/mock-logger.ts +118 -118
  461. package/src/common/test/mock-menu.ts +35 -35
  462. package/src/common/test/mock-resource-provider.ts +33 -33
  463. package/src/common/theme.ts +68 -68
  464. package/src/common/types.spec.ts +86 -86
  465. package/src/common/types.ts +140 -140
  466. package/src/common/uri-command-handler.spec.ts +90 -90
  467. package/src/common/uri-command-handler.ts +148 -148
  468. package/src/common/uri.spec.ts +278 -278
  469. package/src/common/uri.ts +279 -279
  470. package/src/common/uuid.ts +45 -45
  471. package/src/common/version.ts +17 -17
  472. package/src/common/view-column.ts +33 -33
  473. package/src/common/window.ts +34 -34
  474. package/src/electron-browser/electron-clipboard-service.ts +32 -32
  475. package/src/electron-browser/electron-uri-handler.ts +42 -42
  476. package/src/electron-browser/keyboard/electron-keyboard-layout-change-notifier.ts +39 -39
  477. package/src/electron-browser/keyboard/electron-keyboard-module.ts +28 -28
  478. package/src/electron-browser/menu/electron-context-menu-renderer.ts +122 -122
  479. package/src/electron-browser/menu/electron-main-menu-factory.ts +339 -339
  480. package/src/electron-browser/menu/electron-menu-contribution.ts +506 -506
  481. package/src/electron-browser/menu/electron-menu-module.ts +40 -40
  482. package/src/electron-browser/menu/electron-menu-style.css +110 -110
  483. package/src/electron-browser/messaging/electron-frontend-id-provider.ts +25 -25
  484. package/src/electron-browser/messaging/electron-ipc-connection-source.ts +65 -65
  485. package/src/electron-browser/messaging/electron-local-ws-connection-source.ts +45 -45
  486. package/src/electron-browser/messaging/electron-messaging-frontend-module.ts +78 -78
  487. package/src/electron-browser/messaging/electron-ws-connection-source.ts +38 -38
  488. package/src/electron-browser/preload.ts +264 -264
  489. package/src/electron-browser/request/electron-browser-request-module.ts +26 -26
  490. package/src/electron-browser/token/electron-token-frontend-module.ts +22 -22
  491. package/src/electron-browser/window/electron-frontend-application-state.ts +26 -26
  492. package/src/electron-browser/window/electron-secondary-window-service.ts +35 -35
  493. package/src/electron-browser/window/electron-window-module.ts +48 -48
  494. package/src/electron-browser/window/electron-window-preferences.ts +76 -76
  495. package/src/electron-browser/window/electron-window-service.ts +109 -109
  496. package/src/electron-browser/window/external-app-open-handler.ts +42 -42
  497. package/src/electron-common/electron-api.ts +157 -157
  498. package/src/electron-common/electron-main-window-service.ts +24 -24
  499. package/src/electron-common/electron-token.ts +27 -27
  500. package/src/electron-main/electron-api-main.ts +373 -373
  501. package/src/electron-main/electron-main-application-module.ts +65 -65
  502. package/src/electron-main/electron-main-application.ts +860 -860
  503. package/src/electron-main/electron-main-constants.ts +23 -23
  504. package/src/electron-main/electron-main-window-service-impl.ts +44 -44
  505. package/src/electron-main/electron-security-token-service.ts +36 -36
  506. package/src/electron-main/event-utils.ts +36 -36
  507. package/src/electron-main/messaging/electron-connection-handler.ts +21 -21
  508. package/src/electron-main/messaging/electron-messaging-contribution.ts +143 -143
  509. package/src/electron-main/messaging/electron-messaging-service.ts +35 -35
  510. package/src/electron-main/theia-electron-window.ts +219 -219
  511. package/src/electron-node/cli/electron-backend-cli-module.ts +24 -24
  512. package/src/electron-node/cli/electron-cli-contribution.ts +35 -35
  513. package/src/electron-node/hosting/electron-backend-hosting-module.ts +24 -24
  514. package/src/electron-node/hosting/electron-ws-origin-validator.ts +37 -37
  515. package/src/electron-node/keyboard/electron-backend-keyboard-module.ts +30 -30
  516. package/src/electron-node/keyboard/electron-keyboard-layout-provider.ts +35 -35
  517. package/src/electron-node/request/electron-backend-request-module.ts +23 -23
  518. package/src/electron-node/request/electron-backend-request-service.ts +78 -78
  519. package/src/electron-node/token/electron-token-backend-contribution.ts +48 -48
  520. package/src/electron-node/token/electron-token-backend-module.ts +28 -28
  521. package/src/electron-node/token/electron-token-validator.ts +93 -93
  522. package/src/node/application-server.ts +59 -59
  523. package/src/node/backend-application-config-provider.spec.ts +29 -29
  524. package/src/node/backend-application-config-provider.ts +48 -48
  525. package/src/node/backend-application-module.ts +139 -139
  526. package/src/node/backend-application.ts +374 -374
  527. package/src/node/cli.spec.ts +94 -94
  528. package/src/node/cli.ts +63 -63
  529. package/src/node/console-logger-server.spec.ts +59 -59
  530. package/src/node/console-logger-server.ts +76 -76
  531. package/src/node/debug.ts +30 -30
  532. package/src/node/dynamic-require.ts +56 -56
  533. package/src/node/env-variables/env-variables-server.ts +123 -123
  534. package/src/node/env-variables/index.ts +17 -17
  535. package/src/node/environment-utils.spec.ts +92 -92
  536. package/src/node/environment-utils.ts +66 -66
  537. package/src/node/file-uri.spec.ts +76 -76
  538. package/src/node/filesystem-locking.ts +77 -77
  539. package/src/node/hosting/backend-application-hosts.ts +60 -60
  540. package/src/node/hosting/backend-hosting-module.ts +26 -26
  541. package/src/node/hosting/ws-origin-validator.ts +36 -36
  542. package/src/node/i18n/i18n-backend-module.ts +42 -42
  543. package/src/node/i18n/localization-contribution.ts +112 -112
  544. package/src/node/i18n/localization-provider.ts +125 -125
  545. package/src/node/i18n/localization-server.ts +52 -52
  546. package/src/node/i18n/theia-localization-contribution.ts +40 -40
  547. package/src/node/index.ts +22 -22
  548. package/src/node/key-store-server.ts +162 -162
  549. package/src/node/logger-backend-module.ts +88 -88
  550. package/src/node/logger-cli-contribution.spec.ts +245 -245
  551. package/src/node/logger-cli-contribution.ts +168 -168
  552. package/src/node/main.ts +33 -33
  553. package/src/node/messaging/binary-message-pipe.ts +168 -168
  554. package/src/node/messaging/connection-container-module.ts +96 -96
  555. package/src/node/messaging/default-messaging-service.ts +129 -129
  556. package/src/node/messaging/frontend-connection-service.ts +24 -24
  557. package/src/node/messaging/index.ts +19 -19
  558. package/src/node/messaging/ipc-bootstrap.ts +27 -27
  559. package/src/node/messaging/ipc-channel.ts +77 -77
  560. package/src/node/messaging/ipc-connection-provider.ts +107 -107
  561. package/src/node/messaging/ipc-protocol.ts +76 -76
  562. package/src/node/messaging/messaging-backend-module.ts +52 -52
  563. package/src/node/messaging/messaging-listeners.ts +52 -52
  564. package/src/node/messaging/messaging-service.ts +46 -46
  565. package/src/node/messaging/test/test-web-socket-channel.ts +61 -61
  566. package/src/node/messaging/websocket-endpoint.ts +79 -79
  567. package/src/node/messaging/websocket-frontend-connection-service.ts +186 -186
  568. package/src/node/os-backend-provider.ts +25 -25
  569. package/src/node/performance/index.ts +18 -18
  570. package/src/node/performance/measurement-backend-bindings.ts +35 -35
  571. package/src/node/performance/node-stopwatch.ts +40 -40
  572. package/src/node/process-utils.spec.ts +48 -48
  573. package/src/node/process-utils.ts +102 -102
  574. package/src/node/remote/backend-remote-service.ts +25 -25
  575. package/src/node/remote/remote-cli-contribution.ts +34 -34
  576. package/src/node/remote/remote-copy-contribution.ts +45 -45
  577. package/src/node/request/backend-request-facade.ts +39 -39
  578. package/src/node/request/backend-request-module.ts +25 -25
  579. package/src/node/request/proxy-cli-contribution.ts +65 -65
  580. package/src/node/ws-request-validators.ts +56 -56
  581. package/src/typings/native-keymap.d.ts +108 -108
@@ -1,2271 +1,2271 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { injectable, inject, optional, postConstruct } from 'inversify';
18
- import { ArrayExt, find, toArray, each } from '@phosphor/algorithm';
19
- import {
20
- BoxLayout, BoxPanel, DockLayout, DockPanel, FocusTracker, Layout, Panel, SplitLayout,
21
- SplitPanel, TabBar, Widget, Title
22
- } from '@phosphor/widgets';
23
- import { Message } from '@phosphor/messaging';
24
- import { IDragEvent } from '@phosphor/dragdrop';
25
- import { RecursivePartial, Event as CommonEvent, DisposableCollection, Disposable, environment, isObject } from '../../common';
26
- import { animationFrame } from '../browser';
27
- import { Saveable, SaveableWidget, SaveOptions } from '../saveable';
28
- import { StatusBarImpl, StatusBarEntry, StatusBarAlignment } from '../status-bar/status-bar';
29
- import { TheiaDockPanel, BOTTOM_AREA_ID, MAIN_AREA_ID } from './theia-dock-panel';
30
- import { SidePanelHandler, SidePanel, SidePanelHandlerFactory } from './side-panel-handler';
31
- import { TabBarRendererFactory, SHELL_TABBAR_CONTEXT_MENU, ScrollableTabBar, ToolbarAwareTabBar } from './tab-bars';
32
- import { SplitPositionHandler, SplitPositionOptions } from './split-panels';
33
- import { FrontendApplicationStateService } from '../frontend-application-state';
34
- import { TabBarToolbarRegistry, TabBarToolbarFactory } from './tab-bar-toolbar';
35
- import { ContextKeyService } from '../context-key-service';
36
- import { Emitter } from '../../common/event';
37
- import { waitForRevealed, waitForClosed, PINNED_CLASS } from '../widgets';
38
- import { CorePreferences } from '../core-preferences';
39
- import { BreadcrumbsRendererFactory } from '../breadcrumbs/breadcrumbs-renderer';
40
- import { Deferred } from '../../common/promise-util';
41
- import { SaveableService } from '../saveable-service';
42
- import { nls } from '../../common/nls';
43
- import { SecondaryWindowHandler } from '../secondary-window-handler';
44
- import URI from '../../common/uri';
45
- import { OpenerService } from '../opener-service';
46
- import { PreviewableWidget } from '../widgets/previewable-widget';
47
- import { WindowService } from '../window/window-service';
48
-
49
- /** The class name added to ApplicationShell instances. */
50
- const APPLICATION_SHELL_CLASS = 'theia-ApplicationShell';
51
- /** The class name added to the main and bottom area panels. */
52
- const MAIN_BOTTOM_AREA_CLASS = 'theia-app-centers';
53
- /** Status bar entry identifier for the bottom panel toggle button. */
54
- const BOTTOM_PANEL_TOGGLE_ID = 'bottom-panel-toggle';
55
- /** The class name added to the main area panel. */
56
- const MAIN_AREA_CLASS = 'theia-app-main';
57
- /** The class name added to the bottom area panel. */
58
- const BOTTOM_AREA_CLASS = 'theia-app-bottom';
59
-
60
- export type ApplicationShellLayoutVersion =
61
- /** layout versioning is introduced, unversioned layout are not compatible */
62
- 2.0 |
63
- /** view containers are introduced, backward compatible to 2.0 */
64
- 3.0 |
65
- /** git history view is replaced by a more generic scm history view, backward compatible to 3.0 */
66
- 4.0 |
67
- /** Replace custom/font-awesome icons with codicons */
68
- 5.0 |
69
- /** added the ability to drag and drop view parts between view containers */
70
- 6.0;
71
-
72
- /**
73
- * When a version is increased, make sure to introduce a migration (ApplicationShellLayoutMigration) to this version.
74
- */
75
- export const applicationShellLayoutVersion: ApplicationShellLayoutVersion = 5.0;
76
-
77
- export const ApplicationShellOptions = Symbol('ApplicationShellOptions');
78
- export const DockPanelRendererFactory = Symbol('DockPanelRendererFactory');
79
- export interface DockPanelRendererFactory {
80
- (): DockPanelRenderer
81
- }
82
-
83
- /**
84
- * A renderer for dock panels that supports context menus on tabs.
85
- */
86
- @injectable()
87
- export class DockPanelRenderer implements DockLayout.IRenderer {
88
-
89
- @inject(TheiaDockPanel.Factory)
90
- protected readonly dockPanelFactory: TheiaDockPanel.Factory;
91
-
92
- readonly tabBarClasses: string[] = [];
93
-
94
- private readonly onDidCreateTabBarEmitter = new Emitter<TabBar<Widget>>();
95
-
96
- constructor(
97
- @inject(TabBarRendererFactory) protected readonly tabBarRendererFactory: TabBarRendererFactory,
98
- @inject(TabBarToolbarRegistry) protected readonly tabBarToolbarRegistry: TabBarToolbarRegistry,
99
- @inject(TabBarToolbarFactory) protected readonly tabBarToolbarFactory: TabBarToolbarFactory,
100
- @inject(BreadcrumbsRendererFactory) protected readonly breadcrumbsRendererFactory: BreadcrumbsRendererFactory,
101
- @inject(CorePreferences) protected readonly corePreferences: CorePreferences
102
- ) { }
103
-
104
- get onDidCreateTabBar(): CommonEvent<TabBar<Widget>> {
105
- return this.onDidCreateTabBarEmitter.event;
106
- }
107
-
108
- createTabBar(): TabBar<Widget> {
109
- const getDynamicTabOptions: () => ScrollableTabBar.Options | undefined = () => {
110
- if (this.corePreferences.get('workbench.tab.shrinkToFit.enabled')) {
111
- return {
112
- minimumTabSize: this.corePreferences.get('workbench.tab.shrinkToFit.minimumSize'),
113
- defaultTabSize: this.corePreferences.get('workbench.tab.shrinkToFit.defaultSize')
114
- };
115
- } else {
116
- return undefined;
117
- }
118
- };
119
-
120
- const renderer = this.tabBarRendererFactory();
121
- const tabBar = new ToolbarAwareTabBar(
122
- this.tabBarToolbarRegistry,
123
- this.tabBarToolbarFactory,
124
- this.breadcrumbsRendererFactory,
125
- {
126
- renderer,
127
- // Scroll bar options
128
- handlers: ['drag-thumb', 'keyboard', 'wheel', 'touch'],
129
- useBothWheelAxes: true,
130
- scrollXMarginOffset: 4,
131
- suppressScrollY: true
132
- },
133
- getDynamicTabOptions());
134
- this.tabBarClasses.forEach(c => tabBar.addClass(c));
135
- renderer.tabBar = tabBar;
136
- renderer.contextMenuPath = SHELL_TABBAR_CONTEXT_MENU;
137
- tabBar.currentChanged.connect(this.onCurrentTabChanged, this);
138
- const prefChangeDisposable = this.corePreferences.onPreferenceChanged(change => {
139
- if (change.preferenceName === 'workbench.tab.shrinkToFit.enabled' ||
140
- change.preferenceName === 'workbench.tab.shrinkToFit.minimumSize' ||
141
- change.preferenceName === 'workbench.tab.shrinkToFit.defaultSize') {
142
- tabBar.dynamicTabOptions = getDynamicTabOptions();
143
- }
144
- });
145
- tabBar.disposed.connect(() => {
146
- prefChangeDisposable.dispose();
147
- renderer.dispose();
148
- });
149
- this.onDidCreateTabBarEmitter.fire(tabBar);
150
- return tabBar;
151
- }
152
-
153
- createHandle(): HTMLDivElement {
154
- return DockPanel.defaultRenderer.createHandle();
155
- }
156
-
157
- protected onCurrentTabChanged(sender: ToolbarAwareTabBar, { currentIndex }: TabBar.ICurrentChangedArgs<Widget>): void {
158
- if (currentIndex >= 0) {
159
- sender.revealTab(currentIndex);
160
- }
161
- }
162
- }
163
-
164
- /**
165
- * Data stored while dragging widgets in the shell.
166
- */
167
- interface WidgetDragState {
168
- startTime: number;
169
- leftExpanded: boolean;
170
- rightExpanded: boolean;
171
- bottomExpanded: boolean;
172
- lastDragOver?: IDragEvent;
173
- leaveTimeout?: number;
174
- }
175
-
176
- /**
177
- * The application shell manages the top-level widgets of the application. Use this class to
178
- * add, remove, or activate a widget.
179
- */
180
- @injectable()
181
- export class ApplicationShell extends Widget {
182
-
183
- /**
184
- * The dock panel in the main shell area. This is where editors usually go to.
185
- */
186
- mainPanel: TheiaDockPanel;
187
-
188
- /**
189
- * The dock panel in the bottom shell area. In contrast to the main panel, the bottom panel
190
- * can be collapsed and expanded.
191
- */
192
- bottomPanel: TheiaDockPanel;
193
-
194
- /**
195
- * Handler for the left side panel. The primary application views go here, such as the
196
- * file explorer and the git view.
197
- */
198
- leftPanelHandler: SidePanelHandler;
199
-
200
- /**
201
- * Handler for the right side panel. The secondary application views go here, such as the
202
- * outline view.
203
- */
204
- rightPanelHandler: SidePanelHandler;
205
-
206
- /**
207
- * General options for the application shell.
208
- */
209
- protected options: ApplicationShell.Options;
210
-
211
- /**
212
- * The fixed-size panel shown on top. This one usually holds the main menu.
213
- */
214
- topPanel: Panel;
215
-
216
- /**
217
- * The current state of the bottom panel.
218
- */
219
- protected readonly bottomPanelState: SidePanel.State = {
220
- empty: true,
221
- expansion: SidePanel.ExpansionState.collapsed,
222
- pendingUpdate: Promise.resolve()
223
- };
224
-
225
- private readonly tracker = new FocusTracker<Widget>();
226
- private dragState?: WidgetDragState;
227
- additionalDraggedUris: URI[] | undefined;
228
-
229
- @inject(ContextKeyService)
230
- protected readonly contextKeyService: ContextKeyService;
231
-
232
- @inject(OpenerService)
233
- protected readonly openerService: OpenerService;
234
-
235
- protected readonly onDidAddWidgetEmitter = new Emitter<Widget>();
236
- readonly onDidAddWidget = this.onDidAddWidgetEmitter.event;
237
- protected fireDidAddWidget(widget: Widget): void {
238
- this.onDidAddWidgetEmitter.fire(widget);
239
- }
240
-
241
- protected readonly onDidRemoveWidgetEmitter = new Emitter<Widget>();
242
- readonly onDidRemoveWidget = this.onDidRemoveWidgetEmitter.event;
243
- protected fireDidRemoveWidget(widget: Widget): void {
244
- this.onDidRemoveWidgetEmitter.fire(widget);
245
- }
246
-
247
- protected readonly onDidChangeActiveWidgetEmitter = new Emitter<FocusTracker.IChangedArgs<Widget>>();
248
- readonly onDidChangeActiveWidget = this.onDidChangeActiveWidgetEmitter.event;
249
-
250
- protected readonly onDidChangeCurrentWidgetEmitter = new Emitter<FocusTracker.IChangedArgs<Widget>>();
251
- readonly onDidChangeCurrentWidget = this.onDidChangeCurrentWidgetEmitter.event;
252
-
253
- protected readonly onDidDoubleClickMainAreaEmitter = new Emitter<void>();
254
- readonly onDidDoubleClickMainArea = this.onDidDoubleClickMainAreaEmitter.event;
255
-
256
- @inject(TheiaDockPanel.Factory)
257
- protected readonly dockPanelFactory: TheiaDockPanel.Factory;
258
-
259
- private _mainPanelRenderer: DockPanelRenderer;
260
- get mainPanelRenderer(): DockPanelRenderer {
261
- return this._mainPanelRenderer;
262
- }
263
-
264
- /**
265
- * Construct a new application shell.
266
- */
267
- constructor(
268
- @inject(DockPanelRendererFactory) protected dockPanelRendererFactory: () => DockPanelRenderer,
269
- @inject(StatusBarImpl) protected readonly statusBar: StatusBarImpl,
270
- @inject(SidePanelHandlerFactory) protected readonly sidePanelHandlerFactory: () => SidePanelHandler,
271
- @inject(SplitPositionHandler) protected splitPositionHandler: SplitPositionHandler,
272
- @inject(FrontendApplicationStateService) protected readonly applicationStateService: FrontendApplicationStateService,
273
- @inject(ApplicationShellOptions) @optional() options: RecursivePartial<ApplicationShell.Options> = {},
274
- @inject(CorePreferences) protected readonly corePreferences: CorePreferences,
275
- @inject(SaveableService) protected readonly saveableService: SaveableService,
276
- @inject(SecondaryWindowHandler) protected readonly secondaryWindowHandler: SecondaryWindowHandler,
277
- @inject(WindowService) protected readonly windowService: WindowService
278
- ) {
279
- super(options as Widget.IOptions);
280
-
281
- // Merge the user-defined application options with the default options
282
- this.options = {
283
- bottomPanel: {
284
- ...ApplicationShell.DEFAULT_OPTIONS.bottomPanel,
285
- ...options?.bottomPanel || {}
286
- },
287
- leftPanel: {
288
- ...ApplicationShell.DEFAULT_OPTIONS.leftPanel,
289
- ...options?.leftPanel || {}
290
- },
291
- rightPanel: {
292
- ...ApplicationShell.DEFAULT_OPTIONS.rightPanel,
293
- ...options?.rightPanel || {}
294
- }
295
- };
296
- }
297
-
298
- @postConstruct()
299
- protected init(): void {
300
- this.initializeShell();
301
- this.initSidebarVisibleKeyContext();
302
- this.initFocusKeyContexts();
303
-
304
- if (!environment.electron.is()) {
305
- this.corePreferences.ready.then(() => {
306
- this.setTopPanelVisibility(this.corePreferences['window.menuBarVisibility']);
307
- });
308
- this.corePreferences.onPreferenceChanged(preference => {
309
- if (preference.preferenceName === 'window.menuBarVisibility') {
310
- this.setTopPanelVisibility(preference.newValue);
311
- }
312
- });
313
- }
314
-
315
- this.corePreferences.onPreferenceChanged(preference => {
316
- if (preference.preferenceName === 'window.tabbar.enhancedPreview') {
317
- this.allTabBars.forEach(tabBar => {
318
- tabBar.update();
319
- });
320
- }
321
- });
322
- }
323
-
324
- protected initializeShell(): void {
325
- this.addClass(APPLICATION_SHELL_CLASS);
326
- this.id = 'theia-app-shell';
327
-
328
- this.mainPanel = this.createMainPanel();
329
- this.topPanel = this.createTopPanel();
330
- this.bottomPanel = this.createBottomPanel();
331
-
332
- this.leftPanelHandler = this.sidePanelHandlerFactory();
333
- this.leftPanelHandler.create('left', this.options.leftPanel);
334
- this.leftPanelHandler.dockPanel.widgetAdded.connect((_, widget) => this.fireDidAddWidget(widget));
335
- this.leftPanelHandler.dockPanel.widgetRemoved.connect((_, widget) => this.fireDidRemoveWidget(widget));
336
-
337
- this.rightPanelHandler = this.sidePanelHandlerFactory();
338
- this.rightPanelHandler.create('right', this.options.rightPanel);
339
- this.rightPanelHandler.dockPanel.widgetAdded.connect((_, widget) => this.fireDidAddWidget(widget));
340
- this.rightPanelHandler.dockPanel.widgetRemoved.connect((_, widget) => this.fireDidRemoveWidget(widget));
341
-
342
- this.secondaryWindowHandler.init(this);
343
- this.secondaryWindowHandler.onDidAddWidget(([widget, window]) => this.fireDidAddWidget(widget));
344
- this.secondaryWindowHandler.onDidRemoveWidget(([widget, window]) => this.fireDidRemoveWidget(widget));
345
-
346
- this.layout = this.createLayout();
347
-
348
- this.tracker.currentChanged.connect(this.onCurrentChanged, this);
349
- this.tracker.activeChanged.connect(this.onActiveChanged, this);
350
- }
351
-
352
- protected initSidebarVisibleKeyContext(): void {
353
- const leftSideBarPanel = this.leftPanelHandler.dockPanel;
354
- const sidebarVisibleKey = this.contextKeyService.createKey('sidebarVisible', leftSideBarPanel.isVisible);
355
- const onAfterShow = leftSideBarPanel['onAfterShow'].bind(leftSideBarPanel);
356
- leftSideBarPanel['onAfterShow'] = (msg: Message) => {
357
- onAfterShow(msg);
358
- sidebarVisibleKey.set(true);
359
- };
360
- const onAfterHide = leftSideBarPanel['onAfterHide'].bind(leftSideBarPanel);
361
- leftSideBarPanel['onAfterHide'] = (msg: Message) => {
362
- onAfterHide(msg);
363
- sidebarVisibleKey.set(false);
364
- };
365
- }
366
-
367
- protected initFocusKeyContexts(): void {
368
- const sideBarFocus = this.contextKeyService.createKey<boolean>('sideBarFocus', false);
369
- const panelFocus = this.contextKeyService.createKey<boolean>('panelFocus', false);
370
- const updateFocusContextKeys = () => {
371
- const area = this.activeWidget && this.getAreaFor(this.activeWidget);
372
- sideBarFocus.set(area === 'left');
373
- panelFocus.set(area === 'main');
374
- };
375
- updateFocusContextKeys();
376
- this.onDidChangeActiveWidget(updateFocusContextKeys);
377
- }
378
-
379
- protected setTopPanelVisibility(preference: string): void {
380
- const hiddenPreferences = ['compact', 'hidden'];
381
- this.topPanel.setHidden(hiddenPreferences.includes(preference));
382
- }
383
-
384
- protected override onBeforeAttach(msg: Message): void {
385
- document.addEventListener('p-dragenter', this, true);
386
- document.addEventListener('p-dragover', this, true);
387
- document.addEventListener('p-dragleave', this, true);
388
- document.addEventListener('p-drop', this, true);
389
- }
390
-
391
- protected override onAfterDetach(msg: Message): void {
392
- document.removeEventListener('p-dragenter', this, true);
393
- document.removeEventListener('p-dragover', this, true);
394
- document.removeEventListener('p-dragleave', this, true);
395
- document.removeEventListener('p-drop', this, true);
396
- }
397
-
398
- handleEvent(event: Event): void {
399
- switch (event.type) {
400
- case 'p-dragenter':
401
- this.onDragEnter(event as IDragEvent);
402
- break;
403
- case 'p-dragover':
404
- this.onDragOver(event as IDragEvent);
405
- break;
406
- case 'p-drop':
407
- this.onDrop(event as IDragEvent);
408
- break;
409
- case 'p-dragleave':
410
- this.onDragLeave(event as IDragEvent);
411
- break;
412
- }
413
- }
414
-
415
- protected onDragEnter({ mimeData }: IDragEvent): void {
416
- if (!this.dragState) {
417
- if (mimeData && mimeData.hasData('application/vnd.phosphor.widget-factory')) {
418
- // The drag contains a widget, so we'll track it and expand side panels as needed
419
- this.dragState = {
420
- startTime: performance.now(),
421
- leftExpanded: false,
422
- rightExpanded: false,
423
- bottomExpanded: false
424
- };
425
- }
426
- }
427
- }
428
-
429
- protected onDragOver(event: IDragEvent): void {
430
- const state = this.dragState;
431
- if (state) {
432
- state.lastDragOver = event;
433
- if (state.leaveTimeout) {
434
- window.clearTimeout(state.leaveTimeout);
435
- state.leaveTimeout = undefined;
436
- }
437
- const { clientX, clientY } = event;
438
- const { offsetLeft, offsetTop, clientWidth, clientHeight } = this.node;
439
-
440
- // Don't expand any side panels right after the drag has started
441
- const allowExpansion = performance.now() - state.startTime >= 500;
442
- const expLeft = allowExpansion && clientX >= offsetLeft
443
- && clientX <= offsetLeft + this.options.leftPanel.expandThreshold;
444
- const expRight = allowExpansion && clientX <= offsetLeft + clientWidth
445
- && clientX >= offsetLeft + clientWidth - this.options.rightPanel.expandThreshold;
446
- const expBottom = allowExpansion && !expLeft && !expRight && clientY <= offsetTop + clientHeight
447
- && clientY >= offsetTop + clientHeight - this.options.bottomPanel.expandThreshold;
448
- // eslint-disable-next-line no-null/no-null
449
- if (expLeft && !state.leftExpanded && this.leftPanelHandler.tabBar.currentTitle === null) {
450
- // The mouse cursor is moved close to the left border
451
- this.leftPanelHandler.expand();
452
- this.leftPanelHandler.state.pendingUpdate.then(() => this.dispatchMouseMove());
453
- state.leftExpanded = true;
454
- } else if (!expLeft && state.leftExpanded) {
455
- // The mouse cursor is moved away from the left border
456
- this.leftPanelHandler.collapse();
457
- state.leftExpanded = false;
458
- }
459
- // eslint-disable-next-line no-null/no-null
460
- if (expRight && !state.rightExpanded && this.rightPanelHandler.tabBar.currentTitle === null) {
461
- // The mouse cursor is moved close to the right border
462
- this.rightPanelHandler.expand();
463
- this.rightPanelHandler.state.pendingUpdate.then(() => this.dispatchMouseMove());
464
- state.rightExpanded = true;
465
- } else if (!expRight && state.rightExpanded) {
466
- // The mouse cursor is moved away from the right border
467
- this.rightPanelHandler.collapse();
468
- state.rightExpanded = false;
469
- }
470
- if (expBottom && !state.bottomExpanded && this.bottomPanel.isHidden) {
471
- // The mouse cursor is moved close to the bottom border
472
- this.expandBottomPanel();
473
- this.bottomPanelState.pendingUpdate.then(() => this.dispatchMouseMove());
474
- state.bottomExpanded = true;
475
- } else if (!expBottom && state.bottomExpanded) {
476
- // The mouse cursor is moved away from the bottom border
477
- this.collapseBottomPanel();
478
- state.bottomExpanded = false;
479
- }
480
- }
481
- }
482
-
483
- /**
484
- * This method is called after a side panel has been expanded while dragging a widget. It fires
485
- * a `mousemove` event so that the drag overlay markers are updated correctly in all dock panels.
486
- */
487
- private dispatchMouseMove(): void {
488
- if (this.dragState && this.dragState.lastDragOver) {
489
- const { clientX, clientY } = this.dragState.lastDragOver;
490
- const event = document.createEvent('MouseEvent');
491
- event.initMouseEvent('mousemove', true, true, window, 0, 0, 0,
492
- // eslint-disable-next-line no-null/no-null
493
- clientX, clientY, false, false, false, false, 0, null);
494
- document.dispatchEvent(event);
495
- }
496
- }
497
-
498
- protected onDrop(event: IDragEvent): void {
499
- const state = this.dragState;
500
- if (state) {
501
- if (state.leaveTimeout) {
502
- window.clearTimeout(state.leaveTimeout);
503
- }
504
- this.dragState = undefined;
505
- window.requestAnimationFrame(() => {
506
- // Clean up the side panel state in the next frame
507
- if (this.leftPanelHandler.dockPanel.isEmpty) {
508
- this.leftPanelHandler.collapse();
509
- }
510
- if (this.rightPanelHandler.dockPanel.isEmpty) {
511
- this.rightPanelHandler.collapse();
512
- }
513
- if (this.bottomPanel.isEmpty) {
514
- this.collapseBottomPanel();
515
- }
516
- });
517
- }
518
- }
519
-
520
- protected onDragLeave(event: IDragEvent): void {
521
- const state = this.dragState;
522
- if (state) {
523
- state.lastDragOver = undefined;
524
- if (state.leaveTimeout) {
525
- window.clearTimeout(state.leaveTimeout);
526
- }
527
- state.leaveTimeout = window.setTimeout(() => {
528
- this.dragState = undefined;
529
- if (state.leftExpanded || this.leftPanelHandler.dockPanel.isEmpty) {
530
- this.leftPanelHandler.collapse();
531
- }
532
- if (state.rightExpanded || this.rightPanelHandler.dockPanel.isEmpty) {
533
- this.rightPanelHandler.collapse();
534
- }
535
- if (state.bottomExpanded || this.bottomPanel.isEmpty) {
536
- this.collapseBottomPanel();
537
- }
538
- }, 100);
539
- }
540
- }
541
-
542
- /**
543
- * Create the dock panel in the main shell area.
544
- */
545
- protected createMainPanel(): TheiaDockPanel {
546
- const renderer = this.dockPanelRendererFactory();
547
- renderer.tabBarClasses.push(MAIN_BOTTOM_AREA_CLASS);
548
- renderer.tabBarClasses.push(MAIN_AREA_CLASS);
549
- this._mainPanelRenderer = renderer;
550
- const dockPanel = this.dockPanelFactory({
551
- mode: 'multiple-document',
552
- renderer,
553
- spacing: 0
554
- });
555
- dockPanel.id = MAIN_AREA_ID;
556
- dockPanel.widgetAdded.connect((_, widget) => this.fireDidAddWidget(widget));
557
- dockPanel.widgetRemoved.connect((_, widget) => this.fireDidRemoveWidget(widget));
558
-
559
- const openUri = async (fileUri: URI) => {
560
- try {
561
- const opener = await this.openerService.getOpener(fileUri);
562
- opener.open(fileUri);
563
- } catch (e) {
564
- console.info(`no opener found for '${fileUri}'`);
565
- }
566
- };
567
-
568
- dockPanel.node.addEventListener('drop', event => {
569
- if (event.dataTransfer) {
570
- const uris = this.additionalDraggedUris || ApplicationShell.getDraggedEditorUris(event.dataTransfer);
571
- if (uris.length > 0) {
572
- uris.forEach(openUri);
573
- } else if (event.dataTransfer.files?.length > 0) {
574
- // the files were dragged from the outside the workspace
575
- Array.from(event.dataTransfer.files).forEach(file => {
576
- if (file.path) {
577
- const fileUri = URI.fromComponents({
578
- scheme: 'file',
579
- path: file.path,
580
- authority: '',
581
- query: '',
582
- fragment: ''
583
- });
584
- openUri(fileUri);
585
- }
586
- });
587
- }
588
- }
589
- });
590
-
591
- dockPanel.node.addEventListener('dblclick', event => {
592
- const el = event.target as Element;
593
- if (el.id === MAIN_AREA_ID || el.classList.contains('p-TabBar-content')) {
594
- this.onDidDoubleClickMainAreaEmitter.fire();
595
- }
596
- });
597
-
598
- const handler = (e: DragEvent) => {
599
- if (e.dataTransfer) {
600
- e.dataTransfer.dropEffect = 'link';
601
- e.preventDefault();
602
- e.stopPropagation();
603
- }
604
- };
605
- dockPanel.node.addEventListener('dragover', handler);
606
- dockPanel.node.addEventListener('dragenter', handler);
607
-
608
- return dockPanel;
609
- }
610
-
611
- addAdditionalDraggedEditorUris(uris: URI[]): void {
612
- this.additionalDraggedUris = uris;
613
- }
614
-
615
- clearAdditionalDraggedEditorUris(): void {
616
- this.additionalDraggedUris = undefined;
617
- }
618
-
619
- protected static getDraggedEditorUris(dataTransfer: DataTransfer): URI[] {
620
- const data = dataTransfer.getData('theia-editor-dnd');
621
- return data ? data.split('\n').map(entry => new URI(entry)) : [];
622
- }
623
-
624
- static setDraggedEditorUris(dataTransfer: DataTransfer, uris: URI[]): void {
625
- dataTransfer.setData('theia-editor-dnd', uris.map(uri => uri.toString()).join('\n'));
626
- }
627
-
628
- /**
629
- * Create the dock panel in the bottom shell area.
630
- */
631
- protected createBottomPanel(): TheiaDockPanel {
632
- const renderer = this.dockPanelRendererFactory();
633
- renderer.tabBarClasses.push(MAIN_BOTTOM_AREA_CLASS);
634
- renderer.tabBarClasses.push(BOTTOM_AREA_CLASS);
635
- const dockPanel = this.dockPanelFactory({
636
- mode: 'multiple-document',
637
- renderer,
638
- spacing: 0
639
- });
640
- dockPanel.id = BOTTOM_AREA_ID;
641
- dockPanel.widgetAdded.connect((sender, widget) => {
642
- this.refreshBottomPanelToggleButton();
643
- });
644
- dockPanel.widgetRemoved.connect((sender, widget) => {
645
- if (sender.isEmpty) {
646
- this.collapseBottomPanel();
647
- }
648
- this.refreshBottomPanelToggleButton();
649
- }, this);
650
- dockPanel.node.addEventListener('p-dragenter', event => {
651
- // Make sure that the main panel hides its overlay when the bottom panel is expanded
652
- this.mainPanel.overlay.hide(0);
653
- });
654
- dockPanel.hide();
655
- dockPanel.widgetAdded.connect((_, widget) => this.fireDidAddWidget(widget));
656
- dockPanel.widgetRemoved.connect((_, widget) => this.fireDidRemoveWidget(widget));
657
- return dockPanel;
658
- }
659
-
660
- /**
661
- * Create the top panel, which is used to hold the main menu.
662
- */
663
- protected createTopPanel(): Panel {
664
- const topPanel = new Panel();
665
- topPanel.id = 'theia-top-panel';
666
- topPanel.hide();
667
- return topPanel;
668
- }
669
-
670
- /**
671
- * Create a box layout to assemble the application shell layout.
672
- */
673
- protected createBoxLayout(widgets: Widget[], stretch?: number[], options?: BoxPanel.IOptions): BoxLayout {
674
- const boxLayout = new BoxLayout(options);
675
- for (let i = 0; i < widgets.length; i++) {
676
- if (stretch !== undefined && i < stretch.length) {
677
- BoxPanel.setStretch(widgets[i], stretch[i]);
678
- }
679
- boxLayout.addWidget(widgets[i]);
680
- }
681
- return boxLayout;
682
- }
683
-
684
- /**
685
- * Create a split layout to assemble the application shell layout.
686
- */
687
- protected createSplitLayout(widgets: Widget[], stretch?: number[], options?: Partial<SplitLayout.IOptions>): SplitLayout {
688
- let optParam: SplitLayout.IOptions = { renderer: SplitPanel.defaultRenderer, };
689
- if (options) {
690
- optParam = { ...optParam, ...options };
691
- }
692
- const splitLayout = new SplitLayout(optParam);
693
- for (let i = 0; i < widgets.length; i++) {
694
- if (stretch !== undefined && i < stretch.length) {
695
- SplitPanel.setStretch(widgets[i], stretch[i]);
696
- }
697
- splitLayout.addWidget(widgets[i]);
698
- }
699
- return splitLayout;
700
- }
701
-
702
- /**
703
- * Assemble the application shell layout. Override this method in order to change the arrangement
704
- * of the main area and the side panels.
705
- */
706
- protected createLayout(): Layout {
707
- const bottomSplitLayout = this.createSplitLayout(
708
- [this.mainPanel, this.bottomPanel],
709
- [1, 0],
710
- { orientation: 'vertical', spacing: 0 }
711
- );
712
- const panelForBottomArea = new SplitPanel({ layout: bottomSplitLayout });
713
- panelForBottomArea.id = 'theia-bottom-split-panel';
714
-
715
- const leftRightSplitLayout = this.createSplitLayout(
716
- [this.leftPanelHandler.container, panelForBottomArea, this.rightPanelHandler.container],
717
- [0, 1, 0],
718
- { orientation: 'horizontal', spacing: 0 }
719
- );
720
- const panelForSideAreas = new SplitPanel({ layout: leftRightSplitLayout });
721
- panelForSideAreas.id = 'theia-left-right-split-panel';
722
-
723
- return this.createBoxLayout(
724
- [this.topPanel, panelForSideAreas, this.statusBar],
725
- [0, 1, 0],
726
- { direction: 'top-to-bottom', spacing: 0 }
727
- );
728
- }
729
-
730
- /**
731
- * Create an object that describes the current shell layout. This object may contain references
732
- * to widgets; these need to be transformed before the layout can be serialized.
733
- */
734
- getLayoutData(): ApplicationShell.LayoutData {
735
- return {
736
- version: applicationShellLayoutVersion,
737
- mainPanel: this.mainPanel.saveLayout(),
738
- mainPanelPinned: this.getPinnedMainWidgets(),
739
- bottomPanel: {
740
- config: this.bottomPanel.saveLayout(),
741
- pinned: this.getPinnedBottomWidgets(),
742
- size: this.bottomPanel.isVisible ? this.getBottomPanelSize() : this.bottomPanelState.lastPanelSize,
743
- expanded: this.isExpanded('bottom')
744
- },
745
- leftPanel: this.leftPanelHandler.getLayoutData(),
746
- rightPanel: this.rightPanelHandler.getLayoutData(),
747
- activeWidgetId: this.activeWidget ? this.activeWidget.id : undefined
748
- };
749
- }
750
-
751
- // Get an array corresponding to main panel widgets' pinned state.
752
- getPinnedMainWidgets(): boolean[] {
753
- const pinned: boolean[] = [];
754
-
755
- toArray(this.mainPanel.widgets()).forEach((a, i) => {
756
- pinned[i] = a.title.className.includes(PINNED_CLASS);
757
- });
758
-
759
- return pinned;
760
- }
761
-
762
- // Get an array corresponding to bottom panel widgets' pinned state.
763
- getPinnedBottomWidgets(): boolean[] {
764
- const pinned: boolean[] = [];
765
-
766
- toArray(this.bottomPanel.widgets()).forEach((a, i) => {
767
- pinned[i] = a.title.className.includes(PINNED_CLASS);
768
- });
769
-
770
- return pinned;
771
- }
772
-
773
- /**
774
- * Compute the current height of the bottom panel. This implementation assumes that the container
775
- * of the bottom panel is a `SplitPanel`.
776
- */
777
- protected getBottomPanelSize(): number | undefined {
778
- const parent = this.bottomPanel.parent;
779
- if (parent instanceof SplitPanel && parent.isVisible) {
780
- const index = parent.widgets.indexOf(this.bottomPanel) - 1;
781
- if (index >= 0) {
782
- const handle = parent.handles[index];
783
- if (!handle.classList.contains('p-mod-hidden')) {
784
- const parentHeight = parent.node.clientHeight;
785
- return parentHeight - handle.offsetTop;
786
- }
787
- }
788
- }
789
- }
790
-
791
- /**
792
- * Determine the default size to apply when the bottom panel is expanded for the first time.
793
- */
794
- protected getDefaultBottomPanelSize(): number | undefined {
795
- const parent = this.bottomPanel.parent;
796
- if (parent && parent.isVisible) {
797
- return parent.node.clientHeight * this.options.bottomPanel.initialSizeRatio;
798
- }
799
- }
800
-
801
- /**
802
- * Apply a shell layout that has been previously created with `getLayoutData`.
803
- */
804
- async setLayoutData(layoutData: ApplicationShell.LayoutData): Promise<void> {
805
- const { mainPanel, mainPanelPinned, bottomPanel, leftPanel, rightPanel, activeWidgetId } = layoutData;
806
- if (leftPanel) {
807
- this.leftPanelHandler.setLayoutData(leftPanel);
808
- this.registerWithFocusTracker(leftPanel);
809
- }
810
- if (rightPanel) {
811
- this.rightPanelHandler.setLayoutData(rightPanel);
812
- this.registerWithFocusTracker(rightPanel);
813
- }
814
- // Proceed with the bottom panel once the side panels are set up
815
- await Promise.all([this.leftPanelHandler.state.pendingUpdate, this.rightPanelHandler.state.pendingUpdate]);
816
- if (bottomPanel) {
817
- if (bottomPanel.config) {
818
- this.bottomPanel.restoreLayout(bottomPanel.config);
819
- this.registerWithFocusTracker(bottomPanel.config.main);
820
- }
821
- if (bottomPanel.size) {
822
- this.bottomPanelState.lastPanelSize = bottomPanel.size;
823
- }
824
- if (bottomPanel.expanded) {
825
- this.expandBottomPanel();
826
- } else {
827
- this.collapseBottomPanel();
828
- }
829
- const widgets = toArray(this.bottomPanel.widgets());
830
- this.bottomPanel.markActiveTabBar(widgets[0]?.title);
831
- if (bottomPanel.pinned && bottomPanel.pinned.length === widgets.length) {
832
- widgets.forEach((a, i) => {
833
- if (bottomPanel.pinned![i]) {
834
- a.title.className += ` ${PINNED_CLASS}`;
835
- a.title.closable = false;
836
- }
837
- });
838
- }
839
- this.refreshBottomPanelToggleButton();
840
- }
841
- // Proceed with the main panel once all others are set up
842
- await this.bottomPanelState.pendingUpdate;
843
- if (mainPanel) {
844
- this.mainPanel.restoreLayout(mainPanel);
845
- this.registerWithFocusTracker(mainPanel.main);
846
- const widgets = toArray(this.mainPanel.widgets());
847
- // We don't store information about the last active tabbar
848
- // So we simply mark the first as being active
849
- this.mainPanel.markActiveTabBar(widgets[0]?.title);
850
- if (mainPanelPinned && mainPanelPinned.length === widgets.length) {
851
- widgets.forEach((a, i) => {
852
- if (mainPanelPinned[i]) {
853
- a.title.className += ` ${PINNED_CLASS}`;
854
- a.title.closable = false;
855
- }
856
- });
857
- }
858
- }
859
- if (activeWidgetId) {
860
- this.activateWidget(activeWidgetId);
861
- }
862
- }
863
-
864
- /**
865
- * Modify the height of the bottom panel. This implementation assumes that the container of the
866
- * bottom panel is a `SplitPanel`.
867
- */
868
- protected setBottomPanelSize(size: number): Promise<void> {
869
- const enableAnimation = this.applicationStateService.state === 'ready';
870
- const options: SplitPositionOptions = {
871
- side: 'bottom',
872
- duration: enableAnimation ? this.options.bottomPanel.expandDuration : 0,
873
- referenceWidget: this.bottomPanel
874
- };
875
- const promise = this.splitPositionHandler.setSidePanelSize(this.bottomPanel, size, options);
876
- const result = new Promise<void>(resolve => {
877
- // Resolve the resulting promise in any case, regardless of whether resizing was successful
878
- promise.then(() => resolve(), () => resolve());
879
- });
880
- this.bottomPanelState.pendingUpdate = this.bottomPanelState.pendingUpdate.then(() => result);
881
- return result;
882
- }
883
-
884
- /**
885
- * A promise that is resolved when all currently pending updates are done.
886
- */
887
- get pendingUpdates(): Promise<void> {
888
- return Promise.all([
889
- this.bottomPanelState.pendingUpdate,
890
- this.leftPanelHandler.state.pendingUpdate,
891
- this.rightPanelHandler.state.pendingUpdate
892
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
893
- ]) as Promise<any>;
894
- }
895
-
896
- /**
897
- * Track all widgets that are referenced by the given layout data.
898
- */
899
- protected registerWithFocusTracker(data: DockLayout.ITabAreaConfig | DockLayout.ISplitAreaConfig | SidePanel.LayoutData | null): void {
900
- if (data) {
901
- if (data.type === 'tab-area') {
902
- for (const widget of data.widgets) {
903
- if (widget) {
904
- this.track(widget);
905
- }
906
- }
907
- } else if (data.type === 'split-area') {
908
- for (const child of data.children) {
909
- this.registerWithFocusTracker(child);
910
- }
911
- } else if (data.type === 'sidepanel' && data.items) {
912
- for (const item of data.items) {
913
- if (item.widget) {
914
- this.track(item.widget);
915
- }
916
- }
917
- }
918
- }
919
- }
920
-
921
- /**
922
- * Add a widget to the application shell. The given widget must have a unique `id` property,
923
- * which will be used as the DOM id.
924
- *
925
- * Widgets are removed from the shell by calling their `close` or `dispose` methods.
926
- *
927
- * Widgets added to the top area are not tracked regarding the _current_ and _active_ states.
928
- */
929
- async addWidget(widget: Widget, options?: Readonly<ApplicationShell.WidgetOptions>): Promise<void> {
930
- if (!widget.id) {
931
- console.error('Widgets added to the application shell must have a unique id property.');
932
- return;
933
- }
934
- const { area, addOptions } = this.getInsertionOptions(options);
935
- const sidePanelOptions: SidePanel.WidgetOptions = { rank: options?.rank };
936
- switch (area) {
937
- case 'main':
938
- this.mainPanel.addWidget(widget, addOptions);
939
- break;
940
- case 'top':
941
- this.topPanel.addWidget(widget);
942
- break;
943
- case 'bottom':
944
- this.bottomPanel.addWidget(widget, addOptions);
945
- break;
946
- case 'left':
947
- this.leftPanelHandler.addWidget(widget, sidePanelOptions);
948
- break;
949
- case 'right':
950
- this.rightPanelHandler.addWidget(widget, sidePanelOptions);
951
- break;
952
- case 'secondaryWindow':
953
- /** At the moment, widgets are only moved to this area (i.e. a secondary window) by moving them from one of the other areas. */
954
- throw new Error('Widgets cannot be added directly to a secondary window');
955
- default:
956
- throw new Error('Unexpected area: ' + options?.area);
957
- }
958
- if (area !== 'top') {
959
- this.track(widget);
960
- }
961
- }
962
-
963
- getInsertionOptions(options?: Readonly<ApplicationShell.WidgetOptions>): { area: string; addOptions: TheiaDockPanel.AddOptions; } {
964
- let ref: Widget | undefined = options?.ref;
965
- let area: ApplicationShell.Area = options?.area || 'main';
966
- if (!ref && (area === 'main' || area === 'bottom')) {
967
- const tabBar = this.getTabBarFor(area);
968
- ref = tabBar && tabBar.currentTitle && tabBar.currentTitle.owner || undefined;
969
- }
970
- // make sure that ref belongs to area
971
- area = ref && this.getAreaFor(ref) || area;
972
- const addOptions: TheiaDockPanel.AddOptions = {};
973
- if (ApplicationShell.isOpenToSideMode(options?.mode)) {
974
- const areaPanel = area === 'main' ? this.mainPanel : area === 'bottom' ? this.bottomPanel : undefined;
975
- const sideRef = areaPanel && ref && (options?.mode === 'open-to-left' ?
976
- areaPanel.previousTabBarWidget(ref) :
977
- areaPanel.nextTabBarWidget(ref));
978
- if (sideRef) {
979
- addOptions.ref = sideRef;
980
- } else {
981
- addOptions.ref = ref;
982
- addOptions.mode = options?.mode === 'open-to-left' ? 'split-left' : 'split-right';
983
- }
984
- } else if (ApplicationShell.isReplaceMode(options?.mode)) {
985
- addOptions.ref = options?.ref;
986
- addOptions.closeRef = true;
987
- addOptions.mode = 'tab-after';
988
- } else {
989
- addOptions.ref = ref;
990
- addOptions.mode = options?.mode;
991
- }
992
- return { area, addOptions };
993
- }
994
-
995
- /**
996
- * The widgets contained in the given shell area.
997
- */
998
- getWidgets(area: ApplicationShell.Area): Widget[] {
999
- switch (area) {
1000
- case 'main':
1001
- return toArray(this.mainPanel.widgets());
1002
- case 'top':
1003
- return toArray(this.topPanel.widgets);
1004
- case 'bottom':
1005
- return toArray(this.bottomPanel.widgets());
1006
- case 'left':
1007
- return toArray(this.leftPanelHandler.dockPanel.widgets());
1008
- case 'right':
1009
- return toArray(this.rightPanelHandler.dockPanel.widgets());
1010
- case 'secondaryWindow':
1011
- return toArray(this.secondaryWindowHandler.widgets);
1012
- default:
1013
- throw new Error('Illegal argument: ' + area);
1014
- }
1015
- }
1016
-
1017
- /**
1018
- * Find the widget that contains the given HTML element. The returned widget may be one
1019
- * that is managed by the application shell, or one that is embedded in another widget and
1020
- * not directly managed by the shell, or a tab bar.
1021
- */
1022
- findWidgetForElement(element: HTMLElement): Widget | undefined {
1023
- let widgetNode: HTMLElement | null = element;
1024
- while (widgetNode && !widgetNode.classList.contains('p-Widget')) {
1025
- widgetNode = widgetNode.parentElement;
1026
- }
1027
- if (widgetNode) {
1028
- return this.findWidgetForNode(widgetNode, this);
1029
- }
1030
- return undefined;
1031
- }
1032
-
1033
- private findWidgetForNode(widgetNode: HTMLElement, widget: Widget): Widget | undefined {
1034
- if (widget.node === widgetNode) {
1035
- return widget;
1036
- }
1037
- let result: Widget | undefined;
1038
- each(widget.children(), child => {
1039
- result = this.findWidgetForNode(widgetNode, child);
1040
- return !result;
1041
- });
1042
- return result;
1043
- }
1044
-
1045
- /**
1046
- * Finds the title widget from the tab-bar.
1047
- * @param tabBar used for providing an array of titles.
1048
- * @returns the selected title widget, else returns the currentTitle or undefined.
1049
- */
1050
- findTitle(tabBar: TabBar<Widget>, event?: Event): Title<Widget> | undefined {
1051
- if (event?.target instanceof HTMLElement) {
1052
- const tabNode = event.target;
1053
-
1054
- const titleIndex = Array.from(tabBar.contentNode.getElementsByClassName('p-TabBar-tab'))
1055
- .findIndex(node => node.contains(tabNode));
1056
-
1057
- if (titleIndex !== -1) {
1058
- return tabBar.titles[titleIndex];
1059
- }
1060
-
1061
- }
1062
- return tabBar.currentTitle || undefined;
1063
- }
1064
-
1065
- /**
1066
- * Finds the tab-bar widget.
1067
- * @returns the selected tab-bar, else returns the currentTabBar.
1068
- */
1069
- findTabBar(event?: Event): TabBar<Widget> | undefined {
1070
- if (event?.target instanceof HTMLElement) {
1071
- const tabBar = this.findWidgetForElement(event.target);
1072
- if (tabBar instanceof TabBar) {
1073
- return tabBar;
1074
- }
1075
- }
1076
- return this.currentTabBar;
1077
- }
1078
-
1079
- /**
1080
- * @returns the widget whose title has been targeted by a DOM event on a tabbar, or undefined if none can be found.
1081
- */
1082
- findTargetedWidget(event?: Event): Widget | undefined {
1083
- if (event) {
1084
- const tab = this.findTabBar(event);
1085
- const title = tab && this.findTitle(tab, event);
1086
- return title && title.owner;
1087
- }
1088
- }
1089
-
1090
- /**
1091
- * The current widget in the application shell. The current widget is the last widget that
1092
- * was active and not yet closed. See the remarks to `activeWidget` on what _active_ means.
1093
- */
1094
- get currentWidget(): Widget | undefined {
1095
- return this.tracker.currentWidget || undefined;
1096
- }
1097
-
1098
- /**
1099
- * The active widget in the application shell. The active widget is the one that has focus
1100
- * (either the widget itself or any of its contents).
1101
- *
1102
- * _Note:_ Focus is taken by a widget through the `onActivateRequest` method. It is up to the
1103
- * widget implementation which DOM element will get the focus. The default implementation
1104
- * does not take any focus; in that case the widget is never returned by this property.
1105
- */
1106
- get activeWidget(): Widget | undefined {
1107
- return this.tracker.activeWidget || undefined;
1108
- }
1109
-
1110
- /**
1111
- * Returns the last active widget in the given shell area.
1112
- */
1113
- getCurrentWidget(area: ApplicationShell.Area): Widget | undefined {
1114
- let title: Title<Widget> | null | undefined;
1115
- switch (area) {
1116
- case 'main':
1117
- title = this.mainPanel.currentTitle;
1118
- break;
1119
- case 'bottom':
1120
- title = this.bottomPanel.currentTitle;
1121
- break;
1122
- case 'left':
1123
- title = this.leftPanelHandler.tabBar.currentTitle;
1124
- break;
1125
- case 'right':
1126
- title = this.rightPanelHandler.tabBar.currentTitle;
1127
- break;
1128
- case 'secondaryWindow':
1129
- // The current widget in a secondary window is not tracked.
1130
- return undefined;
1131
- default:
1132
- throw new Error('Illegal argument: ' + area);
1133
- }
1134
- return title ? title.owner : undefined;
1135
- }
1136
-
1137
- /**
1138
- * Handle a change to the current widget.
1139
- */
1140
- private onCurrentChanged(sender: FocusTracker<Widget>, args: FocusTracker.IChangedArgs<Widget>): void {
1141
- this.onDidChangeCurrentWidgetEmitter.fire(args);
1142
- }
1143
-
1144
- protected readonly toDisposeOnActiveChanged = new DisposableCollection();
1145
-
1146
- /**
1147
- * Handle a change to the active widget.
1148
- */
1149
- private onActiveChanged(sender: FocusTracker<Widget>, args: FocusTracker.IChangedArgs<Widget>): void {
1150
- this.toDisposeOnActiveChanged.dispose();
1151
- const { newValue, oldValue } = args;
1152
- if (oldValue) {
1153
- let w: Widget | null = oldValue;
1154
- while (w) {
1155
- // Remove the mark of the previously active widget
1156
- w.title.className = w.title.className.replace(' theia-mod-active', '');
1157
- w = w.parent;
1158
- }
1159
- // Reset the z-index to the default
1160
- // eslint-disable-next-line no-null/no-null
1161
- this.setZIndex(oldValue.node, null);
1162
- }
1163
- if (newValue) {
1164
- let w: Widget | null = newValue;
1165
- while (w) {
1166
- // Mark the tab of the active widget
1167
- w.title.className += ' theia-mod-active';
1168
- w = w.parent;
1169
- }
1170
- // Reveal the title of the active widget in its tab bar
1171
- const tabBar = this.getTabBarFor(newValue);
1172
- if (tabBar instanceof ScrollableTabBar) {
1173
- const index = tabBar.titles.indexOf(newValue.title);
1174
- if (index >= 0) {
1175
- tabBar.revealTab(index);
1176
- }
1177
- }
1178
- const widget = this.toTrackedStack(newValue.id).pop();
1179
- const panel = this.findPanel(widget);
1180
- if (panel) {
1181
- // if widget was undefined, we wouldn't have gotten a panel back before
1182
- panel.markAsCurrent(widget!.title);
1183
- }
1184
- // Add checks to ensure that the 'sash' for left panel is displayed correctly
1185
- if (newValue.node.className === 'p-Widget theia-view-container p-DockPanel-widget') {
1186
- // Set the z-index so elements with `position: fixed` contained in the active widget are displayed correctly
1187
- this.setZIndex(newValue.node, '1');
1188
- }
1189
-
1190
- // activate another widget if an active widget will be closed
1191
- const onCloseRequest = newValue['onCloseRequest'];
1192
- newValue['onCloseRequest'] = msg => {
1193
- const currentTabBar = this.currentTabBar;
1194
- if (currentTabBar) {
1195
- const recentlyUsedInTabBar = currentTabBar['_previousTitle'] as TabBar<Widget>['currentTitle'];
1196
- if (recentlyUsedInTabBar && recentlyUsedInTabBar.owner !== newValue) {
1197
- currentTabBar.currentIndex = ArrayExt.firstIndexOf(currentTabBar.titles, recentlyUsedInTabBar);
1198
- if (currentTabBar.currentTitle) {
1199
- this.activateWidget(currentTabBar.currentTitle.owner.id);
1200
- }
1201
- } else if (!this.activateNextTabInTabBar(currentTabBar)) {
1202
- if (!this.activatePreviousTabBar(currentTabBar)) {
1203
- this.activateNextTabBar(currentTabBar);
1204
- }
1205
- }
1206
- }
1207
- newValue['onCloseRequest'] = onCloseRequest;
1208
- newValue['onCloseRequest'](msg);
1209
- };
1210
- this.toDisposeOnActiveChanged.push(Disposable.create(() => newValue['onCloseRequest'] = onCloseRequest));
1211
- if (PreviewableWidget.is(newValue)) {
1212
- newValue.loaded = true;
1213
- }
1214
- }
1215
- this.onDidChangeActiveWidgetEmitter.fire(args);
1216
- }
1217
-
1218
- /**
1219
- * Set the z-index of the given element and its ancestors to the value `z`.
1220
- */
1221
- private setZIndex(element: HTMLElement, z: string | null): void {
1222
- element.style.zIndex = z || '';
1223
- const parent = element.parentElement;
1224
- if (parent && parent !== this.node) {
1225
- this.setZIndex(parent, z);
1226
- }
1227
- }
1228
-
1229
- /**
1230
- * Track the given widget so it is considered in the `current` and `active` state of the shell.
1231
- */
1232
- protected track(widget: Widget): void {
1233
- if (this.tracker.widgets.indexOf(widget) !== -1) {
1234
- return;
1235
- }
1236
- this.tracker.add(widget);
1237
- this.checkActivation(widget);
1238
- if (ApplicationShell.TrackableWidgetProvider.is(widget)) {
1239
- for (const toTrack of widget.getTrackableWidgets()) {
1240
- this.track(toTrack);
1241
- }
1242
- if (widget.onDidChangeTrackableWidgets) {
1243
- widget.onDidChangeTrackableWidgets(widgets => widgets.forEach(w => this.track(w)));
1244
- }
1245
- }
1246
- }
1247
-
1248
- /**
1249
- * @returns an array of Widgets, all of which are tracked by the focus tracker
1250
- * The first member of the array is the widget whose id is passed in, and the other widgets
1251
- * are its tracked parents in ascending order
1252
- */
1253
- protected toTrackedStack(id: string): Widget[] {
1254
- const tracked = new Map<string, Widget>(this.tracker.widgets.map(w => [w.id, w] as [string, Widget]));
1255
- let current = tracked.get(id);
1256
- const stack: Widget[] = [];
1257
- while (current) {
1258
- if (tracked.has(current.id)) {
1259
- stack.push(current);
1260
- }
1261
- current = current.parent || undefined;
1262
- }
1263
- return stack;
1264
- }
1265
-
1266
- /**
1267
- * Activate a widget in the application shell. This makes the widget visible and usually
1268
- * also assigns focus to it.
1269
- *
1270
- * _Note:_ Focus is taken by a widget through the `onActivateRequest` method. It is up to the
1271
- * widget implementation which DOM element will get the focus. The default implementation
1272
- * does not take any focus.
1273
- *
1274
- * @returns the activated widget if it was found
1275
- */
1276
- async activateWidget(id: string): Promise<Widget | undefined> {
1277
- const stack = this.toTrackedStack(id);
1278
- let current = stack.pop();
1279
- if (current && !this.doActivateWidget(current.id)) {
1280
- return undefined;
1281
- }
1282
- while (current && stack.length) {
1283
- const child = stack.pop()!;
1284
- if (ApplicationShell.TrackableWidgetProvider.is(current) && current.activateWidget) {
1285
- current = current.activateWidget(child.id);
1286
- } else {
1287
- child.activate();
1288
- current = child;
1289
- }
1290
- }
1291
- if (!current) {
1292
- return undefined;
1293
- }
1294
- return Promise.all([
1295
- this.waitForActivation(current.id),
1296
- waitForRevealed(current),
1297
- this.pendingUpdates
1298
- ]).then(() => current, () => undefined);
1299
- }
1300
-
1301
- waitForActivation(id: string): Promise<void> {
1302
- if (this.activeWidget && this.activeWidget.id === id) {
1303
- return Promise.resolve();
1304
- }
1305
- const activation = new Deferred();
1306
- const success = this.onDidChangeActiveWidget(() => {
1307
- if (this.activeWidget && this.activeWidget.id === id) {
1308
- activation.resolve();
1309
- }
1310
- });
1311
- const failure = setTimeout(() => activation.reject(new Error(`Widget with id '${id}' failed to activate.`)), this.activationTimeout + 250);
1312
- return activation.promise.finally(() => {
1313
- success.dispose();
1314
- clearTimeout(failure);
1315
- });
1316
- }
1317
-
1318
- /**
1319
- * Activate top-level area widget.
1320
- */
1321
- protected doActivateWidget(id: string): Widget | undefined {
1322
- let widget = find(this.mainPanel.widgets(), w => w.id === id);
1323
- if (widget) {
1324
- this.mainPanel.activateWidget(widget);
1325
- }
1326
- if (!widget) {
1327
- widget = find(this.bottomPanel.widgets(), w => w.id === id);
1328
- if (widget) {
1329
- this.expandBottomPanel();
1330
- this.bottomPanel.activateWidget(widget);
1331
- }
1332
- }
1333
- if (!widget) {
1334
- widget = this.leftPanelHandler.activate(id);
1335
- }
1336
-
1337
- if (!widget) {
1338
- widget = this.rightPanelHandler.activate(id);
1339
- }
1340
- if (widget) {
1341
- this.windowService.focus();
1342
- return widget;
1343
- }
1344
- return this.secondaryWindowHandler.activateWidget(id);
1345
- }
1346
-
1347
- /**
1348
- * Focus is taken by a widget through the `onActivateRequest` method. It is up to the
1349
- * widget implementation which DOM element will get the focus. The default implementation
1350
- * of Widget does not take any focus. This method can help finding such problems by logging
1351
- * a warning in case a widget was explicitly activated, but did not trigger a change of the
1352
- * `activeWidget` property.
1353
- */
1354
- private checkActivation(widget: Widget): Widget {
1355
- const onActivateRequest = widget['onActivateRequest'].bind(widget);
1356
- widget['onActivateRequest'] = (msg: Message) => {
1357
- onActivateRequest(msg);
1358
- this.assertActivated(widget);
1359
- };
1360
- return widget;
1361
- }
1362
-
1363
- private readonly activationTimeout = 2000;
1364
- private readonly toDisposeOnActivationCheck = new DisposableCollection();
1365
- private assertActivated(widget: Widget): void {
1366
- this.toDisposeOnActivationCheck.dispose();
1367
-
1368
- const onDispose = () => this.toDisposeOnActivationCheck.dispose();
1369
- widget.disposed.connect(onDispose);
1370
- this.toDisposeOnActivationCheck.push(Disposable.create(() => widget.disposed.disconnect(onDispose)));
1371
-
1372
- let start = 0;
1373
- const step: FrameRequestCallback = timestamp => {
1374
- const activeElement = widget.node.ownerDocument.activeElement;
1375
- if (activeElement && widget.node.contains(activeElement)) {
1376
- return;
1377
- }
1378
- if (!start) {
1379
- start = timestamp;
1380
- }
1381
- const delta = timestamp - start;
1382
- if (delta < this.activationTimeout) {
1383
- request = window.requestAnimationFrame(step);
1384
- } else {
1385
- console.warn(`Widget was activated, but did not accept focus after ${this.activationTimeout}ms: ${widget.id}`);
1386
- }
1387
- };
1388
- let request = window.requestAnimationFrame(step);
1389
- this.toDisposeOnActivationCheck.push(Disposable.create(() => window.cancelAnimationFrame(request)));
1390
- }
1391
-
1392
- /**
1393
- * Reveal a widget in the application shell. This makes the widget visible,
1394
- * but does not activate it.
1395
- *
1396
- * @returns the revealed widget if it was found
1397
- */
1398
- async revealWidget(id: string): Promise<Widget | undefined> {
1399
- const stack = this.toTrackedStack(id);
1400
- let current = stack.pop();
1401
- if (current && !this.doRevealWidget(current.id)) {
1402
- return undefined;
1403
- }
1404
- while (current && stack.length) {
1405
- const child = stack.pop()!;
1406
- if (ApplicationShell.TrackableWidgetProvider.is(current) && current.revealWidget) {
1407
- current = current.revealWidget(child.id);
1408
- } else {
1409
- current = child;
1410
- }
1411
- }
1412
- if (!current) {
1413
- return undefined;
1414
- }
1415
- await Promise.all([
1416
- waitForRevealed(current),
1417
- this.pendingUpdates
1418
- ]);
1419
- return current;
1420
- }
1421
-
1422
- /**
1423
- * Reveal top-level area widget.
1424
- */
1425
- protected doRevealWidget(id: string): Widget | undefined {
1426
- let widget = find(this.mainPanel.widgets(), w => w.id === id);
1427
- if (!widget) {
1428
- widget = find(this.bottomPanel.widgets(), w => w.id === id);
1429
- if (widget) {
1430
- this.expandBottomPanel();
1431
- }
1432
- }
1433
- if (widget) {
1434
- const tabBar = this.getTabBarFor(widget);
1435
- if (tabBar) {
1436
- tabBar.currentTitle = widget.title;
1437
- }
1438
- }
1439
- if (!widget) {
1440
- widget = this.leftPanelHandler.expand(id);
1441
- }
1442
- if (!widget) {
1443
- widget = this.rightPanelHandler.expand(id);
1444
- }
1445
- if (widget) {
1446
- this.windowService.focus();
1447
- return widget;
1448
- } else {
1449
- return this.secondaryWindowHandler.revealWidget(id);
1450
- }
1451
- }
1452
-
1453
- /**
1454
- * Expand the named side panel area. This makes sure that the panel is visible, even if there
1455
- * are no widgets in it. If the panel is already visible, nothing happens. If the panel is currently
1456
- * collapsed (see `collapsePanel`) and it contains widgets, the widgets are revealed that were
1457
- * visible before it was collapsed.
1458
- */
1459
- expandPanel(area: ApplicationShell.Area): void {
1460
- switch (area) {
1461
- case 'bottom':
1462
- this.expandBottomPanel();
1463
- break;
1464
- case 'left':
1465
- this.leftPanelHandler.expand();
1466
- break;
1467
- case 'right':
1468
- this.rightPanelHandler.expand();
1469
- break;
1470
- default:
1471
- throw new Error('Area cannot be expanded: ' + area);
1472
- }
1473
- }
1474
-
1475
- /**
1476
- * Adjusts the size of the given area in the application shell.
1477
- *
1478
- * @param size the desired size of the panel in pixels.
1479
- * @param area the area to resize.
1480
- */
1481
- resize(size: number, area: ApplicationShell.Area): void {
1482
- switch (area) {
1483
- case 'bottom':
1484
- if (this.bottomPanel.isHidden) {
1485
- this.bottomPanelState.lastPanelSize = size;
1486
- } else {
1487
- this.setBottomPanelSize(size);
1488
- }
1489
- break;
1490
- case 'left':
1491
- this.leftPanelHandler.resize(size);
1492
- break;
1493
- case 'right':
1494
- this.rightPanelHandler.resize(size);
1495
- break;
1496
- default:
1497
- throw new Error('Area cannot be resized: ' + area);
1498
- }
1499
- }
1500
-
1501
- /**
1502
- * Expand the bottom panel. See `expandPanel` regarding the exact behavior.
1503
- */
1504
- protected expandBottomPanel(): void {
1505
- const bottomPanel = this.bottomPanel;
1506
- if (bottomPanel.isHidden) {
1507
- let relativeSizes: number[] | undefined;
1508
- const parent = bottomPanel.parent;
1509
- if (parent instanceof SplitPanel) {
1510
- relativeSizes = parent.relativeSizes();
1511
- }
1512
- bottomPanel.show();
1513
- if (relativeSizes && parent instanceof SplitPanel) {
1514
- // Make sure that the expansion animation starts at the smallest possible size
1515
- parent.setRelativeSizes(relativeSizes);
1516
- }
1517
-
1518
- let size: number | undefined;
1519
- if (bottomPanel.isEmpty) {
1520
- bottomPanel.node.style.minHeight = '0';
1521
- size = this.options.bottomPanel.emptySize;
1522
- } else if (this.bottomPanelState.lastPanelSize) {
1523
- size = this.bottomPanelState.lastPanelSize;
1524
- } else {
1525
- size = this.getDefaultBottomPanelSize();
1526
- }
1527
- if (size) {
1528
- this.bottomPanelState.expansion = SidePanel.ExpansionState.expanding;
1529
- this.setBottomPanelSize(size).then(() => {
1530
- if (this.bottomPanelState.expansion === SidePanel.ExpansionState.expanding) {
1531
- this.bottomPanelState.expansion = SidePanel.ExpansionState.expanded;
1532
- }
1533
- });
1534
- } else {
1535
- this.bottomPanelState.expansion = SidePanel.ExpansionState.expanded;
1536
- }
1537
- }
1538
- }
1539
-
1540
- /**
1541
- * Collapse the named side panel area. This makes sure that the panel is hidden,
1542
- * increasing the space that is available for other shell areas.
1543
- */
1544
- collapsePanel(area: ApplicationShell.Area): Promise<void> {
1545
- switch (area) {
1546
- case 'bottom':
1547
- return this.collapseBottomPanel();
1548
- case 'left':
1549
- return this.leftPanelHandler.collapse();
1550
- case 'right':
1551
- return this.rightPanelHandler.collapse();
1552
- default:
1553
- throw new Error('Area cannot be collapsed: ' + area);
1554
- }
1555
- }
1556
-
1557
- /**
1558
- * Collapse the bottom panel. All contained widgets are hidden, but not closed.
1559
- * They can be restored by calling `expandBottomPanel`.
1560
- */
1561
- protected collapseBottomPanel(): Promise<void> {
1562
- const bottomPanel = this.bottomPanel;
1563
- if (bottomPanel.isHidden) {
1564
- return Promise.resolve();
1565
- }
1566
- if (this.bottomPanelState.expansion === SidePanel.ExpansionState.expanded) {
1567
- const size = this.getBottomPanelSize();
1568
- if (size) {
1569
- this.bottomPanelState.lastPanelSize = size;
1570
- }
1571
- }
1572
- this.bottomPanelState.expansion = SidePanel.ExpansionState.collapsed;
1573
- bottomPanel.hide();
1574
- return animationFrame();
1575
- }
1576
-
1577
- /**
1578
- * Refresh the toggle button for the bottom panel. This implementation creates a status bar entry
1579
- * and refers to the command `core.toggle.bottom.panel`.
1580
- */
1581
- protected refreshBottomPanelToggleButton(): void {
1582
- if (this.bottomPanel.isEmpty) {
1583
- this.statusBar.removeElement(BOTTOM_PANEL_TOGGLE_ID);
1584
- } else {
1585
- const label = nls.localize('theia/core/common/collapseBottomPanel', 'Toggle Bottom Panel');
1586
- const element: StatusBarEntry = {
1587
- name: label,
1588
- text: '$(codicon-window)',
1589
- alignment: StatusBarAlignment.RIGHT,
1590
- tooltip: label,
1591
- command: 'core.toggle.bottom.panel',
1592
- accessibilityInformation: {
1593
- label: label,
1594
- role: 'button'
1595
- },
1596
- priority: -1000
1597
- };
1598
- this.statusBar.setElement(BOTTOM_PANEL_TOGGLE_ID, element);
1599
- }
1600
- }
1601
-
1602
- /**
1603
- * Check whether the named side panel area is expanded (returns `true`) or collapsed (returns `false`).
1604
- */
1605
- isExpanded(area: ApplicationShell.Area): boolean {
1606
- switch (area) {
1607
- case 'bottom':
1608
- return this.bottomPanelState.expansion === SidePanel.ExpansionState.expanded;
1609
- case 'left':
1610
- return this.leftPanelHandler.state.expansion === SidePanel.ExpansionState.expanded;
1611
- case 'right':
1612
- return this.rightPanelHandler.state.expansion === SidePanel.ExpansionState.expanded;
1613
- default:
1614
- return true;
1615
- }
1616
- }
1617
-
1618
- /**
1619
- * Close all tabs or a selection of tabs in a specific part of the application shell.
1620
- *
1621
- * @param tabBarOrArea
1622
- * Either the name of a shell area or a `TabBar` that is contained in such an area.
1623
- * @param filter
1624
- * If undefined, all tabs are closed; otherwise only those tabs that match the filter are closed.
1625
- */
1626
- async closeTabs(tabBarOrArea: TabBar<Widget> | ApplicationShell.Area,
1627
- filter?: (title: Title<Widget>, index: number) => boolean): Promise<void> {
1628
- const titles: Array<Title<Widget>> = this.getWidgetTitles(tabBarOrArea, filter);
1629
- if (titles.length) {
1630
- await this.closeMany(titles.map(title => title.owner));
1631
- }
1632
- }
1633
-
1634
- saveTabs(tabBarOrArea: TabBar<Widget> | ApplicationShell.Area,
1635
- filter?: (title: Title<Widget>, index: number) => boolean): void {
1636
-
1637
- const titles = this.getWidgetTitles(tabBarOrArea, filter);
1638
- for (let i = 0; i < titles.length; i++) {
1639
- const widget = titles[i].owner;
1640
- const saveable = Saveable.get(widget);
1641
- saveable?.save();
1642
- }
1643
- }
1644
-
1645
- /**
1646
- * Collects all widget titles for the given tab bar or area and optionally filters them.
1647
- *
1648
- * @param tabBarOrArea The tab bar or area to retrieve the widget titles for
1649
- * @param filter The filter to apply to the result
1650
- * @returns The filtered array of widget titles or an empty array
1651
- */
1652
- protected getWidgetTitles(tabBarOrArea: TabBar<Widget> | ApplicationShell.Area,
1653
- filter?: (title: Title<Widget>, index: number) => boolean): Title<Widget>[] {
1654
-
1655
- const titles: Title<Widget>[] = [];
1656
- if (tabBarOrArea === 'main') {
1657
- this.mainAreaTabBars.forEach(tabbar => titles.push(...toArray(tabbar.titles)));
1658
- } else if (tabBarOrArea === 'bottom') {
1659
- this.bottomAreaTabBars.forEach(tabbar => titles.push(...toArray(tabbar.titles)));
1660
- } else if (tabBarOrArea === 'secondaryWindow') {
1661
- titles.push(...this.secondaryWindowHandler.widgets.map(w => w.title));
1662
- } else if (typeof tabBarOrArea === 'string') {
1663
- const tabbar = this.getTabBarFor(tabBarOrArea);
1664
- if (tabbar) {
1665
- titles.push(...toArray(tabbar.titles));
1666
- }
1667
- } else if (tabBarOrArea) {
1668
- titles.push(...toArray(tabBarOrArea.titles));
1669
- }
1670
-
1671
- return filter ? titles.filter(filter) : titles;
1672
- }
1673
-
1674
- /**
1675
- * @param targets the widgets to be closed
1676
- * @return an array of all the widgets that were actually closed.
1677
- */
1678
- async closeMany(targets: Widget[], options?: ApplicationShell.CloseOptions): Promise<Widget[]> {
1679
- if (options?.save === false || await Saveable.confirmSaveBeforeClose(targets, this.widgets.filter(widget => !targets.includes(widget)))) {
1680
- return (await Promise.all(targets.map(target => this.closeWidget(target.id, options)))).filter((widget): widget is Widget => widget !== undefined);
1681
- }
1682
- return [];
1683
- }
1684
-
1685
- /**
1686
- * @returns the widget that was closed, if any, `undefined` otherwise.
1687
- *
1688
- * If your use case requires closing multiple widgets, use {@link ApplicationShell#closeMany} instead. That method handles closing saveable widgets more reliably.
1689
- */
1690
- async closeWidget(id: string, options?: ApplicationShell.CloseOptions): Promise<Widget | undefined> {
1691
- // TODO handle save for composite widgets, i.e. the preference widget has 2 editors
1692
- const stack = this.toTrackedStack(id);
1693
- const current = stack.pop();
1694
- if (!current) {
1695
- return undefined;
1696
- }
1697
- const saveableOptions = options && { shouldSave: () => options.save };
1698
- const pendingClose = SaveableWidget.is(current)
1699
- ? current.closeWithSaving(saveableOptions)
1700
- : (current.close(), waitForClosed(current));
1701
- await Promise.all([
1702
- pendingClose,
1703
- this.pendingUpdates
1704
- ]);
1705
- return stack[0] || current;
1706
- }
1707
-
1708
- /**
1709
- * The shell area name of the currently active tab, or undefined.
1710
- */
1711
- get currentTabArea(): ApplicationShell.Area | undefined {
1712
- const currentWidget = this.currentWidget;
1713
- if (currentWidget) {
1714
- return this.getAreaFor(currentWidget);
1715
- }
1716
- }
1717
-
1718
- /**
1719
- * Determine the name of the shell area where the given widget resides. The result is
1720
- * undefined if the widget does not reside directly in the shell.
1721
- */
1722
- getAreaFor(input: TabBar<Widget> | Widget): ApplicationShell.Area | undefined {
1723
- if (input instanceof TabBar) {
1724
- if (find(this.mainPanel.tabBars(), tb => tb === input)) {
1725
- return 'main';
1726
- }
1727
- if (find(this.bottomPanel.tabBars(), tb => tb === input)) {
1728
- return 'bottom';
1729
- }
1730
- if (this.leftPanelHandler.tabBar === input) {
1731
- return 'left';
1732
- }
1733
- if (this.rightPanelHandler.tabBar === input) {
1734
- return 'right';
1735
- }
1736
- }
1737
- const widget = this.toTrackedStack(input.id).pop();
1738
- if (!widget) {
1739
- return undefined;
1740
- }
1741
- const title = widget.title;
1742
- const mainPanelTabBar = this.mainPanel.findTabBar(title);
1743
- if (mainPanelTabBar) {
1744
- return 'main';
1745
- }
1746
- const bottomPanelTabBar = this.bottomPanel.findTabBar(title);
1747
- if (bottomPanelTabBar) {
1748
- return 'bottom';
1749
- }
1750
- if (ArrayExt.firstIndexOf(this.leftPanelHandler.tabBar.titles, title) > -1) {
1751
- return 'left';
1752
- }
1753
- if (ArrayExt.firstIndexOf(this.rightPanelHandler.tabBar.titles, title) > -1) {
1754
- return 'right';
1755
- }
1756
- if (this.secondaryWindowHandler.widgets.includes(widget)) {
1757
- return 'secondaryWindow';
1758
- }
1759
- return undefined;
1760
- }
1761
-
1762
- protected getAreaPanelFor(input: Widget): DockPanel | undefined {
1763
- const widget = this.toTrackedStack(input.id).pop();
1764
- if (!widget) {
1765
- return undefined;
1766
- }
1767
- return this.findPanel(widget);
1768
- }
1769
-
1770
- /**
1771
- * Find the shell panel this top-level widget is part of
1772
- */
1773
- protected findPanel(widget: Widget | undefined): TheiaDockPanel | undefined {
1774
- if (!widget) {
1775
- return undefined;
1776
- }
1777
- const title = widget.title;
1778
- const mainPanelTabBar = this.mainPanel.findTabBar(title);
1779
- if (mainPanelTabBar) {
1780
- return this.mainPanel;
1781
- }
1782
- const bottomPanelTabBar = this.bottomPanel.findTabBar(title);
1783
- if (bottomPanelTabBar) {
1784
- return this.bottomPanel;
1785
- }
1786
- if (ArrayExt.firstIndexOf(this.leftPanelHandler.tabBar.titles, title) > -1) {
1787
- return this.leftPanelHandler.dockPanel;
1788
- }
1789
- if (ArrayExt.firstIndexOf(this.rightPanelHandler.tabBar.titles, title) > -1) {
1790
- return this.rightPanelHandler.dockPanel;
1791
- }
1792
- return undefined;
1793
- }
1794
-
1795
- /**
1796
- * Return the tab bar that has the currently active widget, or undefined.
1797
- */
1798
- get currentTabBar(): TabBar<Widget> | undefined {
1799
- const currentWidget = this.currentWidget;
1800
- if (currentWidget) {
1801
- return this.getTabBarFor(currentWidget);
1802
- }
1803
- }
1804
-
1805
- /**
1806
- * Return the tab bar in the given shell area, or the tab bar that has the given widget, or undefined.
1807
- */
1808
- getTabBarFor(widgetOrArea: Widget | ApplicationShell.Area): TabBar<Widget> | undefined {
1809
- if (typeof widgetOrArea === 'string') {
1810
- switch (widgetOrArea) {
1811
- case 'main':
1812
- return this.mainPanel.currentTabBar;
1813
- case 'bottom':
1814
- return this.bottomPanel.currentTabBar;
1815
- case 'left':
1816
- return this.leftPanelHandler.tabBar;
1817
- case 'right':
1818
- return this.rightPanelHandler.tabBar;
1819
- case 'secondaryWindow':
1820
- // Secondary windows don't have a tab bar
1821
- return undefined;
1822
- default:
1823
- throw new Error('Illegal argument: ' + widgetOrArea);
1824
- }
1825
- }
1826
- const widget = this.toTrackedStack(widgetOrArea.id).pop();
1827
- if (!widget) {
1828
- return undefined;
1829
- }
1830
- const widgetTitle = widget.title;
1831
- const mainPanelTabBar = this.mainPanel.findTabBar(widgetTitle);
1832
- if (mainPanelTabBar) {
1833
- return mainPanelTabBar;
1834
- }
1835
- const bottomPanelTabBar = this.bottomPanel.findTabBar(widgetTitle);
1836
- if (bottomPanelTabBar) {
1837
- return bottomPanelTabBar;
1838
- }
1839
- const leftPanelTabBar = this.leftPanelHandler.tabBar;
1840
- if (ArrayExt.firstIndexOf(leftPanelTabBar.titles, widgetTitle) > -1) {
1841
- return leftPanelTabBar;
1842
- }
1843
- const rightPanelTabBar = this.rightPanelHandler.tabBar;
1844
- if (ArrayExt.firstIndexOf(rightPanelTabBar.titles, widgetTitle) > -1) {
1845
- return rightPanelTabBar;
1846
- }
1847
- return undefined;
1848
- }
1849
-
1850
- /**
1851
- * The tab bars contained in the main shell area. If there is no widget in the main area, the
1852
- * returned array is empty.
1853
- */
1854
- get mainAreaTabBars(): TabBar<Widget>[] {
1855
- return toArray(this.mainPanel.tabBars());
1856
- }
1857
-
1858
- /**
1859
- * The tab bars contained in the bottom shell area. If there is no widget in the bottom area,
1860
- * the returned array is empty.
1861
- */
1862
- get bottomAreaTabBars(): TabBar<Widget>[] {
1863
- return toArray(this.bottomPanel.tabBars());
1864
- }
1865
-
1866
- /**
1867
- * The tab bars contained in all shell areas.
1868
- */
1869
- get allTabBars(): TabBar<Widget>[] {
1870
- return [...this.mainAreaTabBars, ...this.bottomAreaTabBars, this.leftPanelHandler.tabBar, this.rightPanelHandler.tabBar];
1871
- }
1872
-
1873
- /*
1874
- * Activate the next tab in the current tab bar.
1875
- */
1876
- activateNextTabInTabBar(current: TabBar<Widget> | undefined = this.currentTabBar): boolean {
1877
- const index = this.nextTabIndexInTabBar(current);
1878
- if (!current || index === -1) {
1879
- return false;
1880
- }
1881
- current.currentIndex = index;
1882
- if (current.currentTitle) {
1883
- this.activateWidget(current.currentTitle.owner.id);
1884
- }
1885
- return true;
1886
- }
1887
-
1888
- nextTabIndexInTabBar(current: TabBar<Widget> | undefined = this.currentTabBar): number {
1889
- if (!current || current.titles.length <= 1) {
1890
- return -1;
1891
- }
1892
- const index = current.currentIndex;
1893
- if (index === -1) {
1894
- return -1;
1895
- }
1896
- if (index < current.titles.length - 1) {
1897
- return index + 1;
1898
- }
1899
- // last item in tab bar. select the previous one.
1900
- if (index === current.titles.length - 1) {
1901
- return index - 1;
1902
- }
1903
- return 0;
1904
- }
1905
-
1906
- activateNextTab(): boolean {
1907
- const current = this.currentTabBar;
1908
- if (current) {
1909
- const ci = current.currentIndex;
1910
- if (ci !== -1) {
1911
- if (ci < current.titles.length - 1) {
1912
- current.currentIndex += 1;
1913
- if (current.currentTitle) {
1914
- this.activateWidget(current.currentTitle.owner.id);
1915
- }
1916
- return true;
1917
- } else if (ci === current.titles.length - 1) {
1918
- return this.activateNextTabBar(current);
1919
- }
1920
- }
1921
- }
1922
- return false;
1923
- }
1924
-
1925
- activateNextTabBar(current: TabBar<Widget> | undefined = this.currentTabBar): boolean {
1926
- const nextBar = this.nextTabBar(current);
1927
- if (nextBar) {
1928
- nextBar.currentIndex = 0;
1929
- if (nextBar.currentTitle) {
1930
- this.activateWidget(nextBar.currentTitle.owner.id);
1931
- }
1932
- return true;
1933
- }
1934
- return false;
1935
- }
1936
-
1937
- /**
1938
- * Return the tab bar next to the given tab bar; return the given tab bar if there is no adjacent one.
1939
- */
1940
- nextTabBar(current: TabBar<Widget> | undefined = this.currentTabBar): TabBar<Widget> | undefined {
1941
- let bars = toArray(this.bottomPanel.tabBars());
1942
- let len = bars.length;
1943
- let ci = ArrayExt.firstIndexOf(bars, current);
1944
- if (ci < 0) {
1945
- bars = toArray(this.mainPanel.tabBars());
1946
- len = bars.length;
1947
- ci = ArrayExt.firstIndexOf(bars, current);
1948
- }
1949
- if (ci >= 0 && ci < len - 1) {
1950
- return bars[ci + 1];
1951
- } else if (ci >= 0 && ci === len - 1) {
1952
- return bars[0];
1953
- } else {
1954
- return current;
1955
- }
1956
- }
1957
-
1958
- /*
1959
- * Activate the previous tab in the current tab bar.
1960
- */
1961
- activatePreviousTabInTabBar(current: TabBar<Widget> | undefined = this.currentTabBar): boolean {
1962
- const index = this.previousTabIndexInTabBar(current);
1963
- if (!current || index === -1) {
1964
- return false;
1965
- }
1966
- current.currentIndex = index;
1967
- if (current.currentTitle) {
1968
- this.activateWidget(current.currentTitle.owner.id);
1969
- }
1970
- return true;
1971
- }
1972
-
1973
- previousTabIndexInTabBar(current: TabBar<Widget> | undefined = this.currentTabBar): number {
1974
- if (!current || current.titles.length <= 1) {
1975
- return -1;
1976
- }
1977
- const index = current.currentIndex;
1978
- if (index === -1) {
1979
- return -1;
1980
- }
1981
- if (index > 0) {
1982
- return index - 1;
1983
- }
1984
- return current.titles.length - 1;
1985
- }
1986
-
1987
- activatePreviousTab(): boolean {
1988
- const current = this.currentTabBar;
1989
- if (current) {
1990
- const ci = current.currentIndex;
1991
- if (ci !== -1) {
1992
- if (ci > 0) {
1993
- current.currentIndex -= 1;
1994
- if (current.currentTitle) {
1995
- this.activateWidget(current.currentTitle.owner.id);
1996
- }
1997
- return true;
1998
- } else if (ci === 0) {
1999
- if (current && current.titles.length > 0) {
2000
- current.currentIndex = current.titles.length - 1;
2001
- if (current.currentTitle) {
2002
- this.activateWidget(current.currentTitle.owner.id);
2003
- }
2004
- return true;
2005
- }
2006
- return this.activatePreviousTabBar(current);
2007
- }
2008
- }
2009
- }
2010
- return false;
2011
- }
2012
-
2013
- activatePreviousTabBar(current: TabBar<Widget> | undefined = this.currentTabBar): boolean {
2014
- const prevBar = this.previousTabBar(current);
2015
- if (!prevBar) {
2016
- return false;
2017
- }
2018
- if (!prevBar.currentTitle) {
2019
- prevBar.currentIndex = prevBar.titles.length - 1;
2020
- }
2021
- if (prevBar.currentTitle) {
2022
- this.activateWidget(prevBar.currentTitle.owner.id);
2023
- }
2024
- return true;
2025
- }
2026
-
2027
- /**
2028
- * Return the tab bar previous to the given tab bar; return the given tab bar if there is no adjacent one.
2029
- */
2030
- previousTabBar(current: TabBar<Widget> | undefined = this.currentTabBar): TabBar<Widget> | undefined {
2031
- const bars = toArray(this.mainPanel.tabBars());
2032
- const len = bars.length;
2033
- const ci = ArrayExt.firstIndexOf(bars, current);
2034
- if (ci > 0) {
2035
- return bars[ci - 1];
2036
- } else if (ci === 0) {
2037
- return bars[len - 1];
2038
- } else {
2039
- return current;
2040
- }
2041
- }
2042
-
2043
- /**
2044
- * Test whether the current widget is dirty.
2045
- */
2046
- canSave(): boolean {
2047
- return this.saveableService.canSave(this.currentWidget);
2048
- }
2049
-
2050
- /**
2051
- * Save the current widget if it is dirty.
2052
- */
2053
- async save(options?: SaveOptions): Promise<void> {
2054
- await this.saveableService.save(this.currentWidget, options);
2055
- }
2056
-
2057
- /**
2058
- * Test whether there is a dirty widget.
2059
- */
2060
- canSaveAll(): boolean {
2061
- return this.tracker.widgets.some(widget => this.saveableService.canSave(widget));
2062
- }
2063
-
2064
- /**
2065
- * Save all dirty widgets.
2066
- */
2067
- async saveAll(options?: SaveOptions): Promise<void> {
2068
- for (const widget of this.widgets) {
2069
- if (Saveable.isDirty(widget) && this.saveableService.canSaveNotSaveAs(widget)) {
2070
- await this.saveableService.save(widget, options);
2071
- }
2072
- }
2073
- }
2074
-
2075
- /**
2076
- * Returns a snapshot of all tracked widgets to allow async modifications.
2077
- */
2078
- get widgets(): ReadonlyArray<Widget> {
2079
- return [...this.tracker.widgets];
2080
- }
2081
-
2082
- getWidgetById(id: string): Widget | undefined {
2083
- for (const widget of this.tracker.widgets) {
2084
- if (widget.id === id) {
2085
- return widget;
2086
- }
2087
- }
2088
- return undefined;
2089
- }
2090
-
2091
- canToggleMaximized(widget: Widget | undefined = this.currentWidget): boolean {
2092
- const area = widget && this.getAreaFor(widget);
2093
- return area === 'main' || area === 'bottom';
2094
- }
2095
-
2096
- toggleMaximized(widget: Widget | undefined = this.currentWidget): void {
2097
- const area = widget && this.getAreaPanelFor(widget);
2098
- if (area instanceof TheiaDockPanel && (area === this.mainPanel || area === this.bottomPanel)) {
2099
- area.toggleMaximized();
2100
- this.revealWidget(widget!.id);
2101
- }
2102
- }
2103
-
2104
- }
2105
-
2106
- /**
2107
- * The namespace for `ApplicationShell` class statics.
2108
- */
2109
- export namespace ApplicationShell {
2110
- /**
2111
- * The areas of the application shell where widgets can reside.
2112
- */
2113
- export type Area = 'main' | 'top' | 'left' | 'right' | 'bottom' | 'secondaryWindow';
2114
-
2115
- export const areaLabels: Record<Area, string> = {
2116
- main: nls.localizeByDefault('Main'),
2117
- top: nls.localizeByDefault('Top'),
2118
- left: nls.localizeByDefault('Left'),
2119
- right: nls.localizeByDefault('Right'),
2120
- bottom: nls.localizeByDefault('Bottom'),
2121
- secondaryWindow: nls.localize('theia/shell-area/secondary', 'Secondary Window'),
2122
- };
2123
-
2124
- /**
2125
- * The _side areas_ are those shell areas that can be collapsed and expanded,
2126
- * i.e. `left`, `right`, and `bottom`.
2127
- */
2128
- export function isSideArea(area?: string): area is 'left' | 'right' | 'bottom' {
2129
- return area === 'left' || area === 'right' || area === 'bottom';
2130
- }
2131
-
2132
- export function isValidArea(area?: unknown): area is ApplicationShell.Area {
2133
- const areas = ['main', 'top', 'left', 'right', 'bottom', 'secondaryWindow'];
2134
- return typeof area === 'string' && areas.includes(area);
2135
- }
2136
-
2137
- /**
2138
- * General options for the application shell. These are passed on construction and can be modified
2139
- * through dependency injection (`ApplicationShellOptions` symbol).
2140
- */
2141
- export interface Options extends Widget.IOptions {
2142
- bottomPanel: BottomPanelOptions;
2143
- leftPanel: SidePanel.Options;
2144
- rightPanel: SidePanel.Options;
2145
- }
2146
-
2147
- export interface BottomPanelOptions extends SidePanel.Options {
2148
- }
2149
-
2150
- /**
2151
- * The default values for application shell options.
2152
- */
2153
- export const DEFAULT_OPTIONS = Object.freeze(<Options>{
2154
- bottomPanel: Object.freeze(<BottomPanelOptions>{
2155
- emptySize: 140,
2156
- expandThreshold: 160,
2157
- expandDuration: 0,
2158
- initialSizeRatio: 0.382
2159
- }),
2160
- leftPanel: Object.freeze(<SidePanel.Options>{
2161
- emptySize: 140,
2162
- expandThreshold: 140,
2163
- expandDuration: 0,
2164
- initialSizeRatio: 0.191
2165
- }),
2166
- rightPanel: Object.freeze(<SidePanel.Options>{
2167
- emptySize: 140,
2168
- expandThreshold: 140,
2169
- expandDuration: 0,
2170
- initialSizeRatio: 0.191
2171
- })
2172
- });
2173
-
2174
- /**
2175
- * Whether a widget should be opened to the side tab bar relatively to the reference widget.
2176
- */
2177
- export type OpenToSideMode = 'open-to-left' | 'open-to-right';
2178
-
2179
- export function isOpenToSideMode(mode: unknown): mode is OpenToSideMode {
2180
- return mode === 'open-to-left' || mode === 'open-to-right';
2181
- }
2182
-
2183
- /**
2184
- * Whether the `ref` of the options widget should be replaced.
2185
- */
2186
- export type ReplaceMode = 'tab-replace';
2187
-
2188
- export function isReplaceMode(mode: unknown): mode is ReplaceMode {
2189
- return mode === 'tab-replace';
2190
- }
2191
-
2192
- /**
2193
- * Options for adding a widget to the application shell.
2194
- */
2195
- export interface WidgetOptions extends SidePanel.WidgetOptions {
2196
- /**
2197
- * The area of the application shell where the widget will reside.
2198
- */
2199
- area?: Area;
2200
- /**
2201
- * The insertion mode for adding the widget.
2202
- *
2203
- * The default is `'tab-after'`.
2204
- */
2205
- mode?: DockLayout.InsertMode | OpenToSideMode | ReplaceMode
2206
- /**
2207
- * The reference widget for the insert location.
2208
- *
2209
- * The default is `undefined`.
2210
- */
2211
- ref?: Widget;
2212
- }
2213
-
2214
- export interface CloseOptions {
2215
- /**
2216
- * if optional then a user will be prompted
2217
- * if undefined then close will be canceled
2218
- * if true then will be saved on close
2219
- * if false then won't be saved on close
2220
- */
2221
- save?: boolean | undefined
2222
- }
2223
-
2224
- /**
2225
- * Data to save and load the application shell layout.
2226
- */
2227
- export interface LayoutData {
2228
- version?: string | ApplicationShellLayoutVersion,
2229
- mainPanel?: DockPanel.ILayoutConfig;
2230
- mainPanelPinned?: boolean[];
2231
- bottomPanel?: BottomPanelLayoutData;
2232
- leftPanel?: SidePanel.LayoutData;
2233
- rightPanel?: SidePanel.LayoutData;
2234
- activeWidgetId?: string;
2235
- }
2236
-
2237
- /**
2238
- * Data to save and load the bottom panel layout.
2239
- */
2240
- export interface BottomPanelLayoutData {
2241
- config?: DockPanel.ILayoutConfig;
2242
- size?: number;
2243
- expanded?: boolean;
2244
- pinned?: boolean[];
2245
- }
2246
-
2247
- /**
2248
- * Exposes widgets which activation state should be tracked by shell.
2249
- */
2250
- export interface TrackableWidgetProvider {
2251
- getTrackableWidgets(): Widget[]
2252
- readonly onDidChangeTrackableWidgets?: CommonEvent<Widget[]>
2253
- /**
2254
- * Make visible and focus a trackable widget for the given id.
2255
- * If not implemented then `activate` request will be sent to a child widget directly.
2256
- */
2257
- activateWidget?(id: string): Widget | undefined;
2258
- /**
2259
- * Make visible a trackable widget for the given id.
2260
- * If not implemented then a widget should be always visible when an owner is visible.
2261
- */
2262
- revealWidget?(id: string): Widget | undefined;
2263
- }
2264
-
2265
- export namespace TrackableWidgetProvider {
2266
- export function is(widget: unknown): widget is TrackableWidgetProvider {
2267
- return isObject(widget) && 'getTrackableWidgets' in widget;
2268
- }
2269
- }
2270
-
2271
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { injectable, inject, optional, postConstruct } from 'inversify';
18
+ import { ArrayExt, find, toArray, each } from '@phosphor/algorithm';
19
+ import {
20
+ BoxLayout, BoxPanel, DockLayout, DockPanel, FocusTracker, Layout, Panel, SplitLayout,
21
+ SplitPanel, TabBar, Widget, Title
22
+ } from '@phosphor/widgets';
23
+ import { Message } from '@phosphor/messaging';
24
+ import { IDragEvent } from '@phosphor/dragdrop';
25
+ import { RecursivePartial, Event as CommonEvent, DisposableCollection, Disposable, environment, isObject } from '../../common';
26
+ import { animationFrame } from '../browser';
27
+ import { Saveable, SaveableWidget, SaveOptions } from '../saveable';
28
+ import { StatusBarImpl, StatusBarEntry, StatusBarAlignment } from '../status-bar/status-bar';
29
+ import { TheiaDockPanel, BOTTOM_AREA_ID, MAIN_AREA_ID } from './theia-dock-panel';
30
+ import { SidePanelHandler, SidePanel, SidePanelHandlerFactory } from './side-panel-handler';
31
+ import { TabBarRendererFactory, SHELL_TABBAR_CONTEXT_MENU, ScrollableTabBar, ToolbarAwareTabBar } from './tab-bars';
32
+ import { SplitPositionHandler, SplitPositionOptions } from './split-panels';
33
+ import { FrontendApplicationStateService } from '../frontend-application-state';
34
+ import { TabBarToolbarRegistry, TabBarToolbarFactory } from './tab-bar-toolbar';
35
+ import { ContextKeyService } from '../context-key-service';
36
+ import { Emitter } from '../../common/event';
37
+ import { waitForRevealed, waitForClosed, PINNED_CLASS } from '../widgets';
38
+ import { CorePreferences } from '../core-preferences';
39
+ import { BreadcrumbsRendererFactory } from '../breadcrumbs/breadcrumbs-renderer';
40
+ import { Deferred } from '../../common/promise-util';
41
+ import { SaveableService } from '../saveable-service';
42
+ import { nls } from '../../common/nls';
43
+ import { SecondaryWindowHandler } from '../secondary-window-handler';
44
+ import URI from '../../common/uri';
45
+ import { OpenerService } from '../opener-service';
46
+ import { PreviewableWidget } from '../widgets/previewable-widget';
47
+ import { WindowService } from '../window/window-service';
48
+
49
+ /** The class name added to ApplicationShell instances. */
50
+ const APPLICATION_SHELL_CLASS = 'theia-ApplicationShell';
51
+ /** The class name added to the main and bottom area panels. */
52
+ const MAIN_BOTTOM_AREA_CLASS = 'theia-app-centers';
53
+ /** Status bar entry identifier for the bottom panel toggle button. */
54
+ const BOTTOM_PANEL_TOGGLE_ID = 'bottom-panel-toggle';
55
+ /** The class name added to the main area panel. */
56
+ const MAIN_AREA_CLASS = 'theia-app-main';
57
+ /** The class name added to the bottom area panel. */
58
+ const BOTTOM_AREA_CLASS = 'theia-app-bottom';
59
+
60
+ export type ApplicationShellLayoutVersion =
61
+ /** layout versioning is introduced, unversioned layout are not compatible */
62
+ 2.0 |
63
+ /** view containers are introduced, backward compatible to 2.0 */
64
+ 3.0 |
65
+ /** git history view is replaced by a more generic scm history view, backward compatible to 3.0 */
66
+ 4.0 |
67
+ /** Replace custom/font-awesome icons with codicons */
68
+ 5.0 |
69
+ /** added the ability to drag and drop view parts between view containers */
70
+ 6.0;
71
+
72
+ /**
73
+ * When a version is increased, make sure to introduce a migration (ApplicationShellLayoutMigration) to this version.
74
+ */
75
+ export const applicationShellLayoutVersion: ApplicationShellLayoutVersion = 5.0;
76
+
77
+ export const ApplicationShellOptions = Symbol('ApplicationShellOptions');
78
+ export const DockPanelRendererFactory = Symbol('DockPanelRendererFactory');
79
+ export interface DockPanelRendererFactory {
80
+ (): DockPanelRenderer
81
+ }
82
+
83
+ /**
84
+ * A renderer for dock panels that supports context menus on tabs.
85
+ */
86
+ @injectable()
87
+ export class DockPanelRenderer implements DockLayout.IRenderer {
88
+
89
+ @inject(TheiaDockPanel.Factory)
90
+ protected readonly dockPanelFactory: TheiaDockPanel.Factory;
91
+
92
+ readonly tabBarClasses: string[] = [];
93
+
94
+ private readonly onDidCreateTabBarEmitter = new Emitter<TabBar<Widget>>();
95
+
96
+ constructor(
97
+ @inject(TabBarRendererFactory) protected readonly tabBarRendererFactory: TabBarRendererFactory,
98
+ @inject(TabBarToolbarRegistry) protected readonly tabBarToolbarRegistry: TabBarToolbarRegistry,
99
+ @inject(TabBarToolbarFactory) protected readonly tabBarToolbarFactory: TabBarToolbarFactory,
100
+ @inject(BreadcrumbsRendererFactory) protected readonly breadcrumbsRendererFactory: BreadcrumbsRendererFactory,
101
+ @inject(CorePreferences) protected readonly corePreferences: CorePreferences
102
+ ) { }
103
+
104
+ get onDidCreateTabBar(): CommonEvent<TabBar<Widget>> {
105
+ return this.onDidCreateTabBarEmitter.event;
106
+ }
107
+
108
+ createTabBar(): TabBar<Widget> {
109
+ const getDynamicTabOptions: () => ScrollableTabBar.Options | undefined = () => {
110
+ if (this.corePreferences.get('workbench.tab.shrinkToFit.enabled')) {
111
+ return {
112
+ minimumTabSize: this.corePreferences.get('workbench.tab.shrinkToFit.minimumSize'),
113
+ defaultTabSize: this.corePreferences.get('workbench.tab.shrinkToFit.defaultSize')
114
+ };
115
+ } else {
116
+ return undefined;
117
+ }
118
+ };
119
+
120
+ const renderer = this.tabBarRendererFactory();
121
+ const tabBar = new ToolbarAwareTabBar(
122
+ this.tabBarToolbarRegistry,
123
+ this.tabBarToolbarFactory,
124
+ this.breadcrumbsRendererFactory,
125
+ {
126
+ renderer,
127
+ // Scroll bar options
128
+ handlers: ['drag-thumb', 'keyboard', 'wheel', 'touch'],
129
+ useBothWheelAxes: true,
130
+ scrollXMarginOffset: 4,
131
+ suppressScrollY: true
132
+ },
133
+ getDynamicTabOptions());
134
+ this.tabBarClasses.forEach(c => tabBar.addClass(c));
135
+ renderer.tabBar = tabBar;
136
+ renderer.contextMenuPath = SHELL_TABBAR_CONTEXT_MENU;
137
+ tabBar.currentChanged.connect(this.onCurrentTabChanged, this);
138
+ const prefChangeDisposable = this.corePreferences.onPreferenceChanged(change => {
139
+ if (change.preferenceName === 'workbench.tab.shrinkToFit.enabled' ||
140
+ change.preferenceName === 'workbench.tab.shrinkToFit.minimumSize' ||
141
+ change.preferenceName === 'workbench.tab.shrinkToFit.defaultSize') {
142
+ tabBar.dynamicTabOptions = getDynamicTabOptions();
143
+ }
144
+ });
145
+ tabBar.disposed.connect(() => {
146
+ prefChangeDisposable.dispose();
147
+ renderer.dispose();
148
+ });
149
+ this.onDidCreateTabBarEmitter.fire(tabBar);
150
+ return tabBar;
151
+ }
152
+
153
+ createHandle(): HTMLDivElement {
154
+ return DockPanel.defaultRenderer.createHandle();
155
+ }
156
+
157
+ protected onCurrentTabChanged(sender: ToolbarAwareTabBar, { currentIndex }: TabBar.ICurrentChangedArgs<Widget>): void {
158
+ if (currentIndex >= 0) {
159
+ sender.revealTab(currentIndex);
160
+ }
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Data stored while dragging widgets in the shell.
166
+ */
167
+ interface WidgetDragState {
168
+ startTime: number;
169
+ leftExpanded: boolean;
170
+ rightExpanded: boolean;
171
+ bottomExpanded: boolean;
172
+ lastDragOver?: IDragEvent;
173
+ leaveTimeout?: number;
174
+ }
175
+
176
+ /**
177
+ * The application shell manages the top-level widgets of the application. Use this class to
178
+ * add, remove, or activate a widget.
179
+ */
180
+ @injectable()
181
+ export class ApplicationShell extends Widget {
182
+
183
+ /**
184
+ * The dock panel in the main shell area. This is where editors usually go to.
185
+ */
186
+ mainPanel: TheiaDockPanel;
187
+
188
+ /**
189
+ * The dock panel in the bottom shell area. In contrast to the main panel, the bottom panel
190
+ * can be collapsed and expanded.
191
+ */
192
+ bottomPanel: TheiaDockPanel;
193
+
194
+ /**
195
+ * Handler for the left side panel. The primary application views go here, such as the
196
+ * file explorer and the git view.
197
+ */
198
+ leftPanelHandler: SidePanelHandler;
199
+
200
+ /**
201
+ * Handler for the right side panel. The secondary application views go here, such as the
202
+ * outline view.
203
+ */
204
+ rightPanelHandler: SidePanelHandler;
205
+
206
+ /**
207
+ * General options for the application shell.
208
+ */
209
+ protected options: ApplicationShell.Options;
210
+
211
+ /**
212
+ * The fixed-size panel shown on top. This one usually holds the main menu.
213
+ */
214
+ topPanel: Panel;
215
+
216
+ /**
217
+ * The current state of the bottom panel.
218
+ */
219
+ protected readonly bottomPanelState: SidePanel.State = {
220
+ empty: true,
221
+ expansion: SidePanel.ExpansionState.collapsed,
222
+ pendingUpdate: Promise.resolve()
223
+ };
224
+
225
+ private readonly tracker = new FocusTracker<Widget>();
226
+ private dragState?: WidgetDragState;
227
+ additionalDraggedUris: URI[] | undefined;
228
+
229
+ @inject(ContextKeyService)
230
+ protected readonly contextKeyService: ContextKeyService;
231
+
232
+ @inject(OpenerService)
233
+ protected readonly openerService: OpenerService;
234
+
235
+ protected readonly onDidAddWidgetEmitter = new Emitter<Widget>();
236
+ readonly onDidAddWidget = this.onDidAddWidgetEmitter.event;
237
+ protected fireDidAddWidget(widget: Widget): void {
238
+ this.onDidAddWidgetEmitter.fire(widget);
239
+ }
240
+
241
+ protected readonly onDidRemoveWidgetEmitter = new Emitter<Widget>();
242
+ readonly onDidRemoveWidget = this.onDidRemoveWidgetEmitter.event;
243
+ protected fireDidRemoveWidget(widget: Widget): void {
244
+ this.onDidRemoveWidgetEmitter.fire(widget);
245
+ }
246
+
247
+ protected readonly onDidChangeActiveWidgetEmitter = new Emitter<FocusTracker.IChangedArgs<Widget>>();
248
+ readonly onDidChangeActiveWidget = this.onDidChangeActiveWidgetEmitter.event;
249
+
250
+ protected readonly onDidChangeCurrentWidgetEmitter = new Emitter<FocusTracker.IChangedArgs<Widget>>();
251
+ readonly onDidChangeCurrentWidget = this.onDidChangeCurrentWidgetEmitter.event;
252
+
253
+ protected readonly onDidDoubleClickMainAreaEmitter = new Emitter<void>();
254
+ readonly onDidDoubleClickMainArea = this.onDidDoubleClickMainAreaEmitter.event;
255
+
256
+ @inject(TheiaDockPanel.Factory)
257
+ protected readonly dockPanelFactory: TheiaDockPanel.Factory;
258
+
259
+ private _mainPanelRenderer: DockPanelRenderer;
260
+ get mainPanelRenderer(): DockPanelRenderer {
261
+ return this._mainPanelRenderer;
262
+ }
263
+
264
+ /**
265
+ * Construct a new application shell.
266
+ */
267
+ constructor(
268
+ @inject(DockPanelRendererFactory) protected dockPanelRendererFactory: () => DockPanelRenderer,
269
+ @inject(StatusBarImpl) protected readonly statusBar: StatusBarImpl,
270
+ @inject(SidePanelHandlerFactory) protected readonly sidePanelHandlerFactory: () => SidePanelHandler,
271
+ @inject(SplitPositionHandler) protected splitPositionHandler: SplitPositionHandler,
272
+ @inject(FrontendApplicationStateService) protected readonly applicationStateService: FrontendApplicationStateService,
273
+ @inject(ApplicationShellOptions) @optional() options: RecursivePartial<ApplicationShell.Options> = {},
274
+ @inject(CorePreferences) protected readonly corePreferences: CorePreferences,
275
+ @inject(SaveableService) protected readonly saveableService: SaveableService,
276
+ @inject(SecondaryWindowHandler) protected readonly secondaryWindowHandler: SecondaryWindowHandler,
277
+ @inject(WindowService) protected readonly windowService: WindowService
278
+ ) {
279
+ super(options as Widget.IOptions);
280
+
281
+ // Merge the user-defined application options with the default options
282
+ this.options = {
283
+ bottomPanel: {
284
+ ...ApplicationShell.DEFAULT_OPTIONS.bottomPanel,
285
+ ...options?.bottomPanel || {}
286
+ },
287
+ leftPanel: {
288
+ ...ApplicationShell.DEFAULT_OPTIONS.leftPanel,
289
+ ...options?.leftPanel || {}
290
+ },
291
+ rightPanel: {
292
+ ...ApplicationShell.DEFAULT_OPTIONS.rightPanel,
293
+ ...options?.rightPanel || {}
294
+ }
295
+ };
296
+ }
297
+
298
+ @postConstruct()
299
+ protected init(): void {
300
+ this.initializeShell();
301
+ this.initSidebarVisibleKeyContext();
302
+ this.initFocusKeyContexts();
303
+
304
+ if (!environment.electron.is()) {
305
+ this.corePreferences.ready.then(() => {
306
+ this.setTopPanelVisibility(this.corePreferences['window.menuBarVisibility']);
307
+ });
308
+ this.corePreferences.onPreferenceChanged(preference => {
309
+ if (preference.preferenceName === 'window.menuBarVisibility') {
310
+ this.setTopPanelVisibility(preference.newValue);
311
+ }
312
+ });
313
+ }
314
+
315
+ this.corePreferences.onPreferenceChanged(preference => {
316
+ if (preference.preferenceName === 'window.tabbar.enhancedPreview') {
317
+ this.allTabBars.forEach(tabBar => {
318
+ tabBar.update();
319
+ });
320
+ }
321
+ });
322
+ }
323
+
324
+ protected initializeShell(): void {
325
+ this.addClass(APPLICATION_SHELL_CLASS);
326
+ this.id = 'theia-app-shell';
327
+
328
+ this.mainPanel = this.createMainPanel();
329
+ this.topPanel = this.createTopPanel();
330
+ this.bottomPanel = this.createBottomPanel();
331
+
332
+ this.leftPanelHandler = this.sidePanelHandlerFactory();
333
+ this.leftPanelHandler.create('left', this.options.leftPanel);
334
+ this.leftPanelHandler.dockPanel.widgetAdded.connect((_, widget) => this.fireDidAddWidget(widget));
335
+ this.leftPanelHandler.dockPanel.widgetRemoved.connect((_, widget) => this.fireDidRemoveWidget(widget));
336
+
337
+ this.rightPanelHandler = this.sidePanelHandlerFactory();
338
+ this.rightPanelHandler.create('right', this.options.rightPanel);
339
+ this.rightPanelHandler.dockPanel.widgetAdded.connect((_, widget) => this.fireDidAddWidget(widget));
340
+ this.rightPanelHandler.dockPanel.widgetRemoved.connect((_, widget) => this.fireDidRemoveWidget(widget));
341
+
342
+ this.secondaryWindowHandler.init(this);
343
+ this.secondaryWindowHandler.onDidAddWidget(([widget, window]) => this.fireDidAddWidget(widget));
344
+ this.secondaryWindowHandler.onDidRemoveWidget(([widget, window]) => this.fireDidRemoveWidget(widget));
345
+
346
+ this.layout = this.createLayout();
347
+
348
+ this.tracker.currentChanged.connect(this.onCurrentChanged, this);
349
+ this.tracker.activeChanged.connect(this.onActiveChanged, this);
350
+ }
351
+
352
+ protected initSidebarVisibleKeyContext(): void {
353
+ const leftSideBarPanel = this.leftPanelHandler.dockPanel;
354
+ const sidebarVisibleKey = this.contextKeyService.createKey('sidebarVisible', leftSideBarPanel.isVisible);
355
+ const onAfterShow = leftSideBarPanel['onAfterShow'].bind(leftSideBarPanel);
356
+ leftSideBarPanel['onAfterShow'] = (msg: Message) => {
357
+ onAfterShow(msg);
358
+ sidebarVisibleKey.set(true);
359
+ };
360
+ const onAfterHide = leftSideBarPanel['onAfterHide'].bind(leftSideBarPanel);
361
+ leftSideBarPanel['onAfterHide'] = (msg: Message) => {
362
+ onAfterHide(msg);
363
+ sidebarVisibleKey.set(false);
364
+ };
365
+ }
366
+
367
+ protected initFocusKeyContexts(): void {
368
+ const sideBarFocus = this.contextKeyService.createKey<boolean>('sideBarFocus', false);
369
+ const panelFocus = this.contextKeyService.createKey<boolean>('panelFocus', false);
370
+ const updateFocusContextKeys = () => {
371
+ const area = this.activeWidget && this.getAreaFor(this.activeWidget);
372
+ sideBarFocus.set(area === 'left');
373
+ panelFocus.set(area === 'main');
374
+ };
375
+ updateFocusContextKeys();
376
+ this.onDidChangeActiveWidget(updateFocusContextKeys);
377
+ }
378
+
379
+ protected setTopPanelVisibility(preference: string): void {
380
+ const hiddenPreferences = ['compact', 'hidden'];
381
+ this.topPanel.setHidden(hiddenPreferences.includes(preference));
382
+ }
383
+
384
+ protected override onBeforeAttach(msg: Message): void {
385
+ document.addEventListener('p-dragenter', this, true);
386
+ document.addEventListener('p-dragover', this, true);
387
+ document.addEventListener('p-dragleave', this, true);
388
+ document.addEventListener('p-drop', this, true);
389
+ }
390
+
391
+ protected override onAfterDetach(msg: Message): void {
392
+ document.removeEventListener('p-dragenter', this, true);
393
+ document.removeEventListener('p-dragover', this, true);
394
+ document.removeEventListener('p-dragleave', this, true);
395
+ document.removeEventListener('p-drop', this, true);
396
+ }
397
+
398
+ handleEvent(event: Event): void {
399
+ switch (event.type) {
400
+ case 'p-dragenter':
401
+ this.onDragEnter(event as IDragEvent);
402
+ break;
403
+ case 'p-dragover':
404
+ this.onDragOver(event as IDragEvent);
405
+ break;
406
+ case 'p-drop':
407
+ this.onDrop(event as IDragEvent);
408
+ break;
409
+ case 'p-dragleave':
410
+ this.onDragLeave(event as IDragEvent);
411
+ break;
412
+ }
413
+ }
414
+
415
+ protected onDragEnter({ mimeData }: IDragEvent): void {
416
+ if (!this.dragState) {
417
+ if (mimeData && mimeData.hasData('application/vnd.phosphor.widget-factory')) {
418
+ // The drag contains a widget, so we'll track it and expand side panels as needed
419
+ this.dragState = {
420
+ startTime: performance.now(),
421
+ leftExpanded: false,
422
+ rightExpanded: false,
423
+ bottomExpanded: false
424
+ };
425
+ }
426
+ }
427
+ }
428
+
429
+ protected onDragOver(event: IDragEvent): void {
430
+ const state = this.dragState;
431
+ if (state) {
432
+ state.lastDragOver = event;
433
+ if (state.leaveTimeout) {
434
+ window.clearTimeout(state.leaveTimeout);
435
+ state.leaveTimeout = undefined;
436
+ }
437
+ const { clientX, clientY } = event;
438
+ const { offsetLeft, offsetTop, clientWidth, clientHeight } = this.node;
439
+
440
+ // Don't expand any side panels right after the drag has started
441
+ const allowExpansion = performance.now() - state.startTime >= 500;
442
+ const expLeft = allowExpansion && clientX >= offsetLeft
443
+ && clientX <= offsetLeft + this.options.leftPanel.expandThreshold;
444
+ const expRight = allowExpansion && clientX <= offsetLeft + clientWidth
445
+ && clientX >= offsetLeft + clientWidth - this.options.rightPanel.expandThreshold;
446
+ const expBottom = allowExpansion && !expLeft && !expRight && clientY <= offsetTop + clientHeight
447
+ && clientY >= offsetTop + clientHeight - this.options.bottomPanel.expandThreshold;
448
+ // eslint-disable-next-line no-null/no-null
449
+ if (expLeft && !state.leftExpanded && this.leftPanelHandler.tabBar.currentTitle === null) {
450
+ // The mouse cursor is moved close to the left border
451
+ this.leftPanelHandler.expand();
452
+ this.leftPanelHandler.state.pendingUpdate.then(() => this.dispatchMouseMove());
453
+ state.leftExpanded = true;
454
+ } else if (!expLeft && state.leftExpanded) {
455
+ // The mouse cursor is moved away from the left border
456
+ this.leftPanelHandler.collapse();
457
+ state.leftExpanded = false;
458
+ }
459
+ // eslint-disable-next-line no-null/no-null
460
+ if (expRight && !state.rightExpanded && this.rightPanelHandler.tabBar.currentTitle === null) {
461
+ // The mouse cursor is moved close to the right border
462
+ this.rightPanelHandler.expand();
463
+ this.rightPanelHandler.state.pendingUpdate.then(() => this.dispatchMouseMove());
464
+ state.rightExpanded = true;
465
+ } else if (!expRight && state.rightExpanded) {
466
+ // The mouse cursor is moved away from the right border
467
+ this.rightPanelHandler.collapse();
468
+ state.rightExpanded = false;
469
+ }
470
+ if (expBottom && !state.bottomExpanded && this.bottomPanel.isHidden) {
471
+ // The mouse cursor is moved close to the bottom border
472
+ this.expandBottomPanel();
473
+ this.bottomPanelState.pendingUpdate.then(() => this.dispatchMouseMove());
474
+ state.bottomExpanded = true;
475
+ } else if (!expBottom && state.bottomExpanded) {
476
+ // The mouse cursor is moved away from the bottom border
477
+ this.collapseBottomPanel();
478
+ state.bottomExpanded = false;
479
+ }
480
+ }
481
+ }
482
+
483
+ /**
484
+ * This method is called after a side panel has been expanded while dragging a widget. It fires
485
+ * a `mousemove` event so that the drag overlay markers are updated correctly in all dock panels.
486
+ */
487
+ private dispatchMouseMove(): void {
488
+ if (this.dragState && this.dragState.lastDragOver) {
489
+ const { clientX, clientY } = this.dragState.lastDragOver;
490
+ const event = document.createEvent('MouseEvent');
491
+ event.initMouseEvent('mousemove', true, true, window, 0, 0, 0,
492
+ // eslint-disable-next-line no-null/no-null
493
+ clientX, clientY, false, false, false, false, 0, null);
494
+ document.dispatchEvent(event);
495
+ }
496
+ }
497
+
498
+ protected onDrop(event: IDragEvent): void {
499
+ const state = this.dragState;
500
+ if (state) {
501
+ if (state.leaveTimeout) {
502
+ window.clearTimeout(state.leaveTimeout);
503
+ }
504
+ this.dragState = undefined;
505
+ window.requestAnimationFrame(() => {
506
+ // Clean up the side panel state in the next frame
507
+ if (this.leftPanelHandler.dockPanel.isEmpty) {
508
+ this.leftPanelHandler.collapse();
509
+ }
510
+ if (this.rightPanelHandler.dockPanel.isEmpty) {
511
+ this.rightPanelHandler.collapse();
512
+ }
513
+ if (this.bottomPanel.isEmpty) {
514
+ this.collapseBottomPanel();
515
+ }
516
+ });
517
+ }
518
+ }
519
+
520
+ protected onDragLeave(event: IDragEvent): void {
521
+ const state = this.dragState;
522
+ if (state) {
523
+ state.lastDragOver = undefined;
524
+ if (state.leaveTimeout) {
525
+ window.clearTimeout(state.leaveTimeout);
526
+ }
527
+ state.leaveTimeout = window.setTimeout(() => {
528
+ this.dragState = undefined;
529
+ if (state.leftExpanded || this.leftPanelHandler.dockPanel.isEmpty) {
530
+ this.leftPanelHandler.collapse();
531
+ }
532
+ if (state.rightExpanded || this.rightPanelHandler.dockPanel.isEmpty) {
533
+ this.rightPanelHandler.collapse();
534
+ }
535
+ if (state.bottomExpanded || this.bottomPanel.isEmpty) {
536
+ this.collapseBottomPanel();
537
+ }
538
+ }, 100);
539
+ }
540
+ }
541
+
542
+ /**
543
+ * Create the dock panel in the main shell area.
544
+ */
545
+ protected createMainPanel(): TheiaDockPanel {
546
+ const renderer = this.dockPanelRendererFactory();
547
+ renderer.tabBarClasses.push(MAIN_BOTTOM_AREA_CLASS);
548
+ renderer.tabBarClasses.push(MAIN_AREA_CLASS);
549
+ this._mainPanelRenderer = renderer;
550
+ const dockPanel = this.dockPanelFactory({
551
+ mode: 'multiple-document',
552
+ renderer,
553
+ spacing: 0
554
+ });
555
+ dockPanel.id = MAIN_AREA_ID;
556
+ dockPanel.widgetAdded.connect((_, widget) => this.fireDidAddWidget(widget));
557
+ dockPanel.widgetRemoved.connect((_, widget) => this.fireDidRemoveWidget(widget));
558
+
559
+ const openUri = async (fileUri: URI) => {
560
+ try {
561
+ const opener = await this.openerService.getOpener(fileUri);
562
+ opener.open(fileUri);
563
+ } catch (e) {
564
+ console.info(`no opener found for '${fileUri}'`);
565
+ }
566
+ };
567
+
568
+ dockPanel.node.addEventListener('drop', event => {
569
+ if (event.dataTransfer) {
570
+ const uris = this.additionalDraggedUris || ApplicationShell.getDraggedEditorUris(event.dataTransfer);
571
+ if (uris.length > 0) {
572
+ uris.forEach(openUri);
573
+ } else if (event.dataTransfer.files?.length > 0) {
574
+ // the files were dragged from the outside the workspace
575
+ Array.from(event.dataTransfer.files).forEach(file => {
576
+ if (file.path) {
577
+ const fileUri = URI.fromComponents({
578
+ scheme: 'file',
579
+ path: file.path,
580
+ authority: '',
581
+ query: '',
582
+ fragment: ''
583
+ });
584
+ openUri(fileUri);
585
+ }
586
+ });
587
+ }
588
+ }
589
+ });
590
+
591
+ dockPanel.node.addEventListener('dblclick', event => {
592
+ const el = event.target as Element;
593
+ if (el.id === MAIN_AREA_ID || el.classList.contains('p-TabBar-content')) {
594
+ this.onDidDoubleClickMainAreaEmitter.fire();
595
+ }
596
+ });
597
+
598
+ const handler = (e: DragEvent) => {
599
+ if (e.dataTransfer) {
600
+ e.dataTransfer.dropEffect = 'link';
601
+ e.preventDefault();
602
+ e.stopPropagation();
603
+ }
604
+ };
605
+ dockPanel.node.addEventListener('dragover', handler);
606
+ dockPanel.node.addEventListener('dragenter', handler);
607
+
608
+ return dockPanel;
609
+ }
610
+
611
+ addAdditionalDraggedEditorUris(uris: URI[]): void {
612
+ this.additionalDraggedUris = uris;
613
+ }
614
+
615
+ clearAdditionalDraggedEditorUris(): void {
616
+ this.additionalDraggedUris = undefined;
617
+ }
618
+
619
+ protected static getDraggedEditorUris(dataTransfer: DataTransfer): URI[] {
620
+ const data = dataTransfer.getData('theia-editor-dnd');
621
+ return data ? data.split('\n').map(entry => new URI(entry)) : [];
622
+ }
623
+
624
+ static setDraggedEditorUris(dataTransfer: DataTransfer, uris: URI[]): void {
625
+ dataTransfer.setData('theia-editor-dnd', uris.map(uri => uri.toString()).join('\n'));
626
+ }
627
+
628
+ /**
629
+ * Create the dock panel in the bottom shell area.
630
+ */
631
+ protected createBottomPanel(): TheiaDockPanel {
632
+ const renderer = this.dockPanelRendererFactory();
633
+ renderer.tabBarClasses.push(MAIN_BOTTOM_AREA_CLASS);
634
+ renderer.tabBarClasses.push(BOTTOM_AREA_CLASS);
635
+ const dockPanel = this.dockPanelFactory({
636
+ mode: 'multiple-document',
637
+ renderer,
638
+ spacing: 0
639
+ });
640
+ dockPanel.id = BOTTOM_AREA_ID;
641
+ dockPanel.widgetAdded.connect((sender, widget) => {
642
+ this.refreshBottomPanelToggleButton();
643
+ });
644
+ dockPanel.widgetRemoved.connect((sender, widget) => {
645
+ if (sender.isEmpty) {
646
+ this.collapseBottomPanel();
647
+ }
648
+ this.refreshBottomPanelToggleButton();
649
+ }, this);
650
+ dockPanel.node.addEventListener('p-dragenter', event => {
651
+ // Make sure that the main panel hides its overlay when the bottom panel is expanded
652
+ this.mainPanel.overlay.hide(0);
653
+ });
654
+ dockPanel.hide();
655
+ dockPanel.widgetAdded.connect((_, widget) => this.fireDidAddWidget(widget));
656
+ dockPanel.widgetRemoved.connect((_, widget) => this.fireDidRemoveWidget(widget));
657
+ return dockPanel;
658
+ }
659
+
660
+ /**
661
+ * Create the top panel, which is used to hold the main menu.
662
+ */
663
+ protected createTopPanel(): Panel {
664
+ const topPanel = new Panel();
665
+ topPanel.id = 'theia-top-panel';
666
+ topPanel.hide();
667
+ return topPanel;
668
+ }
669
+
670
+ /**
671
+ * Create a box layout to assemble the application shell layout.
672
+ */
673
+ protected createBoxLayout(widgets: Widget[], stretch?: number[], options?: BoxPanel.IOptions): BoxLayout {
674
+ const boxLayout = new BoxLayout(options);
675
+ for (let i = 0; i < widgets.length; i++) {
676
+ if (stretch !== undefined && i < stretch.length) {
677
+ BoxPanel.setStretch(widgets[i], stretch[i]);
678
+ }
679
+ boxLayout.addWidget(widgets[i]);
680
+ }
681
+ return boxLayout;
682
+ }
683
+
684
+ /**
685
+ * Create a split layout to assemble the application shell layout.
686
+ */
687
+ protected createSplitLayout(widgets: Widget[], stretch?: number[], options?: Partial<SplitLayout.IOptions>): SplitLayout {
688
+ let optParam: SplitLayout.IOptions = { renderer: SplitPanel.defaultRenderer, };
689
+ if (options) {
690
+ optParam = { ...optParam, ...options };
691
+ }
692
+ const splitLayout = new SplitLayout(optParam);
693
+ for (let i = 0; i < widgets.length; i++) {
694
+ if (stretch !== undefined && i < stretch.length) {
695
+ SplitPanel.setStretch(widgets[i], stretch[i]);
696
+ }
697
+ splitLayout.addWidget(widgets[i]);
698
+ }
699
+ return splitLayout;
700
+ }
701
+
702
+ /**
703
+ * Assemble the application shell layout. Override this method in order to change the arrangement
704
+ * of the main area and the side panels.
705
+ */
706
+ protected createLayout(): Layout {
707
+ const bottomSplitLayout = this.createSplitLayout(
708
+ [this.mainPanel, this.bottomPanel],
709
+ [1, 0],
710
+ { orientation: 'vertical', spacing: 0 }
711
+ );
712
+ const panelForBottomArea = new SplitPanel({ layout: bottomSplitLayout });
713
+ panelForBottomArea.id = 'theia-bottom-split-panel';
714
+
715
+ const leftRightSplitLayout = this.createSplitLayout(
716
+ [this.leftPanelHandler.container, panelForBottomArea, this.rightPanelHandler.container],
717
+ [0, 1, 0],
718
+ { orientation: 'horizontal', spacing: 0 }
719
+ );
720
+ const panelForSideAreas = new SplitPanel({ layout: leftRightSplitLayout });
721
+ panelForSideAreas.id = 'theia-left-right-split-panel';
722
+
723
+ return this.createBoxLayout(
724
+ [this.topPanel, panelForSideAreas, this.statusBar],
725
+ [0, 1, 0],
726
+ { direction: 'top-to-bottom', spacing: 0 }
727
+ );
728
+ }
729
+
730
+ /**
731
+ * Create an object that describes the current shell layout. This object may contain references
732
+ * to widgets; these need to be transformed before the layout can be serialized.
733
+ */
734
+ getLayoutData(): ApplicationShell.LayoutData {
735
+ return {
736
+ version: applicationShellLayoutVersion,
737
+ mainPanel: this.mainPanel.saveLayout(),
738
+ mainPanelPinned: this.getPinnedMainWidgets(),
739
+ bottomPanel: {
740
+ config: this.bottomPanel.saveLayout(),
741
+ pinned: this.getPinnedBottomWidgets(),
742
+ size: this.bottomPanel.isVisible ? this.getBottomPanelSize() : this.bottomPanelState.lastPanelSize,
743
+ expanded: this.isExpanded('bottom')
744
+ },
745
+ leftPanel: this.leftPanelHandler.getLayoutData(),
746
+ rightPanel: this.rightPanelHandler.getLayoutData(),
747
+ activeWidgetId: this.activeWidget ? this.activeWidget.id : undefined
748
+ };
749
+ }
750
+
751
+ // Get an array corresponding to main panel widgets' pinned state.
752
+ getPinnedMainWidgets(): boolean[] {
753
+ const pinned: boolean[] = [];
754
+
755
+ toArray(this.mainPanel.widgets()).forEach((a, i) => {
756
+ pinned[i] = a.title.className.includes(PINNED_CLASS);
757
+ });
758
+
759
+ return pinned;
760
+ }
761
+
762
+ // Get an array corresponding to bottom panel widgets' pinned state.
763
+ getPinnedBottomWidgets(): boolean[] {
764
+ const pinned: boolean[] = [];
765
+
766
+ toArray(this.bottomPanel.widgets()).forEach((a, i) => {
767
+ pinned[i] = a.title.className.includes(PINNED_CLASS);
768
+ });
769
+
770
+ return pinned;
771
+ }
772
+
773
+ /**
774
+ * Compute the current height of the bottom panel. This implementation assumes that the container
775
+ * of the bottom panel is a `SplitPanel`.
776
+ */
777
+ protected getBottomPanelSize(): number | undefined {
778
+ const parent = this.bottomPanel.parent;
779
+ if (parent instanceof SplitPanel && parent.isVisible) {
780
+ const index = parent.widgets.indexOf(this.bottomPanel) - 1;
781
+ if (index >= 0) {
782
+ const handle = parent.handles[index];
783
+ if (!handle.classList.contains('p-mod-hidden')) {
784
+ const parentHeight = parent.node.clientHeight;
785
+ return parentHeight - handle.offsetTop;
786
+ }
787
+ }
788
+ }
789
+ }
790
+
791
+ /**
792
+ * Determine the default size to apply when the bottom panel is expanded for the first time.
793
+ */
794
+ protected getDefaultBottomPanelSize(): number | undefined {
795
+ const parent = this.bottomPanel.parent;
796
+ if (parent && parent.isVisible) {
797
+ return parent.node.clientHeight * this.options.bottomPanel.initialSizeRatio;
798
+ }
799
+ }
800
+
801
+ /**
802
+ * Apply a shell layout that has been previously created with `getLayoutData`.
803
+ */
804
+ async setLayoutData(layoutData: ApplicationShell.LayoutData): Promise<void> {
805
+ const { mainPanel, mainPanelPinned, bottomPanel, leftPanel, rightPanel, activeWidgetId } = layoutData;
806
+ if (leftPanel) {
807
+ this.leftPanelHandler.setLayoutData(leftPanel);
808
+ this.registerWithFocusTracker(leftPanel);
809
+ }
810
+ if (rightPanel) {
811
+ this.rightPanelHandler.setLayoutData(rightPanel);
812
+ this.registerWithFocusTracker(rightPanel);
813
+ }
814
+ // Proceed with the bottom panel once the side panels are set up
815
+ await Promise.all([this.leftPanelHandler.state.pendingUpdate, this.rightPanelHandler.state.pendingUpdate]);
816
+ if (bottomPanel) {
817
+ if (bottomPanel.config) {
818
+ this.bottomPanel.restoreLayout(bottomPanel.config);
819
+ this.registerWithFocusTracker(bottomPanel.config.main);
820
+ }
821
+ if (bottomPanel.size) {
822
+ this.bottomPanelState.lastPanelSize = bottomPanel.size;
823
+ }
824
+ if (bottomPanel.expanded) {
825
+ this.expandBottomPanel();
826
+ } else {
827
+ this.collapseBottomPanel();
828
+ }
829
+ const widgets = toArray(this.bottomPanel.widgets());
830
+ this.bottomPanel.markActiveTabBar(widgets[0]?.title);
831
+ if (bottomPanel.pinned && bottomPanel.pinned.length === widgets.length) {
832
+ widgets.forEach((a, i) => {
833
+ if (bottomPanel.pinned![i]) {
834
+ a.title.className += ` ${PINNED_CLASS}`;
835
+ a.title.closable = false;
836
+ }
837
+ });
838
+ }
839
+ this.refreshBottomPanelToggleButton();
840
+ }
841
+ // Proceed with the main panel once all others are set up
842
+ await this.bottomPanelState.pendingUpdate;
843
+ if (mainPanel) {
844
+ this.mainPanel.restoreLayout(mainPanel);
845
+ this.registerWithFocusTracker(mainPanel.main);
846
+ const widgets = toArray(this.mainPanel.widgets());
847
+ // We don't store information about the last active tabbar
848
+ // So we simply mark the first as being active
849
+ this.mainPanel.markActiveTabBar(widgets[0]?.title);
850
+ if (mainPanelPinned && mainPanelPinned.length === widgets.length) {
851
+ widgets.forEach((a, i) => {
852
+ if (mainPanelPinned[i]) {
853
+ a.title.className += ` ${PINNED_CLASS}`;
854
+ a.title.closable = false;
855
+ }
856
+ });
857
+ }
858
+ }
859
+ if (activeWidgetId) {
860
+ this.activateWidget(activeWidgetId);
861
+ }
862
+ }
863
+
864
+ /**
865
+ * Modify the height of the bottom panel. This implementation assumes that the container of the
866
+ * bottom panel is a `SplitPanel`.
867
+ */
868
+ protected setBottomPanelSize(size: number): Promise<void> {
869
+ const enableAnimation = this.applicationStateService.state === 'ready';
870
+ const options: SplitPositionOptions = {
871
+ side: 'bottom',
872
+ duration: enableAnimation ? this.options.bottomPanel.expandDuration : 0,
873
+ referenceWidget: this.bottomPanel
874
+ };
875
+ const promise = this.splitPositionHandler.setSidePanelSize(this.bottomPanel, size, options);
876
+ const result = new Promise<void>(resolve => {
877
+ // Resolve the resulting promise in any case, regardless of whether resizing was successful
878
+ promise.then(() => resolve(), () => resolve());
879
+ });
880
+ this.bottomPanelState.pendingUpdate = this.bottomPanelState.pendingUpdate.then(() => result);
881
+ return result;
882
+ }
883
+
884
+ /**
885
+ * A promise that is resolved when all currently pending updates are done.
886
+ */
887
+ get pendingUpdates(): Promise<void> {
888
+ return Promise.all([
889
+ this.bottomPanelState.pendingUpdate,
890
+ this.leftPanelHandler.state.pendingUpdate,
891
+ this.rightPanelHandler.state.pendingUpdate
892
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
893
+ ]) as Promise<any>;
894
+ }
895
+
896
+ /**
897
+ * Track all widgets that are referenced by the given layout data.
898
+ */
899
+ protected registerWithFocusTracker(data: DockLayout.ITabAreaConfig | DockLayout.ISplitAreaConfig | SidePanel.LayoutData | null): void {
900
+ if (data) {
901
+ if (data.type === 'tab-area') {
902
+ for (const widget of data.widgets) {
903
+ if (widget) {
904
+ this.track(widget);
905
+ }
906
+ }
907
+ } else if (data.type === 'split-area') {
908
+ for (const child of data.children) {
909
+ this.registerWithFocusTracker(child);
910
+ }
911
+ } else if (data.type === 'sidepanel' && data.items) {
912
+ for (const item of data.items) {
913
+ if (item.widget) {
914
+ this.track(item.widget);
915
+ }
916
+ }
917
+ }
918
+ }
919
+ }
920
+
921
+ /**
922
+ * Add a widget to the application shell. The given widget must have a unique `id` property,
923
+ * which will be used as the DOM id.
924
+ *
925
+ * Widgets are removed from the shell by calling their `close` or `dispose` methods.
926
+ *
927
+ * Widgets added to the top area are not tracked regarding the _current_ and _active_ states.
928
+ */
929
+ async addWidget(widget: Widget, options?: Readonly<ApplicationShell.WidgetOptions>): Promise<void> {
930
+ if (!widget.id) {
931
+ console.error('Widgets added to the application shell must have a unique id property.');
932
+ return;
933
+ }
934
+ const { area, addOptions } = this.getInsertionOptions(options);
935
+ const sidePanelOptions: SidePanel.WidgetOptions = { rank: options?.rank };
936
+ switch (area) {
937
+ case 'main':
938
+ this.mainPanel.addWidget(widget, addOptions);
939
+ break;
940
+ case 'top':
941
+ this.topPanel.addWidget(widget);
942
+ break;
943
+ case 'bottom':
944
+ this.bottomPanel.addWidget(widget, addOptions);
945
+ break;
946
+ case 'left':
947
+ this.leftPanelHandler.addWidget(widget, sidePanelOptions);
948
+ break;
949
+ case 'right':
950
+ this.rightPanelHandler.addWidget(widget, sidePanelOptions);
951
+ break;
952
+ case 'secondaryWindow':
953
+ /** At the moment, widgets are only moved to this area (i.e. a secondary window) by moving them from one of the other areas. */
954
+ throw new Error('Widgets cannot be added directly to a secondary window');
955
+ default:
956
+ throw new Error('Unexpected area: ' + options?.area);
957
+ }
958
+ if (area !== 'top') {
959
+ this.track(widget);
960
+ }
961
+ }
962
+
963
+ getInsertionOptions(options?: Readonly<ApplicationShell.WidgetOptions>): { area: string; addOptions: TheiaDockPanel.AddOptions; } {
964
+ let ref: Widget | undefined = options?.ref;
965
+ let area: ApplicationShell.Area = options?.area || 'main';
966
+ if (!ref && (area === 'main' || area === 'bottom')) {
967
+ const tabBar = this.getTabBarFor(area);
968
+ ref = tabBar && tabBar.currentTitle && tabBar.currentTitle.owner || undefined;
969
+ }
970
+ // make sure that ref belongs to area
971
+ area = ref && this.getAreaFor(ref) || area;
972
+ const addOptions: TheiaDockPanel.AddOptions = {};
973
+ if (ApplicationShell.isOpenToSideMode(options?.mode)) {
974
+ const areaPanel = area === 'main' ? this.mainPanel : area === 'bottom' ? this.bottomPanel : undefined;
975
+ const sideRef = areaPanel && ref && (options?.mode === 'open-to-left' ?
976
+ areaPanel.previousTabBarWidget(ref) :
977
+ areaPanel.nextTabBarWidget(ref));
978
+ if (sideRef) {
979
+ addOptions.ref = sideRef;
980
+ } else {
981
+ addOptions.ref = ref;
982
+ addOptions.mode = options?.mode === 'open-to-left' ? 'split-left' : 'split-right';
983
+ }
984
+ } else if (ApplicationShell.isReplaceMode(options?.mode)) {
985
+ addOptions.ref = options?.ref;
986
+ addOptions.closeRef = true;
987
+ addOptions.mode = 'tab-after';
988
+ } else {
989
+ addOptions.ref = ref;
990
+ addOptions.mode = options?.mode;
991
+ }
992
+ return { area, addOptions };
993
+ }
994
+
995
+ /**
996
+ * The widgets contained in the given shell area.
997
+ */
998
+ getWidgets(area: ApplicationShell.Area): Widget[] {
999
+ switch (area) {
1000
+ case 'main':
1001
+ return toArray(this.mainPanel.widgets());
1002
+ case 'top':
1003
+ return toArray(this.topPanel.widgets);
1004
+ case 'bottom':
1005
+ return toArray(this.bottomPanel.widgets());
1006
+ case 'left':
1007
+ return toArray(this.leftPanelHandler.dockPanel.widgets());
1008
+ case 'right':
1009
+ return toArray(this.rightPanelHandler.dockPanel.widgets());
1010
+ case 'secondaryWindow':
1011
+ return toArray(this.secondaryWindowHandler.widgets);
1012
+ default:
1013
+ throw new Error('Illegal argument: ' + area);
1014
+ }
1015
+ }
1016
+
1017
+ /**
1018
+ * Find the widget that contains the given HTML element. The returned widget may be one
1019
+ * that is managed by the application shell, or one that is embedded in another widget and
1020
+ * not directly managed by the shell, or a tab bar.
1021
+ */
1022
+ findWidgetForElement(element: HTMLElement): Widget | undefined {
1023
+ let widgetNode: HTMLElement | null = element;
1024
+ while (widgetNode && !widgetNode.classList.contains('p-Widget')) {
1025
+ widgetNode = widgetNode.parentElement;
1026
+ }
1027
+ if (widgetNode) {
1028
+ return this.findWidgetForNode(widgetNode, this);
1029
+ }
1030
+ return undefined;
1031
+ }
1032
+
1033
+ private findWidgetForNode(widgetNode: HTMLElement, widget: Widget): Widget | undefined {
1034
+ if (widget.node === widgetNode) {
1035
+ return widget;
1036
+ }
1037
+ let result: Widget | undefined;
1038
+ each(widget.children(), child => {
1039
+ result = this.findWidgetForNode(widgetNode, child);
1040
+ return !result;
1041
+ });
1042
+ return result;
1043
+ }
1044
+
1045
+ /**
1046
+ * Finds the title widget from the tab-bar.
1047
+ * @param tabBar used for providing an array of titles.
1048
+ * @returns the selected title widget, else returns the currentTitle or undefined.
1049
+ */
1050
+ findTitle(tabBar: TabBar<Widget>, event?: Event): Title<Widget> | undefined {
1051
+ if (event?.target instanceof HTMLElement) {
1052
+ const tabNode = event.target;
1053
+
1054
+ const titleIndex = Array.from(tabBar.contentNode.getElementsByClassName('p-TabBar-tab'))
1055
+ .findIndex(node => node.contains(tabNode));
1056
+
1057
+ if (titleIndex !== -1) {
1058
+ return tabBar.titles[titleIndex];
1059
+ }
1060
+
1061
+ }
1062
+ return tabBar.currentTitle || undefined;
1063
+ }
1064
+
1065
+ /**
1066
+ * Finds the tab-bar widget.
1067
+ * @returns the selected tab-bar, else returns the currentTabBar.
1068
+ */
1069
+ findTabBar(event?: Event): TabBar<Widget> | undefined {
1070
+ if (event?.target instanceof HTMLElement) {
1071
+ const tabBar = this.findWidgetForElement(event.target);
1072
+ if (tabBar instanceof TabBar) {
1073
+ return tabBar;
1074
+ }
1075
+ }
1076
+ return this.currentTabBar;
1077
+ }
1078
+
1079
+ /**
1080
+ * @returns the widget whose title has been targeted by a DOM event on a tabbar, or undefined if none can be found.
1081
+ */
1082
+ findTargetedWidget(event?: Event): Widget | undefined {
1083
+ if (event) {
1084
+ const tab = this.findTabBar(event);
1085
+ const title = tab && this.findTitle(tab, event);
1086
+ return title && title.owner;
1087
+ }
1088
+ }
1089
+
1090
+ /**
1091
+ * The current widget in the application shell. The current widget is the last widget that
1092
+ * was active and not yet closed. See the remarks to `activeWidget` on what _active_ means.
1093
+ */
1094
+ get currentWidget(): Widget | undefined {
1095
+ return this.tracker.currentWidget || undefined;
1096
+ }
1097
+
1098
+ /**
1099
+ * The active widget in the application shell. The active widget is the one that has focus
1100
+ * (either the widget itself or any of its contents).
1101
+ *
1102
+ * _Note:_ Focus is taken by a widget through the `onActivateRequest` method. It is up to the
1103
+ * widget implementation which DOM element will get the focus. The default implementation
1104
+ * does not take any focus; in that case the widget is never returned by this property.
1105
+ */
1106
+ get activeWidget(): Widget | undefined {
1107
+ return this.tracker.activeWidget || undefined;
1108
+ }
1109
+
1110
+ /**
1111
+ * Returns the last active widget in the given shell area.
1112
+ */
1113
+ getCurrentWidget(area: ApplicationShell.Area): Widget | undefined {
1114
+ let title: Title<Widget> | null | undefined;
1115
+ switch (area) {
1116
+ case 'main':
1117
+ title = this.mainPanel.currentTitle;
1118
+ break;
1119
+ case 'bottom':
1120
+ title = this.bottomPanel.currentTitle;
1121
+ break;
1122
+ case 'left':
1123
+ title = this.leftPanelHandler.tabBar.currentTitle;
1124
+ break;
1125
+ case 'right':
1126
+ title = this.rightPanelHandler.tabBar.currentTitle;
1127
+ break;
1128
+ case 'secondaryWindow':
1129
+ // The current widget in a secondary window is not tracked.
1130
+ return undefined;
1131
+ default:
1132
+ throw new Error('Illegal argument: ' + area);
1133
+ }
1134
+ return title ? title.owner : undefined;
1135
+ }
1136
+
1137
+ /**
1138
+ * Handle a change to the current widget.
1139
+ */
1140
+ private onCurrentChanged(sender: FocusTracker<Widget>, args: FocusTracker.IChangedArgs<Widget>): void {
1141
+ this.onDidChangeCurrentWidgetEmitter.fire(args);
1142
+ }
1143
+
1144
+ protected readonly toDisposeOnActiveChanged = new DisposableCollection();
1145
+
1146
+ /**
1147
+ * Handle a change to the active widget.
1148
+ */
1149
+ private onActiveChanged(sender: FocusTracker<Widget>, args: FocusTracker.IChangedArgs<Widget>): void {
1150
+ this.toDisposeOnActiveChanged.dispose();
1151
+ const { newValue, oldValue } = args;
1152
+ if (oldValue) {
1153
+ let w: Widget | null = oldValue;
1154
+ while (w) {
1155
+ // Remove the mark of the previously active widget
1156
+ w.title.className = w.title.className.replace(' theia-mod-active', '');
1157
+ w = w.parent;
1158
+ }
1159
+ // Reset the z-index to the default
1160
+ // eslint-disable-next-line no-null/no-null
1161
+ this.setZIndex(oldValue.node, null);
1162
+ }
1163
+ if (newValue) {
1164
+ let w: Widget | null = newValue;
1165
+ while (w) {
1166
+ // Mark the tab of the active widget
1167
+ w.title.className += ' theia-mod-active';
1168
+ w = w.parent;
1169
+ }
1170
+ // Reveal the title of the active widget in its tab bar
1171
+ const tabBar = this.getTabBarFor(newValue);
1172
+ if (tabBar instanceof ScrollableTabBar) {
1173
+ const index = tabBar.titles.indexOf(newValue.title);
1174
+ if (index >= 0) {
1175
+ tabBar.revealTab(index);
1176
+ }
1177
+ }
1178
+ const widget = this.toTrackedStack(newValue.id).pop();
1179
+ const panel = this.findPanel(widget);
1180
+ if (panel) {
1181
+ // if widget was undefined, we wouldn't have gotten a panel back before
1182
+ panel.markAsCurrent(widget!.title);
1183
+ }
1184
+ // Add checks to ensure that the 'sash' for left panel is displayed correctly
1185
+ if (newValue.node.className === 'p-Widget theia-view-container p-DockPanel-widget') {
1186
+ // Set the z-index so elements with `position: fixed` contained in the active widget are displayed correctly
1187
+ this.setZIndex(newValue.node, '1');
1188
+ }
1189
+
1190
+ // activate another widget if an active widget will be closed
1191
+ const onCloseRequest = newValue['onCloseRequest'];
1192
+ newValue['onCloseRequest'] = msg => {
1193
+ const currentTabBar = this.currentTabBar;
1194
+ if (currentTabBar) {
1195
+ const recentlyUsedInTabBar = currentTabBar['_previousTitle'] as TabBar<Widget>['currentTitle'];
1196
+ if (recentlyUsedInTabBar && recentlyUsedInTabBar.owner !== newValue) {
1197
+ currentTabBar.currentIndex = ArrayExt.firstIndexOf(currentTabBar.titles, recentlyUsedInTabBar);
1198
+ if (currentTabBar.currentTitle) {
1199
+ this.activateWidget(currentTabBar.currentTitle.owner.id);
1200
+ }
1201
+ } else if (!this.activateNextTabInTabBar(currentTabBar)) {
1202
+ if (!this.activatePreviousTabBar(currentTabBar)) {
1203
+ this.activateNextTabBar(currentTabBar);
1204
+ }
1205
+ }
1206
+ }
1207
+ newValue['onCloseRequest'] = onCloseRequest;
1208
+ newValue['onCloseRequest'](msg);
1209
+ };
1210
+ this.toDisposeOnActiveChanged.push(Disposable.create(() => newValue['onCloseRequest'] = onCloseRequest));
1211
+ if (PreviewableWidget.is(newValue)) {
1212
+ newValue.loaded = true;
1213
+ }
1214
+ }
1215
+ this.onDidChangeActiveWidgetEmitter.fire(args);
1216
+ }
1217
+
1218
+ /**
1219
+ * Set the z-index of the given element and its ancestors to the value `z`.
1220
+ */
1221
+ private setZIndex(element: HTMLElement, z: string | null): void {
1222
+ element.style.zIndex = z || '';
1223
+ const parent = element.parentElement;
1224
+ if (parent && parent !== this.node) {
1225
+ this.setZIndex(parent, z);
1226
+ }
1227
+ }
1228
+
1229
+ /**
1230
+ * Track the given widget so it is considered in the `current` and `active` state of the shell.
1231
+ */
1232
+ protected track(widget: Widget): void {
1233
+ if (this.tracker.widgets.indexOf(widget) !== -1) {
1234
+ return;
1235
+ }
1236
+ this.tracker.add(widget);
1237
+ this.checkActivation(widget);
1238
+ if (ApplicationShell.TrackableWidgetProvider.is(widget)) {
1239
+ for (const toTrack of widget.getTrackableWidgets()) {
1240
+ this.track(toTrack);
1241
+ }
1242
+ if (widget.onDidChangeTrackableWidgets) {
1243
+ widget.onDidChangeTrackableWidgets(widgets => widgets.forEach(w => this.track(w)));
1244
+ }
1245
+ }
1246
+ }
1247
+
1248
+ /**
1249
+ * @returns an array of Widgets, all of which are tracked by the focus tracker
1250
+ * The first member of the array is the widget whose id is passed in, and the other widgets
1251
+ * are its tracked parents in ascending order
1252
+ */
1253
+ protected toTrackedStack(id: string): Widget[] {
1254
+ const tracked = new Map<string, Widget>(this.tracker.widgets.map(w => [w.id, w] as [string, Widget]));
1255
+ let current = tracked.get(id);
1256
+ const stack: Widget[] = [];
1257
+ while (current) {
1258
+ if (tracked.has(current.id)) {
1259
+ stack.push(current);
1260
+ }
1261
+ current = current.parent || undefined;
1262
+ }
1263
+ return stack;
1264
+ }
1265
+
1266
+ /**
1267
+ * Activate a widget in the application shell. This makes the widget visible and usually
1268
+ * also assigns focus to it.
1269
+ *
1270
+ * _Note:_ Focus is taken by a widget through the `onActivateRequest` method. It is up to the
1271
+ * widget implementation which DOM element will get the focus. The default implementation
1272
+ * does not take any focus.
1273
+ *
1274
+ * @returns the activated widget if it was found
1275
+ */
1276
+ async activateWidget(id: string): Promise<Widget | undefined> {
1277
+ const stack = this.toTrackedStack(id);
1278
+ let current = stack.pop();
1279
+ if (current && !this.doActivateWidget(current.id)) {
1280
+ return undefined;
1281
+ }
1282
+ while (current && stack.length) {
1283
+ const child = stack.pop()!;
1284
+ if (ApplicationShell.TrackableWidgetProvider.is(current) && current.activateWidget) {
1285
+ current = current.activateWidget(child.id);
1286
+ } else {
1287
+ child.activate();
1288
+ current = child;
1289
+ }
1290
+ }
1291
+ if (!current) {
1292
+ return undefined;
1293
+ }
1294
+ return Promise.all([
1295
+ this.waitForActivation(current.id),
1296
+ waitForRevealed(current),
1297
+ this.pendingUpdates
1298
+ ]).then(() => current, () => undefined);
1299
+ }
1300
+
1301
+ waitForActivation(id: string): Promise<void> {
1302
+ if (this.activeWidget && this.activeWidget.id === id) {
1303
+ return Promise.resolve();
1304
+ }
1305
+ const activation = new Deferred();
1306
+ const success = this.onDidChangeActiveWidget(() => {
1307
+ if (this.activeWidget && this.activeWidget.id === id) {
1308
+ activation.resolve();
1309
+ }
1310
+ });
1311
+ const failure = setTimeout(() => activation.reject(new Error(`Widget with id '${id}' failed to activate.`)), this.activationTimeout + 250);
1312
+ return activation.promise.finally(() => {
1313
+ success.dispose();
1314
+ clearTimeout(failure);
1315
+ });
1316
+ }
1317
+
1318
+ /**
1319
+ * Activate top-level area widget.
1320
+ */
1321
+ protected doActivateWidget(id: string): Widget | undefined {
1322
+ let widget = find(this.mainPanel.widgets(), w => w.id === id);
1323
+ if (widget) {
1324
+ this.mainPanel.activateWidget(widget);
1325
+ }
1326
+ if (!widget) {
1327
+ widget = find(this.bottomPanel.widgets(), w => w.id === id);
1328
+ if (widget) {
1329
+ this.expandBottomPanel();
1330
+ this.bottomPanel.activateWidget(widget);
1331
+ }
1332
+ }
1333
+ if (!widget) {
1334
+ widget = this.leftPanelHandler.activate(id);
1335
+ }
1336
+
1337
+ if (!widget) {
1338
+ widget = this.rightPanelHandler.activate(id);
1339
+ }
1340
+ if (widget) {
1341
+ this.windowService.focus();
1342
+ return widget;
1343
+ }
1344
+ return this.secondaryWindowHandler.activateWidget(id);
1345
+ }
1346
+
1347
+ /**
1348
+ * Focus is taken by a widget through the `onActivateRequest` method. It is up to the
1349
+ * widget implementation which DOM element will get the focus. The default implementation
1350
+ * of Widget does not take any focus. This method can help finding such problems by logging
1351
+ * a warning in case a widget was explicitly activated, but did not trigger a change of the
1352
+ * `activeWidget` property.
1353
+ */
1354
+ private checkActivation(widget: Widget): Widget {
1355
+ const onActivateRequest = widget['onActivateRequest'].bind(widget);
1356
+ widget['onActivateRequest'] = (msg: Message) => {
1357
+ onActivateRequest(msg);
1358
+ this.assertActivated(widget);
1359
+ };
1360
+ return widget;
1361
+ }
1362
+
1363
+ private readonly activationTimeout = 2000;
1364
+ private readonly toDisposeOnActivationCheck = new DisposableCollection();
1365
+ private assertActivated(widget: Widget): void {
1366
+ this.toDisposeOnActivationCheck.dispose();
1367
+
1368
+ const onDispose = () => this.toDisposeOnActivationCheck.dispose();
1369
+ widget.disposed.connect(onDispose);
1370
+ this.toDisposeOnActivationCheck.push(Disposable.create(() => widget.disposed.disconnect(onDispose)));
1371
+
1372
+ let start = 0;
1373
+ const step: FrameRequestCallback = timestamp => {
1374
+ const activeElement = widget.node.ownerDocument.activeElement;
1375
+ if (activeElement && widget.node.contains(activeElement)) {
1376
+ return;
1377
+ }
1378
+ if (!start) {
1379
+ start = timestamp;
1380
+ }
1381
+ const delta = timestamp - start;
1382
+ if (delta < this.activationTimeout) {
1383
+ request = window.requestAnimationFrame(step);
1384
+ } else {
1385
+ console.warn(`Widget was activated, but did not accept focus after ${this.activationTimeout}ms: ${widget.id}`);
1386
+ }
1387
+ };
1388
+ let request = window.requestAnimationFrame(step);
1389
+ this.toDisposeOnActivationCheck.push(Disposable.create(() => window.cancelAnimationFrame(request)));
1390
+ }
1391
+
1392
+ /**
1393
+ * Reveal a widget in the application shell. This makes the widget visible,
1394
+ * but does not activate it.
1395
+ *
1396
+ * @returns the revealed widget if it was found
1397
+ */
1398
+ async revealWidget(id: string): Promise<Widget | undefined> {
1399
+ const stack = this.toTrackedStack(id);
1400
+ let current = stack.pop();
1401
+ if (current && !this.doRevealWidget(current.id)) {
1402
+ return undefined;
1403
+ }
1404
+ while (current && stack.length) {
1405
+ const child = stack.pop()!;
1406
+ if (ApplicationShell.TrackableWidgetProvider.is(current) && current.revealWidget) {
1407
+ current = current.revealWidget(child.id);
1408
+ } else {
1409
+ current = child;
1410
+ }
1411
+ }
1412
+ if (!current) {
1413
+ return undefined;
1414
+ }
1415
+ await Promise.all([
1416
+ waitForRevealed(current),
1417
+ this.pendingUpdates
1418
+ ]);
1419
+ return current;
1420
+ }
1421
+
1422
+ /**
1423
+ * Reveal top-level area widget.
1424
+ */
1425
+ protected doRevealWidget(id: string): Widget | undefined {
1426
+ let widget = find(this.mainPanel.widgets(), w => w.id === id);
1427
+ if (!widget) {
1428
+ widget = find(this.bottomPanel.widgets(), w => w.id === id);
1429
+ if (widget) {
1430
+ this.expandBottomPanel();
1431
+ }
1432
+ }
1433
+ if (widget) {
1434
+ const tabBar = this.getTabBarFor(widget);
1435
+ if (tabBar) {
1436
+ tabBar.currentTitle = widget.title;
1437
+ }
1438
+ }
1439
+ if (!widget) {
1440
+ widget = this.leftPanelHandler.expand(id);
1441
+ }
1442
+ if (!widget) {
1443
+ widget = this.rightPanelHandler.expand(id);
1444
+ }
1445
+ if (widget) {
1446
+ this.windowService.focus();
1447
+ return widget;
1448
+ } else {
1449
+ return this.secondaryWindowHandler.revealWidget(id);
1450
+ }
1451
+ }
1452
+
1453
+ /**
1454
+ * Expand the named side panel area. This makes sure that the panel is visible, even if there
1455
+ * are no widgets in it. If the panel is already visible, nothing happens. If the panel is currently
1456
+ * collapsed (see `collapsePanel`) and it contains widgets, the widgets are revealed that were
1457
+ * visible before it was collapsed.
1458
+ */
1459
+ expandPanel(area: ApplicationShell.Area): void {
1460
+ switch (area) {
1461
+ case 'bottom':
1462
+ this.expandBottomPanel();
1463
+ break;
1464
+ case 'left':
1465
+ this.leftPanelHandler.expand();
1466
+ break;
1467
+ case 'right':
1468
+ this.rightPanelHandler.expand();
1469
+ break;
1470
+ default:
1471
+ throw new Error('Area cannot be expanded: ' + area);
1472
+ }
1473
+ }
1474
+
1475
+ /**
1476
+ * Adjusts the size of the given area in the application shell.
1477
+ *
1478
+ * @param size the desired size of the panel in pixels.
1479
+ * @param area the area to resize.
1480
+ */
1481
+ resize(size: number, area: ApplicationShell.Area): void {
1482
+ switch (area) {
1483
+ case 'bottom':
1484
+ if (this.bottomPanel.isHidden) {
1485
+ this.bottomPanelState.lastPanelSize = size;
1486
+ } else {
1487
+ this.setBottomPanelSize(size);
1488
+ }
1489
+ break;
1490
+ case 'left':
1491
+ this.leftPanelHandler.resize(size);
1492
+ break;
1493
+ case 'right':
1494
+ this.rightPanelHandler.resize(size);
1495
+ break;
1496
+ default:
1497
+ throw new Error('Area cannot be resized: ' + area);
1498
+ }
1499
+ }
1500
+
1501
+ /**
1502
+ * Expand the bottom panel. See `expandPanel` regarding the exact behavior.
1503
+ */
1504
+ protected expandBottomPanel(): void {
1505
+ const bottomPanel = this.bottomPanel;
1506
+ if (bottomPanel.isHidden) {
1507
+ let relativeSizes: number[] | undefined;
1508
+ const parent = bottomPanel.parent;
1509
+ if (parent instanceof SplitPanel) {
1510
+ relativeSizes = parent.relativeSizes();
1511
+ }
1512
+ bottomPanel.show();
1513
+ if (relativeSizes && parent instanceof SplitPanel) {
1514
+ // Make sure that the expansion animation starts at the smallest possible size
1515
+ parent.setRelativeSizes(relativeSizes);
1516
+ }
1517
+
1518
+ let size: number | undefined;
1519
+ if (bottomPanel.isEmpty) {
1520
+ bottomPanel.node.style.minHeight = '0';
1521
+ size = this.options.bottomPanel.emptySize;
1522
+ } else if (this.bottomPanelState.lastPanelSize) {
1523
+ size = this.bottomPanelState.lastPanelSize;
1524
+ } else {
1525
+ size = this.getDefaultBottomPanelSize();
1526
+ }
1527
+ if (size) {
1528
+ this.bottomPanelState.expansion = SidePanel.ExpansionState.expanding;
1529
+ this.setBottomPanelSize(size).then(() => {
1530
+ if (this.bottomPanelState.expansion === SidePanel.ExpansionState.expanding) {
1531
+ this.bottomPanelState.expansion = SidePanel.ExpansionState.expanded;
1532
+ }
1533
+ });
1534
+ } else {
1535
+ this.bottomPanelState.expansion = SidePanel.ExpansionState.expanded;
1536
+ }
1537
+ }
1538
+ }
1539
+
1540
+ /**
1541
+ * Collapse the named side panel area. This makes sure that the panel is hidden,
1542
+ * increasing the space that is available for other shell areas.
1543
+ */
1544
+ collapsePanel(area: ApplicationShell.Area): Promise<void> {
1545
+ switch (area) {
1546
+ case 'bottom':
1547
+ return this.collapseBottomPanel();
1548
+ case 'left':
1549
+ return this.leftPanelHandler.collapse();
1550
+ case 'right':
1551
+ return this.rightPanelHandler.collapse();
1552
+ default:
1553
+ throw new Error('Area cannot be collapsed: ' + area);
1554
+ }
1555
+ }
1556
+
1557
+ /**
1558
+ * Collapse the bottom panel. All contained widgets are hidden, but not closed.
1559
+ * They can be restored by calling `expandBottomPanel`.
1560
+ */
1561
+ protected collapseBottomPanel(): Promise<void> {
1562
+ const bottomPanel = this.bottomPanel;
1563
+ if (bottomPanel.isHidden) {
1564
+ return Promise.resolve();
1565
+ }
1566
+ if (this.bottomPanelState.expansion === SidePanel.ExpansionState.expanded) {
1567
+ const size = this.getBottomPanelSize();
1568
+ if (size) {
1569
+ this.bottomPanelState.lastPanelSize = size;
1570
+ }
1571
+ }
1572
+ this.bottomPanelState.expansion = SidePanel.ExpansionState.collapsed;
1573
+ bottomPanel.hide();
1574
+ return animationFrame();
1575
+ }
1576
+
1577
+ /**
1578
+ * Refresh the toggle button for the bottom panel. This implementation creates a status bar entry
1579
+ * and refers to the command `core.toggle.bottom.panel`.
1580
+ */
1581
+ protected refreshBottomPanelToggleButton(): void {
1582
+ if (this.bottomPanel.isEmpty) {
1583
+ this.statusBar.removeElement(BOTTOM_PANEL_TOGGLE_ID);
1584
+ } else {
1585
+ const label = nls.localize('theia/core/common/collapseBottomPanel', 'Toggle Bottom Panel');
1586
+ const element: StatusBarEntry = {
1587
+ name: label,
1588
+ text: '$(codicon-window)',
1589
+ alignment: StatusBarAlignment.RIGHT,
1590
+ tooltip: label,
1591
+ command: 'core.toggle.bottom.panel',
1592
+ accessibilityInformation: {
1593
+ label: label,
1594
+ role: 'button'
1595
+ },
1596
+ priority: -1000
1597
+ };
1598
+ this.statusBar.setElement(BOTTOM_PANEL_TOGGLE_ID, element);
1599
+ }
1600
+ }
1601
+
1602
+ /**
1603
+ * Check whether the named side panel area is expanded (returns `true`) or collapsed (returns `false`).
1604
+ */
1605
+ isExpanded(area: ApplicationShell.Area): boolean {
1606
+ switch (area) {
1607
+ case 'bottom':
1608
+ return this.bottomPanelState.expansion === SidePanel.ExpansionState.expanded;
1609
+ case 'left':
1610
+ return this.leftPanelHandler.state.expansion === SidePanel.ExpansionState.expanded;
1611
+ case 'right':
1612
+ return this.rightPanelHandler.state.expansion === SidePanel.ExpansionState.expanded;
1613
+ default:
1614
+ return true;
1615
+ }
1616
+ }
1617
+
1618
+ /**
1619
+ * Close all tabs or a selection of tabs in a specific part of the application shell.
1620
+ *
1621
+ * @param tabBarOrArea
1622
+ * Either the name of a shell area or a `TabBar` that is contained in such an area.
1623
+ * @param filter
1624
+ * If undefined, all tabs are closed; otherwise only those tabs that match the filter are closed.
1625
+ */
1626
+ async closeTabs(tabBarOrArea: TabBar<Widget> | ApplicationShell.Area,
1627
+ filter?: (title: Title<Widget>, index: number) => boolean): Promise<void> {
1628
+ const titles: Array<Title<Widget>> = this.getWidgetTitles(tabBarOrArea, filter);
1629
+ if (titles.length) {
1630
+ await this.closeMany(titles.map(title => title.owner));
1631
+ }
1632
+ }
1633
+
1634
+ saveTabs(tabBarOrArea: TabBar<Widget> | ApplicationShell.Area,
1635
+ filter?: (title: Title<Widget>, index: number) => boolean): void {
1636
+
1637
+ const titles = this.getWidgetTitles(tabBarOrArea, filter);
1638
+ for (let i = 0; i < titles.length; i++) {
1639
+ const widget = titles[i].owner;
1640
+ const saveable = Saveable.get(widget);
1641
+ saveable?.save();
1642
+ }
1643
+ }
1644
+
1645
+ /**
1646
+ * Collects all widget titles for the given tab bar or area and optionally filters them.
1647
+ *
1648
+ * @param tabBarOrArea The tab bar or area to retrieve the widget titles for
1649
+ * @param filter The filter to apply to the result
1650
+ * @returns The filtered array of widget titles or an empty array
1651
+ */
1652
+ protected getWidgetTitles(tabBarOrArea: TabBar<Widget> | ApplicationShell.Area,
1653
+ filter?: (title: Title<Widget>, index: number) => boolean): Title<Widget>[] {
1654
+
1655
+ const titles: Title<Widget>[] = [];
1656
+ if (tabBarOrArea === 'main') {
1657
+ this.mainAreaTabBars.forEach(tabbar => titles.push(...toArray(tabbar.titles)));
1658
+ } else if (tabBarOrArea === 'bottom') {
1659
+ this.bottomAreaTabBars.forEach(tabbar => titles.push(...toArray(tabbar.titles)));
1660
+ } else if (tabBarOrArea === 'secondaryWindow') {
1661
+ titles.push(...this.secondaryWindowHandler.widgets.map(w => w.title));
1662
+ } else if (typeof tabBarOrArea === 'string') {
1663
+ const tabbar = this.getTabBarFor(tabBarOrArea);
1664
+ if (tabbar) {
1665
+ titles.push(...toArray(tabbar.titles));
1666
+ }
1667
+ } else if (tabBarOrArea) {
1668
+ titles.push(...toArray(tabBarOrArea.titles));
1669
+ }
1670
+
1671
+ return filter ? titles.filter(filter) : titles;
1672
+ }
1673
+
1674
+ /**
1675
+ * @param targets the widgets to be closed
1676
+ * @return an array of all the widgets that were actually closed.
1677
+ */
1678
+ async closeMany(targets: Widget[], options?: ApplicationShell.CloseOptions): Promise<Widget[]> {
1679
+ if (options?.save === false || await Saveable.confirmSaveBeforeClose(targets, this.widgets.filter(widget => !targets.includes(widget)))) {
1680
+ return (await Promise.all(targets.map(target => this.closeWidget(target.id, options)))).filter((widget): widget is Widget => widget !== undefined);
1681
+ }
1682
+ return [];
1683
+ }
1684
+
1685
+ /**
1686
+ * @returns the widget that was closed, if any, `undefined` otherwise.
1687
+ *
1688
+ * If your use case requires closing multiple widgets, use {@link ApplicationShell#closeMany} instead. That method handles closing saveable widgets more reliably.
1689
+ */
1690
+ async closeWidget(id: string, options?: ApplicationShell.CloseOptions): Promise<Widget | undefined> {
1691
+ // TODO handle save for composite widgets, i.e. the preference widget has 2 editors
1692
+ const stack = this.toTrackedStack(id);
1693
+ const current = stack.pop();
1694
+ if (!current) {
1695
+ return undefined;
1696
+ }
1697
+ const saveableOptions = options && { shouldSave: () => options.save };
1698
+ const pendingClose = SaveableWidget.is(current)
1699
+ ? current.closeWithSaving(saveableOptions)
1700
+ : (current.close(), waitForClosed(current));
1701
+ await Promise.all([
1702
+ pendingClose,
1703
+ this.pendingUpdates
1704
+ ]);
1705
+ return stack[0] || current;
1706
+ }
1707
+
1708
+ /**
1709
+ * The shell area name of the currently active tab, or undefined.
1710
+ */
1711
+ get currentTabArea(): ApplicationShell.Area | undefined {
1712
+ const currentWidget = this.currentWidget;
1713
+ if (currentWidget) {
1714
+ return this.getAreaFor(currentWidget);
1715
+ }
1716
+ }
1717
+
1718
+ /**
1719
+ * Determine the name of the shell area where the given widget resides. The result is
1720
+ * undefined if the widget does not reside directly in the shell.
1721
+ */
1722
+ getAreaFor(input: TabBar<Widget> | Widget): ApplicationShell.Area | undefined {
1723
+ if (input instanceof TabBar) {
1724
+ if (find(this.mainPanel.tabBars(), tb => tb === input)) {
1725
+ return 'main';
1726
+ }
1727
+ if (find(this.bottomPanel.tabBars(), tb => tb === input)) {
1728
+ return 'bottom';
1729
+ }
1730
+ if (this.leftPanelHandler.tabBar === input) {
1731
+ return 'left';
1732
+ }
1733
+ if (this.rightPanelHandler.tabBar === input) {
1734
+ return 'right';
1735
+ }
1736
+ }
1737
+ const widget = this.toTrackedStack(input.id).pop();
1738
+ if (!widget) {
1739
+ return undefined;
1740
+ }
1741
+ const title = widget.title;
1742
+ const mainPanelTabBar = this.mainPanel.findTabBar(title);
1743
+ if (mainPanelTabBar) {
1744
+ return 'main';
1745
+ }
1746
+ const bottomPanelTabBar = this.bottomPanel.findTabBar(title);
1747
+ if (bottomPanelTabBar) {
1748
+ return 'bottom';
1749
+ }
1750
+ if (ArrayExt.firstIndexOf(this.leftPanelHandler.tabBar.titles, title) > -1) {
1751
+ return 'left';
1752
+ }
1753
+ if (ArrayExt.firstIndexOf(this.rightPanelHandler.tabBar.titles, title) > -1) {
1754
+ return 'right';
1755
+ }
1756
+ if (this.secondaryWindowHandler.widgets.includes(widget)) {
1757
+ return 'secondaryWindow';
1758
+ }
1759
+ return undefined;
1760
+ }
1761
+
1762
+ protected getAreaPanelFor(input: Widget): DockPanel | undefined {
1763
+ const widget = this.toTrackedStack(input.id).pop();
1764
+ if (!widget) {
1765
+ return undefined;
1766
+ }
1767
+ return this.findPanel(widget);
1768
+ }
1769
+
1770
+ /**
1771
+ * Find the shell panel this top-level widget is part of
1772
+ */
1773
+ protected findPanel(widget: Widget | undefined): TheiaDockPanel | undefined {
1774
+ if (!widget) {
1775
+ return undefined;
1776
+ }
1777
+ const title = widget.title;
1778
+ const mainPanelTabBar = this.mainPanel.findTabBar(title);
1779
+ if (mainPanelTabBar) {
1780
+ return this.mainPanel;
1781
+ }
1782
+ const bottomPanelTabBar = this.bottomPanel.findTabBar(title);
1783
+ if (bottomPanelTabBar) {
1784
+ return this.bottomPanel;
1785
+ }
1786
+ if (ArrayExt.firstIndexOf(this.leftPanelHandler.tabBar.titles, title) > -1) {
1787
+ return this.leftPanelHandler.dockPanel;
1788
+ }
1789
+ if (ArrayExt.firstIndexOf(this.rightPanelHandler.tabBar.titles, title) > -1) {
1790
+ return this.rightPanelHandler.dockPanel;
1791
+ }
1792
+ return undefined;
1793
+ }
1794
+
1795
+ /**
1796
+ * Return the tab bar that has the currently active widget, or undefined.
1797
+ */
1798
+ get currentTabBar(): TabBar<Widget> | undefined {
1799
+ const currentWidget = this.currentWidget;
1800
+ if (currentWidget) {
1801
+ return this.getTabBarFor(currentWidget);
1802
+ }
1803
+ }
1804
+
1805
+ /**
1806
+ * Return the tab bar in the given shell area, or the tab bar that has the given widget, or undefined.
1807
+ */
1808
+ getTabBarFor(widgetOrArea: Widget | ApplicationShell.Area): TabBar<Widget> | undefined {
1809
+ if (typeof widgetOrArea === 'string') {
1810
+ switch (widgetOrArea) {
1811
+ case 'main':
1812
+ return this.mainPanel.currentTabBar;
1813
+ case 'bottom':
1814
+ return this.bottomPanel.currentTabBar;
1815
+ case 'left':
1816
+ return this.leftPanelHandler.tabBar;
1817
+ case 'right':
1818
+ return this.rightPanelHandler.tabBar;
1819
+ case 'secondaryWindow':
1820
+ // Secondary windows don't have a tab bar
1821
+ return undefined;
1822
+ default:
1823
+ throw new Error('Illegal argument: ' + widgetOrArea);
1824
+ }
1825
+ }
1826
+ const widget = this.toTrackedStack(widgetOrArea.id).pop();
1827
+ if (!widget) {
1828
+ return undefined;
1829
+ }
1830
+ const widgetTitle = widget.title;
1831
+ const mainPanelTabBar = this.mainPanel.findTabBar(widgetTitle);
1832
+ if (mainPanelTabBar) {
1833
+ return mainPanelTabBar;
1834
+ }
1835
+ const bottomPanelTabBar = this.bottomPanel.findTabBar(widgetTitle);
1836
+ if (bottomPanelTabBar) {
1837
+ return bottomPanelTabBar;
1838
+ }
1839
+ const leftPanelTabBar = this.leftPanelHandler.tabBar;
1840
+ if (ArrayExt.firstIndexOf(leftPanelTabBar.titles, widgetTitle) > -1) {
1841
+ return leftPanelTabBar;
1842
+ }
1843
+ const rightPanelTabBar = this.rightPanelHandler.tabBar;
1844
+ if (ArrayExt.firstIndexOf(rightPanelTabBar.titles, widgetTitle) > -1) {
1845
+ return rightPanelTabBar;
1846
+ }
1847
+ return undefined;
1848
+ }
1849
+
1850
+ /**
1851
+ * The tab bars contained in the main shell area. If there is no widget in the main area, the
1852
+ * returned array is empty.
1853
+ */
1854
+ get mainAreaTabBars(): TabBar<Widget>[] {
1855
+ return toArray(this.mainPanel.tabBars());
1856
+ }
1857
+
1858
+ /**
1859
+ * The tab bars contained in the bottom shell area. If there is no widget in the bottom area,
1860
+ * the returned array is empty.
1861
+ */
1862
+ get bottomAreaTabBars(): TabBar<Widget>[] {
1863
+ return toArray(this.bottomPanel.tabBars());
1864
+ }
1865
+
1866
+ /**
1867
+ * The tab bars contained in all shell areas.
1868
+ */
1869
+ get allTabBars(): TabBar<Widget>[] {
1870
+ return [...this.mainAreaTabBars, ...this.bottomAreaTabBars, this.leftPanelHandler.tabBar, this.rightPanelHandler.tabBar];
1871
+ }
1872
+
1873
+ /*
1874
+ * Activate the next tab in the current tab bar.
1875
+ */
1876
+ activateNextTabInTabBar(current: TabBar<Widget> | undefined = this.currentTabBar): boolean {
1877
+ const index = this.nextTabIndexInTabBar(current);
1878
+ if (!current || index === -1) {
1879
+ return false;
1880
+ }
1881
+ current.currentIndex = index;
1882
+ if (current.currentTitle) {
1883
+ this.activateWidget(current.currentTitle.owner.id);
1884
+ }
1885
+ return true;
1886
+ }
1887
+
1888
+ nextTabIndexInTabBar(current: TabBar<Widget> | undefined = this.currentTabBar): number {
1889
+ if (!current || current.titles.length <= 1) {
1890
+ return -1;
1891
+ }
1892
+ const index = current.currentIndex;
1893
+ if (index === -1) {
1894
+ return -1;
1895
+ }
1896
+ if (index < current.titles.length - 1) {
1897
+ return index + 1;
1898
+ }
1899
+ // last item in tab bar. select the previous one.
1900
+ if (index === current.titles.length - 1) {
1901
+ return index - 1;
1902
+ }
1903
+ return 0;
1904
+ }
1905
+
1906
+ activateNextTab(): boolean {
1907
+ const current = this.currentTabBar;
1908
+ if (current) {
1909
+ const ci = current.currentIndex;
1910
+ if (ci !== -1) {
1911
+ if (ci < current.titles.length - 1) {
1912
+ current.currentIndex += 1;
1913
+ if (current.currentTitle) {
1914
+ this.activateWidget(current.currentTitle.owner.id);
1915
+ }
1916
+ return true;
1917
+ } else if (ci === current.titles.length - 1) {
1918
+ return this.activateNextTabBar(current);
1919
+ }
1920
+ }
1921
+ }
1922
+ return false;
1923
+ }
1924
+
1925
+ activateNextTabBar(current: TabBar<Widget> | undefined = this.currentTabBar): boolean {
1926
+ const nextBar = this.nextTabBar(current);
1927
+ if (nextBar) {
1928
+ nextBar.currentIndex = 0;
1929
+ if (nextBar.currentTitle) {
1930
+ this.activateWidget(nextBar.currentTitle.owner.id);
1931
+ }
1932
+ return true;
1933
+ }
1934
+ return false;
1935
+ }
1936
+
1937
+ /**
1938
+ * Return the tab bar next to the given tab bar; return the given tab bar if there is no adjacent one.
1939
+ */
1940
+ nextTabBar(current: TabBar<Widget> | undefined = this.currentTabBar): TabBar<Widget> | undefined {
1941
+ let bars = toArray(this.bottomPanel.tabBars());
1942
+ let len = bars.length;
1943
+ let ci = ArrayExt.firstIndexOf(bars, current);
1944
+ if (ci < 0) {
1945
+ bars = toArray(this.mainPanel.tabBars());
1946
+ len = bars.length;
1947
+ ci = ArrayExt.firstIndexOf(bars, current);
1948
+ }
1949
+ if (ci >= 0 && ci < len - 1) {
1950
+ return bars[ci + 1];
1951
+ } else if (ci >= 0 && ci === len - 1) {
1952
+ return bars[0];
1953
+ } else {
1954
+ return current;
1955
+ }
1956
+ }
1957
+
1958
+ /*
1959
+ * Activate the previous tab in the current tab bar.
1960
+ */
1961
+ activatePreviousTabInTabBar(current: TabBar<Widget> | undefined = this.currentTabBar): boolean {
1962
+ const index = this.previousTabIndexInTabBar(current);
1963
+ if (!current || index === -1) {
1964
+ return false;
1965
+ }
1966
+ current.currentIndex = index;
1967
+ if (current.currentTitle) {
1968
+ this.activateWidget(current.currentTitle.owner.id);
1969
+ }
1970
+ return true;
1971
+ }
1972
+
1973
+ previousTabIndexInTabBar(current: TabBar<Widget> | undefined = this.currentTabBar): number {
1974
+ if (!current || current.titles.length <= 1) {
1975
+ return -1;
1976
+ }
1977
+ const index = current.currentIndex;
1978
+ if (index === -1) {
1979
+ return -1;
1980
+ }
1981
+ if (index > 0) {
1982
+ return index - 1;
1983
+ }
1984
+ return current.titles.length - 1;
1985
+ }
1986
+
1987
+ activatePreviousTab(): boolean {
1988
+ const current = this.currentTabBar;
1989
+ if (current) {
1990
+ const ci = current.currentIndex;
1991
+ if (ci !== -1) {
1992
+ if (ci > 0) {
1993
+ current.currentIndex -= 1;
1994
+ if (current.currentTitle) {
1995
+ this.activateWidget(current.currentTitle.owner.id);
1996
+ }
1997
+ return true;
1998
+ } else if (ci === 0) {
1999
+ if (current && current.titles.length > 0) {
2000
+ current.currentIndex = current.titles.length - 1;
2001
+ if (current.currentTitle) {
2002
+ this.activateWidget(current.currentTitle.owner.id);
2003
+ }
2004
+ return true;
2005
+ }
2006
+ return this.activatePreviousTabBar(current);
2007
+ }
2008
+ }
2009
+ }
2010
+ return false;
2011
+ }
2012
+
2013
+ activatePreviousTabBar(current: TabBar<Widget> | undefined = this.currentTabBar): boolean {
2014
+ const prevBar = this.previousTabBar(current);
2015
+ if (!prevBar) {
2016
+ return false;
2017
+ }
2018
+ if (!prevBar.currentTitle) {
2019
+ prevBar.currentIndex = prevBar.titles.length - 1;
2020
+ }
2021
+ if (prevBar.currentTitle) {
2022
+ this.activateWidget(prevBar.currentTitle.owner.id);
2023
+ }
2024
+ return true;
2025
+ }
2026
+
2027
+ /**
2028
+ * Return the tab bar previous to the given tab bar; return the given tab bar if there is no adjacent one.
2029
+ */
2030
+ previousTabBar(current: TabBar<Widget> | undefined = this.currentTabBar): TabBar<Widget> | undefined {
2031
+ const bars = toArray(this.mainPanel.tabBars());
2032
+ const len = bars.length;
2033
+ const ci = ArrayExt.firstIndexOf(bars, current);
2034
+ if (ci > 0) {
2035
+ return bars[ci - 1];
2036
+ } else if (ci === 0) {
2037
+ return bars[len - 1];
2038
+ } else {
2039
+ return current;
2040
+ }
2041
+ }
2042
+
2043
+ /**
2044
+ * Test whether the current widget is dirty.
2045
+ */
2046
+ canSave(): boolean {
2047
+ return this.saveableService.canSave(this.currentWidget);
2048
+ }
2049
+
2050
+ /**
2051
+ * Save the current widget if it is dirty.
2052
+ */
2053
+ async save(options?: SaveOptions): Promise<void> {
2054
+ await this.saveableService.save(this.currentWidget, options);
2055
+ }
2056
+
2057
+ /**
2058
+ * Test whether there is a dirty widget.
2059
+ */
2060
+ canSaveAll(): boolean {
2061
+ return this.tracker.widgets.some(widget => this.saveableService.canSave(widget));
2062
+ }
2063
+
2064
+ /**
2065
+ * Save all dirty widgets.
2066
+ */
2067
+ async saveAll(options?: SaveOptions): Promise<void> {
2068
+ for (const widget of this.widgets) {
2069
+ if (Saveable.isDirty(widget) && this.saveableService.canSaveNotSaveAs(widget)) {
2070
+ await this.saveableService.save(widget, options);
2071
+ }
2072
+ }
2073
+ }
2074
+
2075
+ /**
2076
+ * Returns a snapshot of all tracked widgets to allow async modifications.
2077
+ */
2078
+ get widgets(): ReadonlyArray<Widget> {
2079
+ return [...this.tracker.widgets];
2080
+ }
2081
+
2082
+ getWidgetById(id: string): Widget | undefined {
2083
+ for (const widget of this.tracker.widgets) {
2084
+ if (widget.id === id) {
2085
+ return widget;
2086
+ }
2087
+ }
2088
+ return undefined;
2089
+ }
2090
+
2091
+ canToggleMaximized(widget: Widget | undefined = this.currentWidget): boolean {
2092
+ const area = widget && this.getAreaFor(widget);
2093
+ return area === 'main' || area === 'bottom';
2094
+ }
2095
+
2096
+ toggleMaximized(widget: Widget | undefined = this.currentWidget): void {
2097
+ const area = widget && this.getAreaPanelFor(widget);
2098
+ if (area instanceof TheiaDockPanel && (area === this.mainPanel || area === this.bottomPanel)) {
2099
+ area.toggleMaximized();
2100
+ this.revealWidget(widget!.id);
2101
+ }
2102
+ }
2103
+
2104
+ }
2105
+
2106
+ /**
2107
+ * The namespace for `ApplicationShell` class statics.
2108
+ */
2109
+ export namespace ApplicationShell {
2110
+ /**
2111
+ * The areas of the application shell where widgets can reside.
2112
+ */
2113
+ export type Area = 'main' | 'top' | 'left' | 'right' | 'bottom' | 'secondaryWindow';
2114
+
2115
+ export const areaLabels: Record<Area, string> = {
2116
+ main: nls.localizeByDefault('Main'),
2117
+ top: nls.localizeByDefault('Top'),
2118
+ left: nls.localizeByDefault('Left'),
2119
+ right: nls.localizeByDefault('Right'),
2120
+ bottom: nls.localizeByDefault('Bottom'),
2121
+ secondaryWindow: nls.localize('theia/shell-area/secondary', 'Secondary Window'),
2122
+ };
2123
+
2124
+ /**
2125
+ * The _side areas_ are those shell areas that can be collapsed and expanded,
2126
+ * i.e. `left`, `right`, and `bottom`.
2127
+ */
2128
+ export function isSideArea(area?: string): area is 'left' | 'right' | 'bottom' {
2129
+ return area === 'left' || area === 'right' || area === 'bottom';
2130
+ }
2131
+
2132
+ export function isValidArea(area?: unknown): area is ApplicationShell.Area {
2133
+ const areas = ['main', 'top', 'left', 'right', 'bottom', 'secondaryWindow'];
2134
+ return typeof area === 'string' && areas.includes(area);
2135
+ }
2136
+
2137
+ /**
2138
+ * General options for the application shell. These are passed on construction and can be modified
2139
+ * through dependency injection (`ApplicationShellOptions` symbol).
2140
+ */
2141
+ export interface Options extends Widget.IOptions {
2142
+ bottomPanel: BottomPanelOptions;
2143
+ leftPanel: SidePanel.Options;
2144
+ rightPanel: SidePanel.Options;
2145
+ }
2146
+
2147
+ export interface BottomPanelOptions extends SidePanel.Options {
2148
+ }
2149
+
2150
+ /**
2151
+ * The default values for application shell options.
2152
+ */
2153
+ export const DEFAULT_OPTIONS = Object.freeze(<Options>{
2154
+ bottomPanel: Object.freeze(<BottomPanelOptions>{
2155
+ emptySize: 140,
2156
+ expandThreshold: 160,
2157
+ expandDuration: 0,
2158
+ initialSizeRatio: 0.382
2159
+ }),
2160
+ leftPanel: Object.freeze(<SidePanel.Options>{
2161
+ emptySize: 140,
2162
+ expandThreshold: 140,
2163
+ expandDuration: 0,
2164
+ initialSizeRatio: 0.191
2165
+ }),
2166
+ rightPanel: Object.freeze(<SidePanel.Options>{
2167
+ emptySize: 140,
2168
+ expandThreshold: 140,
2169
+ expandDuration: 0,
2170
+ initialSizeRatio: 0.191
2171
+ })
2172
+ });
2173
+
2174
+ /**
2175
+ * Whether a widget should be opened to the side tab bar relatively to the reference widget.
2176
+ */
2177
+ export type OpenToSideMode = 'open-to-left' | 'open-to-right';
2178
+
2179
+ export function isOpenToSideMode(mode: unknown): mode is OpenToSideMode {
2180
+ return mode === 'open-to-left' || mode === 'open-to-right';
2181
+ }
2182
+
2183
+ /**
2184
+ * Whether the `ref` of the options widget should be replaced.
2185
+ */
2186
+ export type ReplaceMode = 'tab-replace';
2187
+
2188
+ export function isReplaceMode(mode: unknown): mode is ReplaceMode {
2189
+ return mode === 'tab-replace';
2190
+ }
2191
+
2192
+ /**
2193
+ * Options for adding a widget to the application shell.
2194
+ */
2195
+ export interface WidgetOptions extends SidePanel.WidgetOptions {
2196
+ /**
2197
+ * The area of the application shell where the widget will reside.
2198
+ */
2199
+ area?: Area;
2200
+ /**
2201
+ * The insertion mode for adding the widget.
2202
+ *
2203
+ * The default is `'tab-after'`.
2204
+ */
2205
+ mode?: DockLayout.InsertMode | OpenToSideMode | ReplaceMode
2206
+ /**
2207
+ * The reference widget for the insert location.
2208
+ *
2209
+ * The default is `undefined`.
2210
+ */
2211
+ ref?: Widget;
2212
+ }
2213
+
2214
+ export interface CloseOptions {
2215
+ /**
2216
+ * if optional then a user will be prompted
2217
+ * if undefined then close will be canceled
2218
+ * if true then will be saved on close
2219
+ * if false then won't be saved on close
2220
+ */
2221
+ save?: boolean | undefined
2222
+ }
2223
+
2224
+ /**
2225
+ * Data to save and load the application shell layout.
2226
+ */
2227
+ export interface LayoutData {
2228
+ version?: string | ApplicationShellLayoutVersion,
2229
+ mainPanel?: DockPanel.ILayoutConfig;
2230
+ mainPanelPinned?: boolean[];
2231
+ bottomPanel?: BottomPanelLayoutData;
2232
+ leftPanel?: SidePanel.LayoutData;
2233
+ rightPanel?: SidePanel.LayoutData;
2234
+ activeWidgetId?: string;
2235
+ }
2236
+
2237
+ /**
2238
+ * Data to save and load the bottom panel layout.
2239
+ */
2240
+ export interface BottomPanelLayoutData {
2241
+ config?: DockPanel.ILayoutConfig;
2242
+ size?: number;
2243
+ expanded?: boolean;
2244
+ pinned?: boolean[];
2245
+ }
2246
+
2247
+ /**
2248
+ * Exposes widgets which activation state should be tracked by shell.
2249
+ */
2250
+ export interface TrackableWidgetProvider {
2251
+ getTrackableWidgets(): Widget[]
2252
+ readonly onDidChangeTrackableWidgets?: CommonEvent<Widget[]>
2253
+ /**
2254
+ * Make visible and focus a trackable widget for the given id.
2255
+ * If not implemented then `activate` request will be sent to a child widget directly.
2256
+ */
2257
+ activateWidget?(id: string): Widget | undefined;
2258
+ /**
2259
+ * Make visible a trackable widget for the given id.
2260
+ * If not implemented then a widget should be always visible when an owner is visible.
2261
+ */
2262
+ revealWidget?(id: string): Widget | undefined;
2263
+ }
2264
+
2265
+ export namespace TrackableWidgetProvider {
2266
+ export function is(widget: unknown): widget is TrackableWidgetProvider {
2267
+ return isObject(widget) && 'getTrackableWidgets' in widget;
2268
+ }
2269
+ }
2270
+
2271
+ }