@theia/plugin-ext 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 (381) hide show
  1. package/README.md +54 -54
  2. package/lib/common/plugin-api-rpc.d.ts +1 -4
  3. package/lib/common/plugin-api-rpc.d.ts.map +1 -1
  4. package/lib/common/plugin-api-rpc.js.map +1 -1
  5. package/lib/hosted/browser/hosted-plugin.js +9 -9
  6. package/lib/main/browser/editors-and-documents-main.d.ts.map +1 -1
  7. package/lib/main/browser/editors-and-documents-main.js +14 -2
  8. package/lib/main/browser/editors-and-documents-main.js.map +1 -1
  9. package/lib/main/browser/notebooks/notebook-documents-and-editors-main.d.ts.map +1 -1
  10. package/lib/main/browser/notebooks/notebook-documents-and-editors-main.js +2 -0
  11. package/lib/main/browser/notebooks/notebook-documents-and-editors-main.js.map +1 -1
  12. package/lib/main/browser/notebooks/renderers/cell-output-webview.js +86 -86
  13. package/lib/main/browser/plugin-icon-theme-service.js +20 -20
  14. package/lib/main/browser/plugin-shared-style.js +14 -14
  15. package/lib/main/browser/tabs/tabs-main.d.ts +1 -1
  16. package/lib/main/browser/tabs/tabs-main.d.ts.map +1 -1
  17. package/lib/main/browser/tabs/tabs-main.js +1 -1
  18. package/lib/main/browser/tabs/tabs-main.js.map +1 -1
  19. package/lib/main/browser/text-editor-main.d.ts +6 -3
  20. package/lib/main/browser/text-editor-main.d.ts.map +1 -1
  21. package/lib/main/browser/text-editor-main.js +39 -5
  22. package/lib/main/browser/text-editor-main.js.map +1 -1
  23. package/lib/main/browser/view/plugin-view-registry.js +3 -3
  24. package/lib/main/browser/webview/webview-frontend-security-warnings.js +2 -2
  25. package/lib/main/browser/webview/webview-secondary-window-support.js +10 -10
  26. package/lib/main/browser/workspace-main.d.ts +0 -2
  27. package/lib/main/browser/workspace-main.d.ts.map +1 -1
  28. package/lib/main/node/plugin-service.d.ts +1 -1
  29. package/lib/main/node/webview-backend-security-warnings.js +6 -6
  30. package/lib/plugin/languages.d.ts +0 -1
  31. package/lib/plugin/languages.d.ts.map +1 -1
  32. package/lib/plugin/notebook/notebook-kernels.d.ts +0 -2
  33. package/lib/plugin/notebook/notebook-kernels.d.ts.map +1 -1
  34. package/lib/plugin/notebook/notebooks.d.ts +1 -0
  35. package/lib/plugin/notebook/notebooks.d.ts.map +1 -1
  36. package/lib/plugin/notebook/notebooks.js +22 -2
  37. package/lib/plugin/notebook/notebooks.js.map +1 -1
  38. package/lib/plugin/scm.d.ts +0 -1
  39. package/lib/plugin/scm.d.ts.map +1 -1
  40. package/lib/plugin/terminal-ext.d.ts +0 -1
  41. package/lib/plugin/terminal-ext.d.ts.map +1 -1
  42. package/lib/plugin/text-editor.d.ts +1 -1
  43. package/lib/plugin/text-editor.d.ts.map +1 -1
  44. package/lib/plugin/text-editor.js.map +1 -1
  45. package/lib/plugin/type-converters.d.ts +0 -1
  46. package/lib/plugin/type-converters.d.ts.map +1 -1
  47. package/lib/plugin/types-impl.d.ts +2 -3
  48. package/lib/plugin/types-impl.d.ts.map +1 -1
  49. package/lib/plugin/workspace.d.ts +0 -4
  50. package/lib/plugin/workspace.d.ts.map +1 -1
  51. package/package.json +28 -28
  52. package/src/common/arrays.ts +70 -70
  53. package/src/common/assert.ts +23 -23
  54. package/src/common/cache.ts +51 -51
  55. package/src/common/character-classifier.ts +73 -73
  56. package/src/common/collections.ts +54 -54
  57. package/src/common/commands.ts +19 -19
  58. package/src/common/connection.ts +137 -137
  59. package/src/common/disposable-util.ts +39 -39
  60. package/src/common/editor-options.ts +74 -74
  61. package/src/common/env.ts +19 -19
  62. package/src/common/errors.ts +63 -63
  63. package/src/common/id-generator.ts +26 -26
  64. package/src/common/index.ts +24 -24
  65. package/src/common/language-pack-service.ts +34 -34
  66. package/src/common/link-computer.ts +354 -354
  67. package/src/common/object-identifier.ts +33 -33
  68. package/src/common/objects.ts +50 -50
  69. package/src/common/paths-util.ts +158 -158
  70. package/src/common/plugin-api-rpc-model.ts +907 -907
  71. package/src/common/plugin-api-rpc.ts +2753 -2752
  72. package/src/common/plugin-ext-api-contribution.ts +115 -115
  73. package/src/common/plugin-identifiers.ts +84 -84
  74. package/src/common/plugin-protocol.ts +1094 -1094
  75. package/src/common/reference-map.ts +38 -38
  76. package/src/common/rpc-protocol.ts +306 -306
  77. package/src/common/semantic-tokens-dto.ts +182 -182
  78. package/src/common/test-types.ts +154 -154
  79. package/src/common/types.ts +129 -129
  80. package/src/common/uint.ts +37 -37
  81. package/src/common/uri-components.ts +81 -81
  82. package/src/hosted/browser/hosted-plugin-watcher.ts +54 -54
  83. package/src/hosted/browser/hosted-plugin.ts +635 -635
  84. package/src/hosted/browser/plugin-worker.ts +52 -52
  85. package/src/hosted/browser/worker/debug-stub.ts +29 -29
  86. package/src/hosted/browser/worker/plugin-manifest-loader.ts +114 -114
  87. package/src/hosted/browser/worker/worker-env-ext.ts +40 -40
  88. package/src/hosted/browser/worker/worker-main.ts +212 -212
  89. package/src/hosted/browser/worker/worker-plugin-module.ts +80 -80
  90. package/src/hosted/common/hosted-plugin.ts +456 -456
  91. package/src/hosted/node/hosted-plugin-cli-contribution.ts +75 -75
  92. package/src/hosted/node/hosted-plugin-deployer-handler.ts +274 -274
  93. package/src/hosted/node/hosted-plugin-localization-service.ts +410 -410
  94. package/src/hosted/node/hosted-plugin-process.ts +248 -248
  95. package/src/hosted/node/hosted-plugin-protocol.ts +49 -49
  96. package/src/hosted/node/hosted-plugin.ts +116 -116
  97. package/src/hosted/node/metadata-scanner.ts +64 -64
  98. package/src/hosted/node/plugin-activation-events.ts +112 -112
  99. package/src/hosted/node/plugin-ext-hosted-backend-module.ts +94 -94
  100. package/src/hosted/node/plugin-host-module.ts +69 -69
  101. package/src/hosted/node/plugin-host-proxy.ts +82 -82
  102. package/src/hosted/node/plugin-host-rpc.ts +377 -377
  103. package/src/hosted/node/plugin-host.ts +110 -110
  104. package/src/hosted/node/plugin-language-pack-service.ts +43 -43
  105. package/src/hosted/node/plugin-manifest-loader.ts +32 -32
  106. package/src/hosted/node/plugin-reader.ts +136 -136
  107. package/src/hosted/node/plugin-service.ts +197 -197
  108. package/src/hosted/node/scanners/backend-init-theia.ts +71 -71
  109. package/src/hosted/node/scanners/file-plugin-uri-factory.ts +32 -32
  110. package/src/hosted/node/scanners/grammars-reader.ts +57 -57
  111. package/src/hosted/node/scanners/plugin-uri-factory.ts +33 -33
  112. package/src/hosted/node/scanners/scanner-theia.ts +963 -963
  113. package/src/hosted/node-electron/plugin-ext-hosted-electron-backend-module.ts +26 -26
  114. package/src/hosted/node-electron/scanner-theia-electron.ts +32 -32
  115. package/src/main/browser/authentication-main.ts +401 -401
  116. package/src/main/browser/clipboard-main.ts +38 -38
  117. package/src/main/browser/command-registry-main.ts +130 -130
  118. package/src/main/browser/commands.ts +104 -104
  119. package/src/main/browser/comments/comment-glyph-widget.ts +66 -66
  120. package/src/main/browser/comments/comment-thread-widget.tsx +696 -696
  121. package/src/main/browser/comments/comments-context-key-service.ts +68 -68
  122. package/src/main/browser/comments/comments-contribution.ts +268 -268
  123. package/src/main/browser/comments/comments-decorator.ts +110 -110
  124. package/src/main/browser/comments/comments-main.ts +482 -482
  125. package/src/main/browser/comments/comments-service.ts +205 -205
  126. package/src/main/browser/custom-editors/custom-editor-opener.tsx +205 -205
  127. package/src/main/browser/custom-editors/custom-editor-service.ts +108 -108
  128. package/src/main/browser/custom-editors/custom-editor-undo-redo-handler.ts +41 -41
  129. package/src/main/browser/custom-editors/custom-editor-widget-factory.ts +44 -44
  130. package/src/main/browser/custom-editors/custom-editor-widget.ts +127 -127
  131. package/src/main/browser/custom-editors/custom-editors-main.ts +526 -526
  132. package/src/main/browser/custom-editors/plugin-custom-editor-registry.ts +126 -126
  133. package/src/main/browser/data-transfer/data-transfer-type-converters.ts +68 -68
  134. package/src/main/browser/debug/debug-main.ts +397 -397
  135. package/src/main/browser/debug/plugin-debug-adapter-contribution.ts +48 -48
  136. package/src/main/browser/debug/plugin-debug-configuration-provider.ts +63 -63
  137. package/src/main/browser/debug/plugin-debug-service.ts +427 -427
  138. package/src/main/browser/debug/plugin-debug-session-contribution-registry.ts +76 -76
  139. package/src/main/browser/debug/plugin-debug-session-factory.ts +115 -115
  140. package/src/main/browser/decorations/decorations-main.ts +146 -146
  141. package/src/main/browser/dialogs/modal-notification.ts +112 -112
  142. package/src/main/browser/dialogs/style/modal-notification.css +123 -123
  143. package/src/main/browser/dialogs-main.ts +185 -185
  144. package/src/main/browser/documents-main.ts +275 -275
  145. package/src/main/browser/editors-and-documents-main.ts +448 -425
  146. package/src/main/browser/env-main.ts +60 -60
  147. package/src/main/browser/file-system-main-impl.ts +267 -267
  148. package/src/main/browser/hierarchy/hierarchy-types-converters.ts +189 -189
  149. package/src/main/browser/keybindings/keybindings-contribution-handler.ts +66 -66
  150. package/src/main/browser/label-service-main.ts +51 -51
  151. package/src/main/browser/languages-main.ts +1439 -1439
  152. package/src/main/browser/localization-main.ts +34 -34
  153. package/src/main/browser/main-context.ts +210 -210
  154. package/src/main/browser/main-file-system-event-service.ts +76 -76
  155. package/src/main/browser/menus/menus-contribution-handler.ts +172 -172
  156. package/src/main/browser/menus/plugin-menu-command-adapter.ts +358 -358
  157. package/src/main/browser/menus/vscode-theia-menu-mappings.ts +118 -118
  158. package/src/main/browser/message-registry-main.ts +43 -43
  159. package/src/main/browser/notebooks/notebook-documents-and-editors-main.ts +252 -249
  160. package/src/main/browser/notebooks/notebook-documents-main.ts +202 -202
  161. package/src/main/browser/notebooks/notebook-dto.ts +131 -131
  162. package/src/main/browser/notebooks/notebook-editors-main.ts +88 -88
  163. package/src/main/browser/notebooks/notebook-kernels-main.ts +339 -339
  164. package/src/main/browser/notebooks/notebook-renderers-main.ts +47 -47
  165. package/src/main/browser/notebooks/notebooks-main.ts +164 -164
  166. package/src/main/browser/notebooks/renderers/cell-output-webview.tsx +452 -452
  167. package/src/main/browser/notebooks/renderers/output-webview-internal.ts +636 -636
  168. package/src/main/browser/notebooks/renderers/webview-communication.ts +107 -107
  169. package/src/main/browser/notification-main.ts +26 -26
  170. package/src/main/browser/output-channel-registry-main.ts +53 -53
  171. package/src/main/browser/plugin-authentication-service.ts +71 -71
  172. package/src/main/browser/plugin-contribution-handler.ts +698 -698
  173. package/src/main/browser/plugin-ext-frontend-module.ts +291 -291
  174. package/src/main/browser/plugin-ext-widget.tsx +132 -132
  175. package/src/main/browser/plugin-frontend-contribution.ts +70 -70
  176. package/src/main/browser/plugin-frontend-view-contribution.ts +38 -38
  177. package/src/main/browser/plugin-icon-service.ts +92 -92
  178. package/src/main/browser/plugin-icon-theme-service.ts +625 -625
  179. package/src/main/browser/plugin-shared-style.ts +154 -154
  180. package/src/main/browser/plugin-storage.ts +55 -55
  181. package/src/main/browser/plugin-terminal-registry.ts +27 -27
  182. package/src/main/browser/preference-registry-main.ts +123 -123
  183. package/src/main/browser/quick-open-main.ts +367 -367
  184. package/src/main/browser/scm-main.ts +472 -472
  185. package/src/main/browser/secrets-main.ts +82 -82
  186. package/src/main/browser/selection-provider-command.ts +45 -45
  187. package/src/main/browser/status-bar-message-registry-main.ts +90 -90
  188. package/src/main/browser/style/comments.css +345 -345
  189. package/src/main/browser/style/index.css +84 -84
  190. package/src/main/browser/style/plugin-sidebar.css +73 -73
  191. package/src/main/browser/style/tree.css +54 -54
  192. package/src/main/browser/style/webview.css +55 -55
  193. package/src/main/browser/tabs/tabs-main.ts +388 -384
  194. package/src/main/browser/tasks-main.ts +268 -268
  195. package/src/main/browser/terminal-main.ts +370 -370
  196. package/src/main/browser/test-main.ts +632 -632
  197. package/src/main/browser/text-editor-main.ts +519 -478
  198. package/src/main/browser/text-editor-model-service.ts +111 -111
  199. package/src/main/browser/text-editors-main.ts +234 -234
  200. package/src/main/browser/theme-icon-override.ts +246 -246
  201. package/src/main/browser/theming-main.ts +42 -42
  202. package/src/main/browser/timeline-main.ts +80 -80
  203. package/src/main/browser/uri-main.ts +72 -72
  204. package/src/main/browser/view/dnd-file-content-store.ts +42 -42
  205. package/src/main/browser/view/plugin-tree-view-node-label-provider.ts +81 -81
  206. package/src/main/browser/view/plugin-view-registry.ts +967 -967
  207. package/src/main/browser/view/plugin-view-widget.ts +221 -221
  208. package/src/main/browser/view/tree-view-decorator-service.ts +51 -51
  209. package/src/main/browser/view/tree-view-widget.tsx +931 -931
  210. package/src/main/browser/view/tree-views-main.ts +205 -205
  211. package/src/main/browser/view/view-context-key-service.ts +64 -64
  212. package/src/main/browser/webview/pre/fake.html +14 -14
  213. package/src/main/browser/webview/pre/host.js +130 -130
  214. package/src/main/browser/webview/pre/index.html +17 -17
  215. package/src/main/browser/webview/pre/main.js +682 -682
  216. package/src/main/browser/webview/pre/service-worker.js +296 -296
  217. package/src/main/browser/webview/webview-context-keys.ts +62 -62
  218. package/src/main/browser/webview/webview-environment.ts +87 -87
  219. package/src/main/browser/webview/webview-frontend-security-warnings.ts +59 -59
  220. package/src/main/browser/webview/webview-preferences.ts +72 -72
  221. package/src/main/browser/webview/webview-resource-cache.ts +88 -88
  222. package/src/main/browser/webview/webview-secondary-window-support.ts +47 -47
  223. package/src/main/browser/webview/webview-theme-data-provider.ts +124 -124
  224. package/src/main/browser/webview/webview.ts +718 -718
  225. package/src/main/browser/webview-views/webview-views-main.ts +154 -154
  226. package/src/main/browser/webview-views/webview-views.ts +43 -43
  227. package/src/main/browser/webviews-main.ts +287 -287
  228. package/src/main/browser/window-activity-tracker.ts +96 -96
  229. package/src/main/browser/window-state-main.ts +85 -85
  230. package/src/main/browser/workspace-main.ts +424 -424
  231. package/src/main/common/basic-message-registry-main.ts +53 -53
  232. package/src/main/common/basic-notification-main.ts +86 -86
  233. package/src/main/common/env-main.ts +44 -44
  234. package/src/main/common/plugin-paths-protocol.ts +26 -26
  235. package/src/main/common/plugin-theia-environment.ts +36 -36
  236. package/src/main/common/webview-protocol.ts +28 -28
  237. package/src/main/electron-browser/plugin-ext-frontend-electron-module.ts +25 -25
  238. package/src/main/electron-browser/webview/electron-webview-widget-factory.ts +59 -59
  239. package/src/main/node/errors.spec.ts +37 -37
  240. package/src/main/node/handlers/plugin-theia-directory-handler.ts +137 -137
  241. package/src/main/node/handlers/plugin-theia-file-handler.ts +66 -66
  242. package/src/main/node/paths/const.ts +21 -21
  243. package/src/main/node/paths/plugin-paths-service.ts +163 -163
  244. package/src/main/node/plugin-cli-contribution.ts +85 -85
  245. package/src/main/node/plugin-deployer-contribution.ts +35 -35
  246. package/src/main/node/plugin-deployer-directory-handler-context-impl.ts +45 -45
  247. package/src/main/node/plugin-deployer-entry-impl.ts +132 -132
  248. package/src/main/node/plugin-deployer-file-handler-context-impl.ts +33 -33
  249. package/src/main/node/plugin-deployer-impl.ts +375 -375
  250. package/src/main/node/plugin-deployer-proxy-entry-impl.ts +96 -96
  251. package/src/main/node/plugin-deployer-resolver-context-impl.ts +55 -55
  252. package/src/main/node/plugin-ext-backend-module.ts +106 -106
  253. package/src/main/node/plugin-github-resolver.ts +139 -139
  254. package/src/main/node/plugin-http-resolver.ts +92 -92
  255. package/src/main/node/plugin-localization-server.ts +42 -42
  256. package/src/main/node/plugin-mgmt-cli-contribution.ts +64 -64
  257. package/src/main/node/plugin-remote-cli-contribution.ts +36 -36
  258. package/src/main/node/plugin-remote-copy-contribution.ts +36 -36
  259. package/src/main/node/plugin-server-handler.ts +69 -69
  260. package/src/main/node/plugin-service.ts +97 -97
  261. package/src/main/node/plugin-theia-deployer-participant.ts +32 -32
  262. package/src/main/node/plugin-uninstallation-manager.ts +74 -74
  263. package/src/main/node/plugins-key-value-storage.spec.ts +110 -110
  264. package/src/main/node/plugins-key-value-storage.ts +161 -161
  265. package/src/main/node/resolvers/local-directory-plugin-deployer-resolver.ts +37 -37
  266. package/src/main/node/resolvers/local-plugin-deployer-resolver.ts +56 -56
  267. package/src/main/node/temp-dir-util.ts +36 -36
  268. package/src/main/node/webview-backend-security-warnings.ts +45 -45
  269. package/src/main/style/status-bar.css +35 -35
  270. package/src/plugin/authentication-ext.ts +140 -140
  271. package/src/plugin/clipboard-ext.ts +43 -43
  272. package/src/plugin/command-registry.ts +219 -219
  273. package/src/plugin/comments.ts +549 -549
  274. package/src/plugin/custom-editors.ts +334 -334
  275. package/src/plugin/debug/debug-ext.ts +549 -549
  276. package/src/plugin/debug/plugin-debug-adapter-creator.ts +50 -50
  277. package/src/plugin/debug/plugin-debug-adapter-session.ts +106 -106
  278. package/src/plugin/debug/plugin-debug-adapter-tracker.ts +85 -85
  279. package/src/plugin/decorations.ts +140 -140
  280. package/src/plugin/dialogs.ts +96 -96
  281. package/src/plugin/document-data.ts +366 -366
  282. package/src/plugin/documents.ts +283 -283
  283. package/src/plugin/editors-and-documents.ts +176 -176
  284. package/src/plugin/env.ts +134 -134
  285. package/src/plugin/file-system-event-service-ext-impl.ts +256 -256
  286. package/src/plugin/file-system-ext-impl.ts +415 -415
  287. package/src/plugin/known-commands.spec.ts +50 -50
  288. package/src/plugin/known-commands.ts +429 -429
  289. package/src/plugin/label-service.ts +36 -36
  290. package/src/plugin/languages/call-hierarchy.ts +124 -124
  291. package/src/plugin/languages/code-action.ts +162 -162
  292. package/src/plugin/languages/color.ts +75 -75
  293. package/src/plugin/languages/completion.ts +183 -183
  294. package/src/plugin/languages/declaration.ts +72 -72
  295. package/src/plugin/languages/definition.ts +73 -73
  296. package/src/plugin/languages/diagnostics.ts +325 -325
  297. package/src/plugin/languages/document-drop-edit.ts +44 -44
  298. package/src/plugin/languages/document-formatting.ts +47 -47
  299. package/src/plugin/languages/document-highlight.ts +61 -61
  300. package/src/plugin/languages/evaluatable-expression.ts +47 -47
  301. package/src/plugin/languages/folding.ts +46 -46
  302. package/src/plugin/languages/hover.ts +58 -58
  303. package/src/plugin/languages/implementation.ts +73 -73
  304. package/src/plugin/languages/inlay-hints.ts +149 -149
  305. package/src/plugin/languages/inline-completion.ts +126 -126
  306. package/src/plugin/languages/inline-values.ts +50 -50
  307. package/src/plugin/languages/lens.ts +102 -102
  308. package/src/plugin/languages/link-provider.ts +81 -81
  309. package/src/plugin/languages/linked-editing-range.ts +48 -48
  310. package/src/plugin/languages/on-type-formatting.ts +50 -50
  311. package/src/plugin/languages/outline.ts +126 -126
  312. package/src/plugin/languages/range-formatting.ts +48 -48
  313. package/src/plugin/languages/reference.ts +58 -58
  314. package/src/plugin/languages/rename.ts +130 -130
  315. package/src/plugin/languages/selection-range.ts +80 -80
  316. package/src/plugin/languages/semantic-highlighting.ts +211 -211
  317. package/src/plugin/languages/signature.ts +82 -82
  318. package/src/plugin/languages/type-definition.ts +73 -73
  319. package/src/plugin/languages/type-hierarchy.ts +117 -117
  320. package/src/plugin/languages/util.ts +26 -26
  321. package/src/plugin/languages/workspace-symbol.ts +66 -66
  322. package/src/plugin/languages-utils.ts +68 -68
  323. package/src/plugin/languages.ts +1022 -1022
  324. package/src/plugin/localization-ext.ts +89 -89
  325. package/src/plugin/markdown-string.ts +115 -115
  326. package/src/plugin/message-registry.ts +70 -70
  327. package/src/plugin/node/debug/debug.spec.ts +98 -98
  328. package/src/plugin/node/debug/plugin-node-debug-adapter-creator.ts +167 -167
  329. package/src/plugin/node/env-node-ext.ts +64 -64
  330. package/src/plugin/node/plugin-container-module.ts +165 -165
  331. package/src/plugin/notebook/notebook-document.ts +446 -446
  332. package/src/plugin/notebook/notebook-documents.ts +58 -58
  333. package/src/plugin/notebook/notebook-editor.ts +116 -116
  334. package/src/plugin/notebook/notebook-editors.ts +71 -71
  335. package/src/plugin/notebook/notebook-kernels.ts +631 -631
  336. package/src/plugin/notebook/notebook-renderers.ts +71 -71
  337. package/src/plugin/notebook/notebooks.ts +470 -449
  338. package/src/plugin/notification.ts +80 -80
  339. package/src/plugin/output-channel/log-output-channel.ts +108 -108
  340. package/src/plugin/output-channel/output-channel-item.ts +73 -73
  341. package/src/plugin/output-channel-registry.ts +52 -52
  342. package/src/plugin/path.spec.ts +40 -40
  343. package/src/plugin/path.ts +68 -68
  344. package/src/plugin/plugin-context.ts +1606 -1606
  345. package/src/plugin/plugin-icon-path.ts +53 -53
  346. package/src/plugin/plugin-manager.ts +508 -508
  347. package/src/plugin/plugin-storage.ts +138 -138
  348. package/src/plugin/preference-registry.spec.ts +288 -288
  349. package/src/plugin/preference-registry.ts +335 -335
  350. package/src/plugin/prefix-sum-computer.ts +218 -218
  351. package/src/plugin/quick-open.ts +735 -735
  352. package/src/plugin/scm.ts +919 -919
  353. package/src/plugin/secrets-ext.ts +104 -104
  354. package/src/plugin/status-bar/status-bar-item.ts +193 -193
  355. package/src/plugin/status-bar-message-registry.ts +103 -103
  356. package/src/plugin/tabs.ts +431 -431
  357. package/src/plugin/tasks/task-provider.ts +57 -57
  358. package/src/plugin/tasks/tasks.ts +252 -252
  359. package/src/plugin/telemetry-ext.ts +298 -298
  360. package/src/plugin/terminal-ext.ts +569 -569
  361. package/src/plugin/test-item.ts +174 -174
  362. package/src/plugin/tests.ts +545 -545
  363. package/src/plugin/text-editor.ts +581 -581
  364. package/src/plugin/text-editors.ts +157 -157
  365. package/src/plugin/theming.ts +73 -73
  366. package/src/plugin/timeline.ts +186 -186
  367. package/src/plugin/tree/tree-views.ts +682 -682
  368. package/src/plugin/type-converters.spec.ts +476 -476
  369. package/src/plugin/type-converters.ts +1768 -1768
  370. package/src/plugin/types-impl.spec.ts +85 -85
  371. package/src/plugin/types-impl.ts +4011 -4011
  372. package/src/plugin/uri-ext.ts +60 -60
  373. package/src/plugin/webview-views.ts +228 -228
  374. package/src/plugin/webviews.ts +468 -468
  375. package/src/plugin/window-state.ts +75 -75
  376. package/src/plugin/word-helper.ts +162 -162
  377. package/src/plugin/workspace.ts +505 -505
  378. package/src/plugin-ext-backend-electron-module.ts +24 -24
  379. package/src/plugin-ext-backend-module.ts +24 -24
  380. package/src/plugin-ext-frontend-electron-module.ts +19 -19
  381. package/src/plugin-ext-frontend-module.ts +19 -19
@@ -1,931 +1,931 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018-2019 Red Hat, Inc. 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, postConstruct } from '@theia/core/shared/inversify';
18
- import { TreeViewsExt, TreeViewItemCollapsibleState, TreeViewItem, TreeViewItemReference, ThemeIcon, DataTransferFileDTO } from '../../../common/plugin-api-rpc';
19
- import { Command } from '../../../common/plugin-api-rpc-model';
20
- import {
21
- TreeNode,
22
- NodeProps,
23
- SelectableTreeNode,
24
- ExpandableTreeNode,
25
- CompositeTreeNode,
26
- TreeImpl,
27
- TREE_NODE_SEGMENT_CLASS,
28
- TREE_NODE_SEGMENT_GROW_CLASS,
29
- TREE_NODE_TAIL_CLASS,
30
- TreeModelImpl,
31
- TreeViewWelcomeWidget,
32
- TooltipAttributes,
33
- TreeSelection,
34
- HoverService,
35
- ApplicationShell,
36
- KeybindingRegistry
37
- } from '@theia/core/lib/browser';
38
- import { MenuPath, MenuModelRegistry, ActionMenuNode } from '@theia/core/lib/common/menu';
39
- import * as React from '@theia/core/shared/react';
40
- import { PluginSharedStyle } from '../plugin-shared-style';
41
- import { ACTION_ITEM, Widget } from '@theia/core/lib/browser/widgets/widget';
42
- import { Emitter, Event } from '@theia/core/lib/common/event';
43
- import { MessageService } from '@theia/core/lib/common/message-service';
44
- import { View } from '../../../common/plugin-protocol';
45
- import { URI } from '@theia/core/lib/common/uri';
46
- import { ContextKeyService } from '@theia/core/lib/browser/context-key-service';
47
- import { MarkdownString } from '@theia/core/lib/common/markdown-rendering';
48
- import { LabelParser } from '@theia/core/lib/browser/label-parser';
49
- import { AccessibilityInformation } from '@theia/plugin';
50
- import { ColorRegistry } from '@theia/core/lib/browser/color-registry';
51
- import { DecoratedTreeNode } from '@theia/core/lib/browser/tree/tree-decorator';
52
- import { WidgetDecoration } from '@theia/core/lib/browser/widget-decoration';
53
- import { CancellationTokenSource, CancellationToken, Mutable } from '@theia/core/lib/common';
54
- import { mixin } from '../../../common/types';
55
- import { Deferred } from '@theia/core/lib/common/promise-util';
56
- import { DnDFileContentStore } from './dnd-file-content-store';
57
-
58
- export const TREE_NODE_HYPERLINK = 'theia-TreeNodeHyperlink';
59
- export const VIEW_ITEM_CONTEXT_MENU: MenuPath = ['view-item-context-menu'];
60
- export const VIEW_ITEM_INLINE_MENU: MenuPath = ['view-item-context-menu', 'inline'];
61
-
62
- export interface SelectionEventHandler {
63
- readonly node: SelectableTreeNode;
64
- readonly contextSelection: boolean;
65
- }
66
-
67
- export interface TreeViewNode extends SelectableTreeNode, DecoratedTreeNode {
68
- contextValue?: string;
69
- command?: Command;
70
- resourceUri?: string;
71
- themeIcon?: ThemeIcon;
72
- tooltip?: string | MarkdownString;
73
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
74
- description?: string | boolean | any;
75
- accessibilityInformation?: AccessibilityInformation;
76
- }
77
- export namespace TreeViewNode {
78
- export function is(arg: TreeNode | undefined): arg is TreeViewNode {
79
- return !!arg && SelectableTreeNode.is(arg) && DecoratedTreeNode.is(arg);
80
- }
81
- }
82
-
83
- export class ResolvableTreeViewNode implements TreeViewNode {
84
- contextValue?: string;
85
- command?: Command;
86
- resourceUri?: string;
87
- themeIcon?: ThemeIcon;
88
- tooltip?: string | MarkdownString;
89
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
90
- description?: string | boolean | any;
91
- accessibilityInformation?: AccessibilityInformation;
92
- selected: boolean;
93
- focus?: boolean;
94
- id: string;
95
- name?: string;
96
- icon?: string;
97
- visible?: boolean;
98
- parent: Readonly<CompositeTreeNode>;
99
- previousSibling?: TreeNode;
100
- nextSibling?: TreeNode;
101
- busy?: number;
102
- decorationData: WidgetDecoration.Data;
103
-
104
- resolve: ((token: CancellationToken) => Promise<void>);
105
-
106
- private _resolved = false;
107
- private resolving: Deferred<void> | undefined;
108
-
109
- constructor(treeViewNode: Partial<TreeViewNode>, resolve: (token: CancellationToken) => Promise<TreeViewItem | undefined>) {
110
- mixin(this, treeViewNode);
111
- this.resolve = async (token: CancellationToken) => {
112
- if (this.resolving) {
113
- return this.resolving.promise;
114
- }
115
- if (!this._resolved) {
116
- this.resolving = new Deferred();
117
- const resolvedTreeItem = await resolve(token);
118
- if (resolvedTreeItem) {
119
- this.command = this.command ?? resolvedTreeItem.command;
120
- this.tooltip = this.tooltip ?? resolvedTreeItem.tooltip;
121
- }
122
- this.resolving.resolve();
123
- this.resolving = undefined;
124
- }
125
- if (!token.isCancellationRequested) {
126
- this._resolved = true;
127
- }
128
- };
129
- }
130
-
131
- reset(): void {
132
- this._resolved = false;
133
- this.resolving = undefined;
134
- this.command = undefined;
135
- this.tooltip = undefined;
136
- }
137
-
138
- get resolved(): boolean {
139
- return this._resolved;
140
- }
141
- }
142
-
143
- export class ResolvableCompositeTreeViewNode extends ResolvableTreeViewNode implements CompositeTreeViewNode {
144
- expanded: boolean;
145
- children: readonly TreeNode[];
146
- constructor(
147
- treeViewNode: Pick<CompositeTreeViewNode, 'children' | 'expanded'> & Partial<TreeViewNode>,
148
- resolve: (token: CancellationToken) => Promise<TreeViewItem | undefined>) {
149
- super(treeViewNode, resolve);
150
- this.expanded = treeViewNode.expanded;
151
- this.children = treeViewNode.children;
152
- }
153
- }
154
-
155
- export interface CompositeTreeViewNode extends TreeViewNode, ExpandableTreeNode, CompositeTreeNode {
156
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
157
- description?: string | boolean | any;
158
- }
159
- export namespace CompositeTreeViewNode {
160
- export function is(arg: TreeNode | undefined): arg is CompositeTreeViewNode {
161
- return TreeViewNode.is(arg) && ExpandableTreeNode.is(arg) && CompositeTreeNode.is(arg);
162
- }
163
- }
164
-
165
- @injectable()
166
- export class TreeViewWidgetOptions {
167
- id: string;
168
- manageCheckboxStateManually: boolean | undefined;
169
- showCollapseAll: boolean | undefined;
170
- multiSelect: boolean | undefined;
171
- dragMimeTypes: string[] | undefined;
172
- dropMimeTypes: string[] | undefined;
173
- }
174
-
175
- @injectable()
176
- export class PluginTree extends TreeImpl {
177
-
178
- @inject(PluginSharedStyle)
179
- protected readonly sharedStyle: PluginSharedStyle;
180
-
181
- @inject(TreeViewWidgetOptions)
182
- protected readonly options: TreeViewWidgetOptions;
183
-
184
- @inject(MessageService)
185
- protected readonly notification: MessageService;
186
-
187
- protected readonly onDidChangeWelcomeStateEmitter: Emitter<void> = new Emitter<void>();
188
- readonly onDidChangeWelcomeState = this.onDidChangeWelcomeStateEmitter.event;
189
-
190
- private _proxy: TreeViewsExt | undefined;
191
- private _viewInfo: View | undefined;
192
- private _isEmpty: boolean;
193
- private _hasTreeItemResolve: Promise<boolean> = Promise.resolve(false);
194
-
195
- set proxy(proxy: TreeViewsExt | undefined) {
196
- this._proxy = proxy;
197
- if (proxy) {
198
- this._hasTreeItemResolve = proxy.$hasResolveTreeItem(this.options.id);
199
- } else {
200
- this._hasTreeItemResolve = Promise.resolve(false);
201
- }
202
- }
203
- get proxy(): TreeViewsExt | undefined {
204
- return this._proxy;
205
- }
206
-
207
- get hasTreeItemResolve(): Promise<boolean> {
208
- return this._hasTreeItemResolve;
209
- }
210
-
211
- set viewInfo(viewInfo: View) {
212
- this._viewInfo = viewInfo;
213
- }
214
-
215
- get isEmpty(): boolean {
216
- return this._isEmpty;
217
- }
218
-
219
- protected override async resolveChildren(parent: CompositeTreeNode): Promise<TreeNode[]> {
220
- if (!this._proxy) {
221
- return super.resolveChildren(parent);
222
- }
223
- const children = await this.fetchChildren(this._proxy, parent);
224
- const hasResolve = await this.hasTreeItemResolve;
225
- return children.map(value => hasResolve ? this.createResolvableTreeNode(value, parent) : this.createTreeNode(value, parent));
226
- }
227
-
228
- protected async fetchChildren(proxy: TreeViewsExt, parent: CompositeTreeNode): Promise<TreeViewItem[]> {
229
- try {
230
- const children = await proxy.$getChildren(this.options.id, parent.id);
231
- const oldEmpty = this._isEmpty;
232
- this._isEmpty = !parent.id && (!children || children.length === 0);
233
- if (oldEmpty !== this._isEmpty) {
234
- this.onDidChangeWelcomeStateEmitter.fire();
235
- }
236
- return children || [];
237
- } catch (e) {
238
- if (e) {
239
- console.error(`Failed to fetch children for '${this.options.id}'`, e);
240
- const label = this._viewInfo ? this._viewInfo.name : this.options.id;
241
- this.notification.error(`${label}: ${e.message}`);
242
- }
243
- return [];
244
- }
245
- }
246
-
247
- protected createTreeNode(item: TreeViewItem, parent: CompositeTreeNode): TreeNode {
248
- const update: Partial<TreeViewNode> = this.createTreeNodeUpdate(item);
249
- const node = this.getNode(item.id);
250
- if (item.collapsibleState !== undefined && item.collapsibleState !== TreeViewItemCollapsibleState.None) {
251
- if (CompositeTreeViewNode.is(node)) {
252
- return Object.assign(node, update);
253
- }
254
- return Object.assign({
255
- id: item.id,
256
- parent,
257
- visible: true,
258
- selected: false,
259
- expanded: TreeViewItemCollapsibleState.Expanded === item.collapsibleState,
260
- children: [],
261
- command: item.command
262
- }, update);
263
- }
264
- if (TreeViewNode.is(node) && !ExpandableTreeNode.is(node)) {
265
- return Object.assign(node, update, { command: item.command });
266
- }
267
- return Object.assign({
268
- id: item.id,
269
- parent,
270
- visible: true,
271
- selected: false,
272
- command: item.command,
273
- }, update);
274
- }
275
-
276
- override markAsChecked(node: Mutable<TreeNode>, checked: boolean): void {
277
- function findParentsToChange(child: TreeNode, nodes: TreeNode[]): void {
278
- if ((child.parent?.checkboxInfo !== undefined && child.parent.checkboxInfo.checked !== checked) &&
279
- (!checked || !child.parent.children.some(candidate => candidate !== child && candidate.checkboxInfo?.checked === false))) {
280
- nodes.push(child.parent);
281
- findParentsToChange(child.parent, nodes);
282
- }
283
- }
284
-
285
- function findChildrenToChange(parent: TreeNode, nodes: TreeNode[]): void {
286
- if (CompositeTreeNode.is(parent)) {
287
- parent.children.forEach(child => {
288
- if (child.checkboxInfo !== undefined && child.checkboxInfo.checked !== checked) {
289
- nodes.push(child);
290
- }
291
- findChildrenToChange(child, nodes);
292
- });
293
- }
294
- }
295
-
296
- const nodesToChange = [node];
297
- if (!this.options.manageCheckboxStateManually) {
298
- findParentsToChange(node, nodesToChange);
299
- findChildrenToChange(node, nodesToChange);
300
-
301
- }
302
- nodesToChange.forEach(n => n.checkboxInfo!.checked = checked);
303
- this.onDidUpdateEmitter.fire(nodesToChange);
304
- this.proxy?.$checkStateChanged(this.options.id, [{ id: node.id, checked: checked }]);
305
- }
306
-
307
- /** Creates a resolvable tree node. If a node already exists, reset it because the underlying TreeViewItem might have been disposed in the backend. */
308
- protected createResolvableTreeNode(item: TreeViewItem, parent: CompositeTreeNode): TreeNode {
309
- const update: Partial<TreeViewNode> = this.createTreeNodeUpdate(item);
310
- const node = this.getNode(item.id);
311
-
312
- // Node is a composite node that might contain children
313
- if (item.collapsibleState !== undefined && item.collapsibleState !== TreeViewItemCollapsibleState.None) {
314
- // Reuse existing composite node and reset it
315
- if (node instanceof ResolvableCompositeTreeViewNode) {
316
- node.reset();
317
- return Object.assign(node, update);
318
- }
319
- // Create new composite node
320
- const compositeNode = Object.assign({
321
- id: item.id,
322
- parent,
323
- visible: true,
324
- selected: false,
325
- expanded: TreeViewItemCollapsibleState.Expanded === item.collapsibleState,
326
- children: [],
327
- command: item.command
328
- }, update);
329
- return new ResolvableCompositeTreeViewNode(compositeNode, async (token: CancellationToken) => this._proxy?.$resolveTreeItem(this.options.id, item.id, token));
330
- }
331
-
332
- // Node is a leaf
333
- // Reuse existing node and reset it.
334
- if (node instanceof ResolvableTreeViewNode && !ExpandableTreeNode.is(node)) {
335
- node.reset();
336
- return Object.assign(node, update);
337
- }
338
- const treeNode = Object.assign({
339
- id: item.id,
340
- parent,
341
- visible: true,
342
- selected: false,
343
- command: item.command,
344
- }, update);
345
- return new ResolvableTreeViewNode(treeNode, async (token: CancellationToken) => this._proxy?.$resolveTreeItem(this.options.id, item.id, token));
346
- }
347
-
348
- protected createTreeNodeUpdate(item: TreeViewItem): Partial<TreeViewNode> {
349
- const decorationData = this.toDecorationData(item);
350
- const icon = this.toIconClass(item);
351
- const resourceUri = item.resourceUri && URI.fromComponents(item.resourceUri).toString();
352
- const themeIcon = item.themeIcon ? item.themeIcon : item.collapsibleState !== TreeViewItemCollapsibleState.None ? { id: 'folder' } : undefined;
353
- return {
354
- name: item.label,
355
- decorationData,
356
- icon,
357
- description: item.description,
358
- themeIcon,
359
- resourceUri,
360
- tooltip: item.tooltip,
361
- contextValue: item.contextValue,
362
- command: item.command,
363
- checkboxInfo: item.checkboxInfo,
364
- accessibilityInformation: item.accessibilityInformation,
365
- };
366
- }
367
-
368
- protected toDecorationData(item: TreeViewItem): WidgetDecoration.Data {
369
- let decoration: WidgetDecoration.Data = {};
370
- if (item.highlights) {
371
- const highlight = {
372
- ranges: item.highlights.map(h => ({ offset: h[0], length: h[1] - h[0] }))
373
- };
374
- decoration = { highlight };
375
- }
376
- return decoration;
377
- }
378
-
379
- protected toIconClass(item: TreeViewItem): string | undefined {
380
- if (item.icon) {
381
- return 'fa ' + item.icon;
382
- }
383
- if (item.iconUrl) {
384
- const reference = this.sharedStyle.toIconClass(item.iconUrl);
385
- this.toDispose.push(reference);
386
- return reference.object.iconClass;
387
- }
388
- return undefined;
389
- }
390
-
391
- }
392
-
393
- @injectable()
394
- export class PluginTreeModel extends TreeModelImpl {
395
-
396
- @inject(PluginTree)
397
- protected override readonly tree: PluginTree;
398
-
399
- set proxy(proxy: TreeViewsExt | undefined) {
400
- this.tree.proxy = proxy;
401
- }
402
- get proxy(): TreeViewsExt | undefined {
403
- return this.tree.proxy;
404
- }
405
-
406
- get hasTreeItemResolve(): Promise<boolean> {
407
- return this.tree.hasTreeItemResolve;
408
- }
409
-
410
- set viewInfo(viewInfo: View) {
411
- this.tree.viewInfo = viewInfo;
412
- }
413
-
414
- get isTreeEmpty(): boolean {
415
- return this.tree.isEmpty;
416
- }
417
-
418
- get onDidChangeWelcomeState(): Event<void> {
419
- return this.tree.onDidChangeWelcomeState;
420
- }
421
-
422
- override doOpenNode(node: TreeNode): void {
423
- super.doOpenNode(node);
424
- if (node instanceof ResolvableTreeViewNode) {
425
- node.resolve(CancellationToken.None);
426
- }
427
- }
428
- }
429
-
430
- @injectable()
431
- export class TreeViewWidget extends TreeViewWelcomeWidget {
432
-
433
- protected _contextSelection = false;
434
-
435
- @inject(ApplicationShell)
436
- protected readonly applicationShell: ApplicationShell;
437
-
438
- @inject(MenuModelRegistry)
439
- protected readonly menus: MenuModelRegistry;
440
-
441
- @inject(KeybindingRegistry)
442
- protected readonly keybindings: KeybindingRegistry;
443
-
444
- @inject(ContextKeyService)
445
- protected readonly contextKeys: ContextKeyService;
446
-
447
- @inject(TreeViewWidgetOptions)
448
- readonly options: TreeViewWidgetOptions;
449
-
450
- @inject(PluginTreeModel)
451
- override readonly model: PluginTreeModel;
452
-
453
- @inject(ContextKeyService)
454
- protected readonly contextKeyService: ContextKeyService;
455
-
456
- @inject(HoverService)
457
- protected readonly hoverService: HoverService;
458
-
459
- @inject(LabelParser)
460
- protected readonly labelParser: LabelParser;
461
-
462
- @inject(ColorRegistry)
463
- protected readonly colorRegistry: ColorRegistry;
464
-
465
- @inject(DnDFileContentStore)
466
- protected readonly dndFileContentStore: DnDFileContentStore;
467
-
468
- protected treeDragType: string;
469
- protected readonly expansionTimeouts: Map<string, number> = new Map();
470
-
471
- @postConstruct()
472
- protected override init(): void {
473
- super.init();
474
- this.id = this.options.id;
475
- this.addClass('theia-tree-view');
476
- this.node.style.height = '100%';
477
- this.model.onDidChangeWelcomeState(this.update, this);
478
- this.toDispose.push(this.model.onDidChangeWelcomeState(this.update, this));
479
- this.toDispose.push(this.onDidChangeVisibilityEmitter);
480
- this.toDispose.push(this.contextKeyService.onDidChange(() => this.update()));
481
- this.toDispose.push(this.keybindings.onKeybindingsChanged(() => this.update()));
482
- this.treeDragType = `application/vnd.code.tree.${this.id.toLowerCase()}`;
483
- }
484
-
485
- get showCollapseAll(): boolean {
486
- return this.options.showCollapseAll || false;
487
- }
488
-
489
- protected override renderIcon(node: TreeNode, props: NodeProps): React.ReactNode {
490
- const icon = this.toNodeIcon(node);
491
- if (icon) {
492
- let style: React.CSSProperties | undefined;
493
- if (TreeViewNode.is(node) && node.themeIcon?.color) {
494
- const color = this.colorRegistry.getCurrentColor(node.themeIcon.color.id);
495
- if (color) {
496
- style = { color };
497
- }
498
- }
499
- return <div className={icon + ' theia-tree-view-icon'} style={style}></div>;
500
- }
501
- return undefined;
502
- }
503
-
504
- protected override renderCaption(node: TreeViewNode, props: NodeProps): React.ReactNode {
505
- const classes = [TREE_NODE_SEGMENT_CLASS];
506
- if (!this.hasTrailingSuffixes(node)) {
507
- classes.push(TREE_NODE_SEGMENT_GROW_CLASS);
508
- }
509
- const className = classes.join(' ');
510
-
511
- let attrs: React.HTMLAttributes<HTMLElement> & Partial<TooltipAttributes> = {
512
- ...this.decorateCaption(node, {}),
513
- className,
514
- id: node.id
515
- };
516
-
517
- if (node.accessibilityInformation) {
518
- attrs = {
519
- ...attrs,
520
- 'aria-label': node.accessibilityInformation.label,
521
- 'role': node.accessibilityInformation.role
522
- };
523
- }
524
-
525
- if (!node.tooltip && node instanceof ResolvableTreeViewNode) {
526
- let configuredTip = false;
527
- let source: CancellationTokenSource | undefined;
528
- attrs = {
529
- ...attrs,
530
- onMouseLeave: () => source?.cancel(),
531
- onMouseEnter: async event => {
532
- const target = event.currentTarget; // event.currentTarget will be null after awaiting node resolve()
533
- if (configuredTip) {
534
- if (MarkdownString.is(node.tooltip)) {
535
- this.hoverService.requestHover({
536
- content: node.tooltip,
537
- target: event.target as HTMLElement,
538
- position: 'right'
539
- });
540
- }
541
- return;
542
- }
543
- if (!node.resolved) {
544
- source = new CancellationTokenSource();
545
- const token = source.token;
546
- await node.resolve(token);
547
- if (token.isCancellationRequested) {
548
- return;
549
- }
550
- }
551
- if (MarkdownString.is(node.tooltip)) {
552
- this.hoverService.requestHover({
553
- content: node.tooltip,
554
- target: event.target as HTMLElement,
555
- position: 'right'
556
- });
557
- } else {
558
- const title = node.tooltip ||
559
- (node.resourceUri && this.labelProvider.getLongName(new URI(node.resourceUri)))
560
- || this.toNodeName(node);
561
- target.title = title;
562
- }
563
- configuredTip = true;
564
- }
565
- };
566
- } else if (MarkdownString.is(node.tooltip)) {
567
- attrs = {
568
- ...attrs,
569
- onMouseEnter: event => {
570
- this.hoverService.requestHover({
571
- content: node.tooltip!,
572
- target: event.target as HTMLElement,
573
- position: 'right'
574
- });
575
- }
576
- };
577
- } else {
578
- const title = node.tooltip ||
579
- (node.resourceUri && this.labelProvider.getLongName(new URI(node.resourceUri)))
580
- || this.toNodeName(node);
581
-
582
- attrs = {
583
- ...attrs,
584
- title
585
- };
586
- }
587
-
588
- const children: React.ReactNode[] = [];
589
- const caption = this.toNodeName(node);
590
- const highlight = this.getDecorationData(node, 'highlight')[0];
591
- if (highlight) {
592
- children.push(this.toReactNode(caption, highlight));
593
- }
594
- const searchHighlight = this.searchHighlights && this.searchHighlights.get(node.id);
595
- if (searchHighlight) {
596
- children.push(...this.toReactNode(caption, searchHighlight));
597
- } else if (!highlight) {
598
- children.push(caption);
599
- }
600
- const description = this.toNodeDescription(node);
601
- if (description) {
602
- children.push(<span className='theia-tree-view-description'>{description}</span>);
603
- }
604
- return <div {...attrs}>{...children}</div>;
605
- }
606
-
607
- protected override createNodeAttributes(node: TreeViewNode, props: NodeProps): React.Attributes & React.HTMLAttributes<HTMLElement> {
608
- const attrs = super.createNodeAttributes(node, props);
609
-
610
- if (this.options.dragMimeTypes) {
611
- attrs.onDragStart = event => this.handleDragStartEvent(node, event);
612
- attrs.onDragEnd = event => this.handleDragEnd(node, event);
613
- attrs.draggable = true;
614
- }
615
-
616
- if (this.options.dropMimeTypes) {
617
- attrs.onDrop = event => this.handleDropEvent(node, event);
618
- attrs.onDragEnter = event => this.handleDragEnter(node, event);
619
- attrs.onDragLeave = event => this.handleDragLeave(node, event);
620
- attrs.onDragOver = event => this.handleDragOver(event);
621
- }
622
-
623
- return attrs;
624
- }
625
- handleDragLeave(node: TreeViewNode, event: React.DragEvent<HTMLElement>): void {
626
- const timeout = this.expansionTimeouts.get(node.id);
627
- if (typeof timeout !== 'undefined') {
628
- console.debug(`dragleave ${node.id} canceling timeout`);
629
- clearTimeout(timeout);
630
- this.expansionTimeouts.delete(node.id);
631
- }
632
- }
633
- handleDragEnter(node: TreeViewNode, event: React.DragEvent<HTMLElement>): void {
634
- console.debug(`dragenter ${node.id}`);
635
- if (ExpandableTreeNode.is(node)) {
636
- console.debug(`dragenter ${node.id} starting timeout`);
637
- this.expansionTimeouts.set(node.id, window.setTimeout(() => {
638
- console.debug(`dragenter ${node.id} timeout reached`);
639
- this.model.expandNode(node);
640
- }, 500));
641
- }
642
- }
643
-
644
- protected override createContainerAttributes(): React.HTMLAttributes<HTMLElement> {
645
- const attrs = super.createContainerAttributes();
646
- if (this.options.dropMimeTypes) {
647
- attrs.onDrop = event => this.handleDropEvent(undefined, event);
648
- attrs.onDragOver = event => this.handleDragOver(event);
649
- }
650
- return attrs;
651
- }
652
-
653
- protected handleDragStartEvent(node: TreeViewNode, event: React.DragEvent<HTMLElement>): void {
654
- event.dataTransfer!.setData(this.treeDragType, '');
655
- let selectedNodes: TreeViewNode[] = [];
656
- if (this.model.selectedNodes.find(selected => TreeNode.equals(selected, node))) {
657
- selectedNodes = this.model.selectedNodes.filter(TreeViewNode.is);
658
- } else {
659
- selectedNodes = [node];
660
- }
661
-
662
- this.options.dragMimeTypes!.forEach(type => {
663
- if (type === 'text/uri-list') {
664
- ApplicationShell.setDraggedEditorUris(event.dataTransfer, selectedNodes.filter(n => n.resourceUri).map(n => new URI(n.resourceUri)));
665
- } else {
666
- event.dataTransfer.setData(type, '');
667
- }
668
- });
669
-
670
- this.model.proxy!.$dragStarted(this.options.id, selectedNodes.map(selected => selected.id), CancellationToken.None).then(maybeUris => {
671
- if (maybeUris) {
672
- this.applicationShell.addAdditionalDraggedEditorUris(maybeUris.map(uri => URI.fromComponents(uri)));
673
- }
674
- });
675
- }
676
-
677
- handleDragEnd(node: TreeViewNode, event: React.DragEvent<HTMLElement>): void {
678
- this.applicationShell.clearAdditionalDraggedEditorUris();
679
- this.model.proxy!.$dragEnd(this.id);
680
- }
681
-
682
- handleDragOver(event: React.DragEvent<HTMLElement>): void {
683
- const hasFiles = (items: DataTransferItemList) => {
684
- for (let i = 0; i < items.length; i++) {
685
- if (items[i].kind === 'file') {
686
- return true;
687
- }
688
- }
689
- return false;
690
- };
691
-
692
- if (event.dataTransfer) {
693
- const canDrop = event.dataTransfer.types.some(type => this.options.dropMimeTypes!.includes(type)) ||
694
- event.dataTransfer.types.includes(this.treeDragType) ||
695
- this.options.dropMimeTypes!.includes('files') && hasFiles(event.dataTransfer.items);
696
- if (canDrop) {
697
- event.preventDefault();
698
- event.dataTransfer.dropEffect = 'move';
699
- } else {
700
- event.dataTransfer.dropEffect = 'none';
701
- }
702
- event.stopPropagation();
703
- }
704
- }
705
-
706
- protected handleDropEvent(node: TreeViewNode | undefined, event: React.DragEvent<HTMLElement>): void {
707
- if (event.dataTransfer) {
708
- const items: [string, string | DataTransferFileDTO][] = [];
709
- let files: string[] = [];
710
- try {
711
- for (let i = 0; i < event.dataTransfer.items.length; i++) {
712
- const transferItem = event.dataTransfer.items[i];
713
- if (transferItem.type !== this.treeDragType) {
714
- // do not pass the artificial drag data to the extension
715
- const f = event.dataTransfer.items[i].getAsFile();
716
- if (f) {
717
- const fileId = this.dndFileContentStore.addFile(f);
718
- files.push(fileId);
719
- const uri = f.path ? {
720
- scheme: 'file',
721
- path: f.path,
722
- authority: '',
723
- query: '',
724
- fragment: ''
725
- } : undefined;
726
- items.push([transferItem.type, new DataTransferFileDTO(f.name, fileId, uri)]);
727
- } else {
728
- const textData = event.dataTransfer.getData(transferItem.type);
729
- if (textData) {
730
- items.push([transferItem.type, textData]);
731
- }
732
- }
733
- }
734
- }
735
- if (items.length > 0 || event.dataTransfer.types.includes(this.treeDragType)) {
736
- event.preventDefault();
737
- event.stopPropagation();
738
- this.model.proxy?.$drop(this.id, node?.id, items, CancellationToken.None).finally(() => {
739
- for (const file of files) {
740
- this.dndFileContentStore.removeFile(file);
741
- }
742
- });
743
- files = [];
744
- }
745
- } catch (e) {
746
- for (const file of files) {
747
- this.dndFileContentStore.removeFile(file);
748
- }
749
- throw e;
750
- }
751
- }
752
- }
753
-
754
- protected override renderTailDecorations(treeViewNode: TreeViewNode, props: NodeProps): React.ReactNode {
755
- return this.contextKeys.with({ view: this.id, viewItem: treeViewNode.contextValue }, () => {
756
- const menu = this.menus.getMenu(VIEW_ITEM_INLINE_MENU);
757
- const args = this.toContextMenuArgs(treeViewNode);
758
- const inlineCommands = menu.children.filter((item): item is ActionMenuNode => item instanceof ActionMenuNode);
759
- const tailDecorations = super.renderTailDecorations(treeViewNode, props);
760
- return <React.Fragment>
761
- {inlineCommands.length > 0 && <div className={TREE_NODE_SEGMENT_CLASS + ' flex'}>
762
- {inlineCommands.map((item, index) => this.renderInlineCommand(item, index, this.focusService.hasFocus(treeViewNode), args))}
763
- </div>}
764
- {tailDecorations !== undefined && <div className={TREE_NODE_SEGMENT_CLASS + ' flex'}>{tailDecorations}</div>}
765
- </React.Fragment>;
766
- });
767
- }
768
-
769
- toTreeViewItemReference(treeNode: TreeNode): TreeViewItemReference {
770
- return { viewId: this.id, itemId: treeNode.id };
771
- }
772
-
773
- protected resolveKeybindingForCommand(command: string | undefined): string {
774
- let result = '';
775
- if (command) {
776
- const bindings = this.keybindings.getKeybindingsForCommand(command);
777
- let found = false;
778
- if (bindings && bindings.length > 0) {
779
- bindings.forEach(binding => {
780
- if (!found && this.keybindings.isEnabledInScope(binding, this.node)) {
781
- found = true;
782
- result = ` (${this.keybindings.acceleratorFor(binding, '+')})`;
783
- }
784
- });
785
- }
786
- }
787
- return result;
788
- }
789
-
790
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
791
- protected renderInlineCommand(actionMenuNode: ActionMenuNode, index: number, tabbable: boolean, args: any[]): React.ReactNode {
792
- if (!actionMenuNode.icon || !this.commands.isVisible(actionMenuNode.command, ...args) || !actionMenuNode.when || !this.contextKeys.match(actionMenuNode.when)) {
793
- return false;
794
- }
795
- const className = [TREE_NODE_SEGMENT_CLASS, TREE_NODE_TAIL_CLASS, actionMenuNode.icon, ACTION_ITEM, 'theia-tree-view-inline-action'].join(' ');
796
- const tabIndex = tabbable ? 0 : undefined;
797
- const titleString = actionMenuNode.label + this.resolveKeybindingForCommand(actionMenuNode.command);
798
-
799
- return <div key={index} className={className} title={titleString} tabIndex={tabIndex} onClick={e => {
800
- e.stopPropagation();
801
- this.commands.executeCommand(actionMenuNode.command, ...args);
802
- }} />;
803
- }
804
-
805
- protected override toContextMenuArgs(target: SelectableTreeNode): [TreeViewItemReference, TreeViewItemReference[]] | [TreeViewItemReference] {
806
- if (this.options.multiSelect) {
807
- return [this.toTreeViewItemReference(target), this.model.selectedNodes.map(node => this.toTreeViewItemReference(node))];
808
- } else {
809
- return [this.toTreeViewItemReference(target)];
810
- }
811
- }
812
-
813
- override setFlag(flag: Widget.Flag): void {
814
- super.setFlag(flag);
815
- if (flag === Widget.Flag.IsVisible) {
816
- this.onDidChangeVisibilityEmitter.fire(this.isVisible);
817
- }
818
- }
819
-
820
- override clearFlag(flag: Widget.Flag): void {
821
- super.clearFlag(flag);
822
- if (flag === Widget.Flag.IsVisible) {
823
- this.onDidChangeVisibilityEmitter.fire(this.isVisible);
824
- }
825
- }
826
-
827
- override handleEnter(event: KeyboardEvent): void {
828
- super.handleEnter(event);
829
- this.tryExecuteCommand();
830
- }
831
-
832
- protected override tapNode(node?: TreeNode): void {
833
- super.tapNode(node);
834
- this.findCommands(node).then(commandMap => {
835
- if (commandMap.size > 0) {
836
- this.tryExecuteCommandMap(commandMap);
837
- } else if (node && this.isExpandable(node)) {
838
- this.model.toggleNodeExpansion(node);
839
- }
840
- });
841
- }
842
-
843
- // execute TreeItem.command if present
844
- protected async tryExecuteCommand(node?: TreeNode): Promise<void> {
845
- this.tryExecuteCommandMap(await this.findCommands(node));
846
- }
847
-
848
- protected tryExecuteCommandMap(commandMap: Map<string, unknown[]>): void {
849
- commandMap.forEach((args, commandId) => {
850
- this.commands.executeCommand(commandId, ...args);
851
- });
852
- }
853
-
854
- protected async findCommands(node?: TreeNode): Promise<Map<string, unknown[]>> {
855
- const commandMap = new Map<string, unknown[]>();
856
- const treeNodes = (node ? [node] : this.model.selectedNodes) as TreeViewNode[];
857
- if (await this.model.hasTreeItemResolve) {
858
- const cancellationToken = new CancellationTokenSource().token;
859
- // Resolve all resolvable nodes that don't have a command and haven't been resolved.
860
- const allResolved = Promise.all(treeNodes.map(maybeNeedsResolve => {
861
- if (!maybeNeedsResolve.command && maybeNeedsResolve instanceof ResolvableTreeViewNode && !maybeNeedsResolve.resolved) {
862
- return maybeNeedsResolve.resolve(cancellationToken).catch(err => {
863
- console.error(`Failed to resolve tree item '${maybeNeedsResolve.id}'`, err);
864
- });
865
- }
866
- return Promise.resolve(maybeNeedsResolve);
867
- }));
868
- // Only need to wait but don't need the values because tree items are resolved in place.
869
- await allResolved;
870
- }
871
- for (const treeNode of treeNodes) {
872
- if (treeNode && treeNode.command) {
873
- commandMap.set(treeNode.command.id, treeNode.command.arguments || []);
874
- }
875
- }
876
- return commandMap;
877
- }
878
-
879
- private _message: string | undefined;
880
- get message(): string | undefined {
881
- return this._message;
882
- }
883
-
884
- set message(message: string | undefined) {
885
- this._message = message;
886
- this.update();
887
- }
888
-
889
- protected override render(): React.ReactNode {
890
- return React.createElement('div', this.createContainerAttributes(), this.renderSearchInfo(), this.renderTree(this.model));
891
- }
892
-
893
- protected renderSearchInfo(): React.ReactNode {
894
- if (this._message) {
895
- return <div className='theia-TreeViewInfo'>{this._message}</div>;
896
- }
897
- return undefined;
898
- }
899
-
900
- override shouldShowWelcomeView(): boolean {
901
- return (this.model.proxy === undefined || this.model.isTreeEmpty) && this.message === undefined;
902
- }
903
-
904
- protected override handleContextMenuEvent(node: TreeNode | undefined, event: React.MouseEvent<HTMLElement, MouseEvent>): void {
905
- if (SelectableTreeNode.is(node)) {
906
- // Keep the selection for the context menu, if the widget support multi-selection and the right click happens on an already selected node.
907
- if (!this.props.multiSelect || !node.selected) {
908
- const type = !!this.props.multiSelect && this.hasCtrlCmdMask(event) ? TreeSelection.SelectionType.TOGGLE : TreeSelection.SelectionType.DEFAULT;
909
- this.model.addSelection({ node, type });
910
- }
911
- this.focusService.setFocus(node);
912
- const contextMenuPath = this.props.contextMenuPath;
913
- if (contextMenuPath) {
914
- const { x, y } = event.nativeEvent;
915
- const args = this.toContextMenuArgs(node);
916
- const contextKeyService = this.contextKeyService.createOverlay([
917
- ['viewItem', (TreeViewNode.is(node) && node.contextValue) || undefined],
918
- ['view', this.options.id]
919
- ]);
920
- setTimeout(() => this.contextMenuRenderer.render({
921
- menuPath: contextMenuPath,
922
- anchor: { x, y },
923
- args,
924
- contextKeyService
925
- }), 10);
926
- }
927
- }
928
- event.stopPropagation();
929
- event.preventDefault();
930
- }
931
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018-2019 Red Hat, Inc. 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, postConstruct } from '@theia/core/shared/inversify';
18
+ import { TreeViewsExt, TreeViewItemCollapsibleState, TreeViewItem, TreeViewItemReference, ThemeIcon, DataTransferFileDTO } from '../../../common/plugin-api-rpc';
19
+ import { Command } from '../../../common/plugin-api-rpc-model';
20
+ import {
21
+ TreeNode,
22
+ NodeProps,
23
+ SelectableTreeNode,
24
+ ExpandableTreeNode,
25
+ CompositeTreeNode,
26
+ TreeImpl,
27
+ TREE_NODE_SEGMENT_CLASS,
28
+ TREE_NODE_SEGMENT_GROW_CLASS,
29
+ TREE_NODE_TAIL_CLASS,
30
+ TreeModelImpl,
31
+ TreeViewWelcomeWidget,
32
+ TooltipAttributes,
33
+ TreeSelection,
34
+ HoverService,
35
+ ApplicationShell,
36
+ KeybindingRegistry
37
+ } from '@theia/core/lib/browser';
38
+ import { MenuPath, MenuModelRegistry, ActionMenuNode } from '@theia/core/lib/common/menu';
39
+ import * as React from '@theia/core/shared/react';
40
+ import { PluginSharedStyle } from '../plugin-shared-style';
41
+ import { ACTION_ITEM, Widget } from '@theia/core/lib/browser/widgets/widget';
42
+ import { Emitter, Event } from '@theia/core/lib/common/event';
43
+ import { MessageService } from '@theia/core/lib/common/message-service';
44
+ import { View } from '../../../common/plugin-protocol';
45
+ import { URI } from '@theia/core/lib/common/uri';
46
+ import { ContextKeyService } from '@theia/core/lib/browser/context-key-service';
47
+ import { MarkdownString } from '@theia/core/lib/common/markdown-rendering';
48
+ import { LabelParser } from '@theia/core/lib/browser/label-parser';
49
+ import { AccessibilityInformation } from '@theia/plugin';
50
+ import { ColorRegistry } from '@theia/core/lib/browser/color-registry';
51
+ import { DecoratedTreeNode } from '@theia/core/lib/browser/tree/tree-decorator';
52
+ import { WidgetDecoration } from '@theia/core/lib/browser/widget-decoration';
53
+ import { CancellationTokenSource, CancellationToken, Mutable } from '@theia/core/lib/common';
54
+ import { mixin } from '../../../common/types';
55
+ import { Deferred } from '@theia/core/lib/common/promise-util';
56
+ import { DnDFileContentStore } from './dnd-file-content-store';
57
+
58
+ export const TREE_NODE_HYPERLINK = 'theia-TreeNodeHyperlink';
59
+ export const VIEW_ITEM_CONTEXT_MENU: MenuPath = ['view-item-context-menu'];
60
+ export const VIEW_ITEM_INLINE_MENU: MenuPath = ['view-item-context-menu', 'inline'];
61
+
62
+ export interface SelectionEventHandler {
63
+ readonly node: SelectableTreeNode;
64
+ readonly contextSelection: boolean;
65
+ }
66
+
67
+ export interface TreeViewNode extends SelectableTreeNode, DecoratedTreeNode {
68
+ contextValue?: string;
69
+ command?: Command;
70
+ resourceUri?: string;
71
+ themeIcon?: ThemeIcon;
72
+ tooltip?: string | MarkdownString;
73
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
74
+ description?: string | boolean | any;
75
+ accessibilityInformation?: AccessibilityInformation;
76
+ }
77
+ export namespace TreeViewNode {
78
+ export function is(arg: TreeNode | undefined): arg is TreeViewNode {
79
+ return !!arg && SelectableTreeNode.is(arg) && DecoratedTreeNode.is(arg);
80
+ }
81
+ }
82
+
83
+ export class ResolvableTreeViewNode implements TreeViewNode {
84
+ contextValue?: string;
85
+ command?: Command;
86
+ resourceUri?: string;
87
+ themeIcon?: ThemeIcon;
88
+ tooltip?: string | MarkdownString;
89
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
90
+ description?: string | boolean | any;
91
+ accessibilityInformation?: AccessibilityInformation;
92
+ selected: boolean;
93
+ focus?: boolean;
94
+ id: string;
95
+ name?: string;
96
+ icon?: string;
97
+ visible?: boolean;
98
+ parent: Readonly<CompositeTreeNode>;
99
+ previousSibling?: TreeNode;
100
+ nextSibling?: TreeNode;
101
+ busy?: number;
102
+ decorationData: WidgetDecoration.Data;
103
+
104
+ resolve: ((token: CancellationToken) => Promise<void>);
105
+
106
+ private _resolved = false;
107
+ private resolving: Deferred<void> | undefined;
108
+
109
+ constructor(treeViewNode: Partial<TreeViewNode>, resolve: (token: CancellationToken) => Promise<TreeViewItem | undefined>) {
110
+ mixin(this, treeViewNode);
111
+ this.resolve = async (token: CancellationToken) => {
112
+ if (this.resolving) {
113
+ return this.resolving.promise;
114
+ }
115
+ if (!this._resolved) {
116
+ this.resolving = new Deferred();
117
+ const resolvedTreeItem = await resolve(token);
118
+ if (resolvedTreeItem) {
119
+ this.command = this.command ?? resolvedTreeItem.command;
120
+ this.tooltip = this.tooltip ?? resolvedTreeItem.tooltip;
121
+ }
122
+ this.resolving.resolve();
123
+ this.resolving = undefined;
124
+ }
125
+ if (!token.isCancellationRequested) {
126
+ this._resolved = true;
127
+ }
128
+ };
129
+ }
130
+
131
+ reset(): void {
132
+ this._resolved = false;
133
+ this.resolving = undefined;
134
+ this.command = undefined;
135
+ this.tooltip = undefined;
136
+ }
137
+
138
+ get resolved(): boolean {
139
+ return this._resolved;
140
+ }
141
+ }
142
+
143
+ export class ResolvableCompositeTreeViewNode extends ResolvableTreeViewNode implements CompositeTreeViewNode {
144
+ expanded: boolean;
145
+ children: readonly TreeNode[];
146
+ constructor(
147
+ treeViewNode: Pick<CompositeTreeViewNode, 'children' | 'expanded'> & Partial<TreeViewNode>,
148
+ resolve: (token: CancellationToken) => Promise<TreeViewItem | undefined>) {
149
+ super(treeViewNode, resolve);
150
+ this.expanded = treeViewNode.expanded;
151
+ this.children = treeViewNode.children;
152
+ }
153
+ }
154
+
155
+ export interface CompositeTreeViewNode extends TreeViewNode, ExpandableTreeNode, CompositeTreeNode {
156
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
157
+ description?: string | boolean | any;
158
+ }
159
+ export namespace CompositeTreeViewNode {
160
+ export function is(arg: TreeNode | undefined): arg is CompositeTreeViewNode {
161
+ return TreeViewNode.is(arg) && ExpandableTreeNode.is(arg) && CompositeTreeNode.is(arg);
162
+ }
163
+ }
164
+
165
+ @injectable()
166
+ export class TreeViewWidgetOptions {
167
+ id: string;
168
+ manageCheckboxStateManually: boolean | undefined;
169
+ showCollapseAll: boolean | undefined;
170
+ multiSelect: boolean | undefined;
171
+ dragMimeTypes: string[] | undefined;
172
+ dropMimeTypes: string[] | undefined;
173
+ }
174
+
175
+ @injectable()
176
+ export class PluginTree extends TreeImpl {
177
+
178
+ @inject(PluginSharedStyle)
179
+ protected readonly sharedStyle: PluginSharedStyle;
180
+
181
+ @inject(TreeViewWidgetOptions)
182
+ protected readonly options: TreeViewWidgetOptions;
183
+
184
+ @inject(MessageService)
185
+ protected readonly notification: MessageService;
186
+
187
+ protected readonly onDidChangeWelcomeStateEmitter: Emitter<void> = new Emitter<void>();
188
+ readonly onDidChangeWelcomeState = this.onDidChangeWelcomeStateEmitter.event;
189
+
190
+ private _proxy: TreeViewsExt | undefined;
191
+ private _viewInfo: View | undefined;
192
+ private _isEmpty: boolean;
193
+ private _hasTreeItemResolve: Promise<boolean> = Promise.resolve(false);
194
+
195
+ set proxy(proxy: TreeViewsExt | undefined) {
196
+ this._proxy = proxy;
197
+ if (proxy) {
198
+ this._hasTreeItemResolve = proxy.$hasResolveTreeItem(this.options.id);
199
+ } else {
200
+ this._hasTreeItemResolve = Promise.resolve(false);
201
+ }
202
+ }
203
+ get proxy(): TreeViewsExt | undefined {
204
+ return this._proxy;
205
+ }
206
+
207
+ get hasTreeItemResolve(): Promise<boolean> {
208
+ return this._hasTreeItemResolve;
209
+ }
210
+
211
+ set viewInfo(viewInfo: View) {
212
+ this._viewInfo = viewInfo;
213
+ }
214
+
215
+ get isEmpty(): boolean {
216
+ return this._isEmpty;
217
+ }
218
+
219
+ protected override async resolveChildren(parent: CompositeTreeNode): Promise<TreeNode[]> {
220
+ if (!this._proxy) {
221
+ return super.resolveChildren(parent);
222
+ }
223
+ const children = await this.fetchChildren(this._proxy, parent);
224
+ const hasResolve = await this.hasTreeItemResolve;
225
+ return children.map(value => hasResolve ? this.createResolvableTreeNode(value, parent) : this.createTreeNode(value, parent));
226
+ }
227
+
228
+ protected async fetchChildren(proxy: TreeViewsExt, parent: CompositeTreeNode): Promise<TreeViewItem[]> {
229
+ try {
230
+ const children = await proxy.$getChildren(this.options.id, parent.id);
231
+ const oldEmpty = this._isEmpty;
232
+ this._isEmpty = !parent.id && (!children || children.length === 0);
233
+ if (oldEmpty !== this._isEmpty) {
234
+ this.onDidChangeWelcomeStateEmitter.fire();
235
+ }
236
+ return children || [];
237
+ } catch (e) {
238
+ if (e) {
239
+ console.error(`Failed to fetch children for '${this.options.id}'`, e);
240
+ const label = this._viewInfo ? this._viewInfo.name : this.options.id;
241
+ this.notification.error(`${label}: ${e.message}`);
242
+ }
243
+ return [];
244
+ }
245
+ }
246
+
247
+ protected createTreeNode(item: TreeViewItem, parent: CompositeTreeNode): TreeNode {
248
+ const update: Partial<TreeViewNode> = this.createTreeNodeUpdate(item);
249
+ const node = this.getNode(item.id);
250
+ if (item.collapsibleState !== undefined && item.collapsibleState !== TreeViewItemCollapsibleState.None) {
251
+ if (CompositeTreeViewNode.is(node)) {
252
+ return Object.assign(node, update);
253
+ }
254
+ return Object.assign({
255
+ id: item.id,
256
+ parent,
257
+ visible: true,
258
+ selected: false,
259
+ expanded: TreeViewItemCollapsibleState.Expanded === item.collapsibleState,
260
+ children: [],
261
+ command: item.command
262
+ }, update);
263
+ }
264
+ if (TreeViewNode.is(node) && !ExpandableTreeNode.is(node)) {
265
+ return Object.assign(node, update, { command: item.command });
266
+ }
267
+ return Object.assign({
268
+ id: item.id,
269
+ parent,
270
+ visible: true,
271
+ selected: false,
272
+ command: item.command,
273
+ }, update);
274
+ }
275
+
276
+ override markAsChecked(node: Mutable<TreeNode>, checked: boolean): void {
277
+ function findParentsToChange(child: TreeNode, nodes: TreeNode[]): void {
278
+ if ((child.parent?.checkboxInfo !== undefined && child.parent.checkboxInfo.checked !== checked) &&
279
+ (!checked || !child.parent.children.some(candidate => candidate !== child && candidate.checkboxInfo?.checked === false))) {
280
+ nodes.push(child.parent);
281
+ findParentsToChange(child.parent, nodes);
282
+ }
283
+ }
284
+
285
+ function findChildrenToChange(parent: TreeNode, nodes: TreeNode[]): void {
286
+ if (CompositeTreeNode.is(parent)) {
287
+ parent.children.forEach(child => {
288
+ if (child.checkboxInfo !== undefined && child.checkboxInfo.checked !== checked) {
289
+ nodes.push(child);
290
+ }
291
+ findChildrenToChange(child, nodes);
292
+ });
293
+ }
294
+ }
295
+
296
+ const nodesToChange = [node];
297
+ if (!this.options.manageCheckboxStateManually) {
298
+ findParentsToChange(node, nodesToChange);
299
+ findChildrenToChange(node, nodesToChange);
300
+
301
+ }
302
+ nodesToChange.forEach(n => n.checkboxInfo!.checked = checked);
303
+ this.onDidUpdateEmitter.fire(nodesToChange);
304
+ this.proxy?.$checkStateChanged(this.options.id, [{ id: node.id, checked: checked }]);
305
+ }
306
+
307
+ /** Creates a resolvable tree node. If a node already exists, reset it because the underlying TreeViewItem might have been disposed in the backend. */
308
+ protected createResolvableTreeNode(item: TreeViewItem, parent: CompositeTreeNode): TreeNode {
309
+ const update: Partial<TreeViewNode> = this.createTreeNodeUpdate(item);
310
+ const node = this.getNode(item.id);
311
+
312
+ // Node is a composite node that might contain children
313
+ if (item.collapsibleState !== undefined && item.collapsibleState !== TreeViewItemCollapsibleState.None) {
314
+ // Reuse existing composite node and reset it
315
+ if (node instanceof ResolvableCompositeTreeViewNode) {
316
+ node.reset();
317
+ return Object.assign(node, update);
318
+ }
319
+ // Create new composite node
320
+ const compositeNode = Object.assign({
321
+ id: item.id,
322
+ parent,
323
+ visible: true,
324
+ selected: false,
325
+ expanded: TreeViewItemCollapsibleState.Expanded === item.collapsibleState,
326
+ children: [],
327
+ command: item.command
328
+ }, update);
329
+ return new ResolvableCompositeTreeViewNode(compositeNode, async (token: CancellationToken) => this._proxy?.$resolveTreeItem(this.options.id, item.id, token));
330
+ }
331
+
332
+ // Node is a leaf
333
+ // Reuse existing node and reset it.
334
+ if (node instanceof ResolvableTreeViewNode && !ExpandableTreeNode.is(node)) {
335
+ node.reset();
336
+ return Object.assign(node, update);
337
+ }
338
+ const treeNode = Object.assign({
339
+ id: item.id,
340
+ parent,
341
+ visible: true,
342
+ selected: false,
343
+ command: item.command,
344
+ }, update);
345
+ return new ResolvableTreeViewNode(treeNode, async (token: CancellationToken) => this._proxy?.$resolveTreeItem(this.options.id, item.id, token));
346
+ }
347
+
348
+ protected createTreeNodeUpdate(item: TreeViewItem): Partial<TreeViewNode> {
349
+ const decorationData = this.toDecorationData(item);
350
+ const icon = this.toIconClass(item);
351
+ const resourceUri = item.resourceUri && URI.fromComponents(item.resourceUri).toString();
352
+ const themeIcon = item.themeIcon ? item.themeIcon : item.collapsibleState !== TreeViewItemCollapsibleState.None ? { id: 'folder' } : undefined;
353
+ return {
354
+ name: item.label,
355
+ decorationData,
356
+ icon,
357
+ description: item.description,
358
+ themeIcon,
359
+ resourceUri,
360
+ tooltip: item.tooltip,
361
+ contextValue: item.contextValue,
362
+ command: item.command,
363
+ checkboxInfo: item.checkboxInfo,
364
+ accessibilityInformation: item.accessibilityInformation,
365
+ };
366
+ }
367
+
368
+ protected toDecorationData(item: TreeViewItem): WidgetDecoration.Data {
369
+ let decoration: WidgetDecoration.Data = {};
370
+ if (item.highlights) {
371
+ const highlight = {
372
+ ranges: item.highlights.map(h => ({ offset: h[0], length: h[1] - h[0] }))
373
+ };
374
+ decoration = { highlight };
375
+ }
376
+ return decoration;
377
+ }
378
+
379
+ protected toIconClass(item: TreeViewItem): string | undefined {
380
+ if (item.icon) {
381
+ return 'fa ' + item.icon;
382
+ }
383
+ if (item.iconUrl) {
384
+ const reference = this.sharedStyle.toIconClass(item.iconUrl);
385
+ this.toDispose.push(reference);
386
+ return reference.object.iconClass;
387
+ }
388
+ return undefined;
389
+ }
390
+
391
+ }
392
+
393
+ @injectable()
394
+ export class PluginTreeModel extends TreeModelImpl {
395
+
396
+ @inject(PluginTree)
397
+ protected override readonly tree: PluginTree;
398
+
399
+ set proxy(proxy: TreeViewsExt | undefined) {
400
+ this.tree.proxy = proxy;
401
+ }
402
+ get proxy(): TreeViewsExt | undefined {
403
+ return this.tree.proxy;
404
+ }
405
+
406
+ get hasTreeItemResolve(): Promise<boolean> {
407
+ return this.tree.hasTreeItemResolve;
408
+ }
409
+
410
+ set viewInfo(viewInfo: View) {
411
+ this.tree.viewInfo = viewInfo;
412
+ }
413
+
414
+ get isTreeEmpty(): boolean {
415
+ return this.tree.isEmpty;
416
+ }
417
+
418
+ get onDidChangeWelcomeState(): Event<void> {
419
+ return this.tree.onDidChangeWelcomeState;
420
+ }
421
+
422
+ override doOpenNode(node: TreeNode): void {
423
+ super.doOpenNode(node);
424
+ if (node instanceof ResolvableTreeViewNode) {
425
+ node.resolve(CancellationToken.None);
426
+ }
427
+ }
428
+ }
429
+
430
+ @injectable()
431
+ export class TreeViewWidget extends TreeViewWelcomeWidget {
432
+
433
+ protected _contextSelection = false;
434
+
435
+ @inject(ApplicationShell)
436
+ protected readonly applicationShell: ApplicationShell;
437
+
438
+ @inject(MenuModelRegistry)
439
+ protected readonly menus: MenuModelRegistry;
440
+
441
+ @inject(KeybindingRegistry)
442
+ protected readonly keybindings: KeybindingRegistry;
443
+
444
+ @inject(ContextKeyService)
445
+ protected readonly contextKeys: ContextKeyService;
446
+
447
+ @inject(TreeViewWidgetOptions)
448
+ readonly options: TreeViewWidgetOptions;
449
+
450
+ @inject(PluginTreeModel)
451
+ override readonly model: PluginTreeModel;
452
+
453
+ @inject(ContextKeyService)
454
+ protected readonly contextKeyService: ContextKeyService;
455
+
456
+ @inject(HoverService)
457
+ protected readonly hoverService: HoverService;
458
+
459
+ @inject(LabelParser)
460
+ protected readonly labelParser: LabelParser;
461
+
462
+ @inject(ColorRegistry)
463
+ protected readonly colorRegistry: ColorRegistry;
464
+
465
+ @inject(DnDFileContentStore)
466
+ protected readonly dndFileContentStore: DnDFileContentStore;
467
+
468
+ protected treeDragType: string;
469
+ protected readonly expansionTimeouts: Map<string, number> = new Map();
470
+
471
+ @postConstruct()
472
+ protected override init(): void {
473
+ super.init();
474
+ this.id = this.options.id;
475
+ this.addClass('theia-tree-view');
476
+ this.node.style.height = '100%';
477
+ this.model.onDidChangeWelcomeState(this.update, this);
478
+ this.toDispose.push(this.model.onDidChangeWelcomeState(this.update, this));
479
+ this.toDispose.push(this.onDidChangeVisibilityEmitter);
480
+ this.toDispose.push(this.contextKeyService.onDidChange(() => this.update()));
481
+ this.toDispose.push(this.keybindings.onKeybindingsChanged(() => this.update()));
482
+ this.treeDragType = `application/vnd.code.tree.${this.id.toLowerCase()}`;
483
+ }
484
+
485
+ get showCollapseAll(): boolean {
486
+ return this.options.showCollapseAll || false;
487
+ }
488
+
489
+ protected override renderIcon(node: TreeNode, props: NodeProps): React.ReactNode {
490
+ const icon = this.toNodeIcon(node);
491
+ if (icon) {
492
+ let style: React.CSSProperties | undefined;
493
+ if (TreeViewNode.is(node) && node.themeIcon?.color) {
494
+ const color = this.colorRegistry.getCurrentColor(node.themeIcon.color.id);
495
+ if (color) {
496
+ style = { color };
497
+ }
498
+ }
499
+ return <div className={icon + ' theia-tree-view-icon'} style={style}></div>;
500
+ }
501
+ return undefined;
502
+ }
503
+
504
+ protected override renderCaption(node: TreeViewNode, props: NodeProps): React.ReactNode {
505
+ const classes = [TREE_NODE_SEGMENT_CLASS];
506
+ if (!this.hasTrailingSuffixes(node)) {
507
+ classes.push(TREE_NODE_SEGMENT_GROW_CLASS);
508
+ }
509
+ const className = classes.join(' ');
510
+
511
+ let attrs: React.HTMLAttributes<HTMLElement> & Partial<TooltipAttributes> = {
512
+ ...this.decorateCaption(node, {}),
513
+ className,
514
+ id: node.id
515
+ };
516
+
517
+ if (node.accessibilityInformation) {
518
+ attrs = {
519
+ ...attrs,
520
+ 'aria-label': node.accessibilityInformation.label,
521
+ 'role': node.accessibilityInformation.role
522
+ };
523
+ }
524
+
525
+ if (!node.tooltip && node instanceof ResolvableTreeViewNode) {
526
+ let configuredTip = false;
527
+ let source: CancellationTokenSource | undefined;
528
+ attrs = {
529
+ ...attrs,
530
+ onMouseLeave: () => source?.cancel(),
531
+ onMouseEnter: async event => {
532
+ const target = event.currentTarget; // event.currentTarget will be null after awaiting node resolve()
533
+ if (configuredTip) {
534
+ if (MarkdownString.is(node.tooltip)) {
535
+ this.hoverService.requestHover({
536
+ content: node.tooltip,
537
+ target: event.target as HTMLElement,
538
+ position: 'right'
539
+ });
540
+ }
541
+ return;
542
+ }
543
+ if (!node.resolved) {
544
+ source = new CancellationTokenSource();
545
+ const token = source.token;
546
+ await node.resolve(token);
547
+ if (token.isCancellationRequested) {
548
+ return;
549
+ }
550
+ }
551
+ if (MarkdownString.is(node.tooltip)) {
552
+ this.hoverService.requestHover({
553
+ content: node.tooltip,
554
+ target: event.target as HTMLElement,
555
+ position: 'right'
556
+ });
557
+ } else {
558
+ const title = node.tooltip ||
559
+ (node.resourceUri && this.labelProvider.getLongName(new URI(node.resourceUri)))
560
+ || this.toNodeName(node);
561
+ target.title = title;
562
+ }
563
+ configuredTip = true;
564
+ }
565
+ };
566
+ } else if (MarkdownString.is(node.tooltip)) {
567
+ attrs = {
568
+ ...attrs,
569
+ onMouseEnter: event => {
570
+ this.hoverService.requestHover({
571
+ content: node.tooltip!,
572
+ target: event.target as HTMLElement,
573
+ position: 'right'
574
+ });
575
+ }
576
+ };
577
+ } else {
578
+ const title = node.tooltip ||
579
+ (node.resourceUri && this.labelProvider.getLongName(new URI(node.resourceUri)))
580
+ || this.toNodeName(node);
581
+
582
+ attrs = {
583
+ ...attrs,
584
+ title
585
+ };
586
+ }
587
+
588
+ const children: React.ReactNode[] = [];
589
+ const caption = this.toNodeName(node);
590
+ const highlight = this.getDecorationData(node, 'highlight')[0];
591
+ if (highlight) {
592
+ children.push(this.toReactNode(caption, highlight));
593
+ }
594
+ const searchHighlight = this.searchHighlights && this.searchHighlights.get(node.id);
595
+ if (searchHighlight) {
596
+ children.push(...this.toReactNode(caption, searchHighlight));
597
+ } else if (!highlight) {
598
+ children.push(caption);
599
+ }
600
+ const description = this.toNodeDescription(node);
601
+ if (description) {
602
+ children.push(<span className='theia-tree-view-description'>{description}</span>);
603
+ }
604
+ return <div {...attrs}>{...children}</div>;
605
+ }
606
+
607
+ protected override createNodeAttributes(node: TreeViewNode, props: NodeProps): React.Attributes & React.HTMLAttributes<HTMLElement> {
608
+ const attrs = super.createNodeAttributes(node, props);
609
+
610
+ if (this.options.dragMimeTypes) {
611
+ attrs.onDragStart = event => this.handleDragStartEvent(node, event);
612
+ attrs.onDragEnd = event => this.handleDragEnd(node, event);
613
+ attrs.draggable = true;
614
+ }
615
+
616
+ if (this.options.dropMimeTypes) {
617
+ attrs.onDrop = event => this.handleDropEvent(node, event);
618
+ attrs.onDragEnter = event => this.handleDragEnter(node, event);
619
+ attrs.onDragLeave = event => this.handleDragLeave(node, event);
620
+ attrs.onDragOver = event => this.handleDragOver(event);
621
+ }
622
+
623
+ return attrs;
624
+ }
625
+ handleDragLeave(node: TreeViewNode, event: React.DragEvent<HTMLElement>): void {
626
+ const timeout = this.expansionTimeouts.get(node.id);
627
+ if (typeof timeout !== 'undefined') {
628
+ console.debug(`dragleave ${node.id} canceling timeout`);
629
+ clearTimeout(timeout);
630
+ this.expansionTimeouts.delete(node.id);
631
+ }
632
+ }
633
+ handleDragEnter(node: TreeViewNode, event: React.DragEvent<HTMLElement>): void {
634
+ console.debug(`dragenter ${node.id}`);
635
+ if (ExpandableTreeNode.is(node)) {
636
+ console.debug(`dragenter ${node.id} starting timeout`);
637
+ this.expansionTimeouts.set(node.id, window.setTimeout(() => {
638
+ console.debug(`dragenter ${node.id} timeout reached`);
639
+ this.model.expandNode(node);
640
+ }, 500));
641
+ }
642
+ }
643
+
644
+ protected override createContainerAttributes(): React.HTMLAttributes<HTMLElement> {
645
+ const attrs = super.createContainerAttributes();
646
+ if (this.options.dropMimeTypes) {
647
+ attrs.onDrop = event => this.handleDropEvent(undefined, event);
648
+ attrs.onDragOver = event => this.handleDragOver(event);
649
+ }
650
+ return attrs;
651
+ }
652
+
653
+ protected handleDragStartEvent(node: TreeViewNode, event: React.DragEvent<HTMLElement>): void {
654
+ event.dataTransfer!.setData(this.treeDragType, '');
655
+ let selectedNodes: TreeViewNode[] = [];
656
+ if (this.model.selectedNodes.find(selected => TreeNode.equals(selected, node))) {
657
+ selectedNodes = this.model.selectedNodes.filter(TreeViewNode.is);
658
+ } else {
659
+ selectedNodes = [node];
660
+ }
661
+
662
+ this.options.dragMimeTypes!.forEach(type => {
663
+ if (type === 'text/uri-list') {
664
+ ApplicationShell.setDraggedEditorUris(event.dataTransfer, selectedNodes.filter(n => n.resourceUri).map(n => new URI(n.resourceUri)));
665
+ } else {
666
+ event.dataTransfer.setData(type, '');
667
+ }
668
+ });
669
+
670
+ this.model.proxy!.$dragStarted(this.options.id, selectedNodes.map(selected => selected.id), CancellationToken.None).then(maybeUris => {
671
+ if (maybeUris) {
672
+ this.applicationShell.addAdditionalDraggedEditorUris(maybeUris.map(uri => URI.fromComponents(uri)));
673
+ }
674
+ });
675
+ }
676
+
677
+ handleDragEnd(node: TreeViewNode, event: React.DragEvent<HTMLElement>): void {
678
+ this.applicationShell.clearAdditionalDraggedEditorUris();
679
+ this.model.proxy!.$dragEnd(this.id);
680
+ }
681
+
682
+ handleDragOver(event: React.DragEvent<HTMLElement>): void {
683
+ const hasFiles = (items: DataTransferItemList) => {
684
+ for (let i = 0; i < items.length; i++) {
685
+ if (items[i].kind === 'file') {
686
+ return true;
687
+ }
688
+ }
689
+ return false;
690
+ };
691
+
692
+ if (event.dataTransfer) {
693
+ const canDrop = event.dataTransfer.types.some(type => this.options.dropMimeTypes!.includes(type)) ||
694
+ event.dataTransfer.types.includes(this.treeDragType) ||
695
+ this.options.dropMimeTypes!.includes('files') && hasFiles(event.dataTransfer.items);
696
+ if (canDrop) {
697
+ event.preventDefault();
698
+ event.dataTransfer.dropEffect = 'move';
699
+ } else {
700
+ event.dataTransfer.dropEffect = 'none';
701
+ }
702
+ event.stopPropagation();
703
+ }
704
+ }
705
+
706
+ protected handleDropEvent(node: TreeViewNode | undefined, event: React.DragEvent<HTMLElement>): void {
707
+ if (event.dataTransfer) {
708
+ const items: [string, string | DataTransferFileDTO][] = [];
709
+ let files: string[] = [];
710
+ try {
711
+ for (let i = 0; i < event.dataTransfer.items.length; i++) {
712
+ const transferItem = event.dataTransfer.items[i];
713
+ if (transferItem.type !== this.treeDragType) {
714
+ // do not pass the artificial drag data to the extension
715
+ const f = event.dataTransfer.items[i].getAsFile();
716
+ if (f) {
717
+ const fileId = this.dndFileContentStore.addFile(f);
718
+ files.push(fileId);
719
+ const uri = f.path ? {
720
+ scheme: 'file',
721
+ path: f.path,
722
+ authority: '',
723
+ query: '',
724
+ fragment: ''
725
+ } : undefined;
726
+ items.push([transferItem.type, new DataTransferFileDTO(f.name, fileId, uri)]);
727
+ } else {
728
+ const textData = event.dataTransfer.getData(transferItem.type);
729
+ if (textData) {
730
+ items.push([transferItem.type, textData]);
731
+ }
732
+ }
733
+ }
734
+ }
735
+ if (items.length > 0 || event.dataTransfer.types.includes(this.treeDragType)) {
736
+ event.preventDefault();
737
+ event.stopPropagation();
738
+ this.model.proxy?.$drop(this.id, node?.id, items, CancellationToken.None).finally(() => {
739
+ for (const file of files) {
740
+ this.dndFileContentStore.removeFile(file);
741
+ }
742
+ });
743
+ files = [];
744
+ }
745
+ } catch (e) {
746
+ for (const file of files) {
747
+ this.dndFileContentStore.removeFile(file);
748
+ }
749
+ throw e;
750
+ }
751
+ }
752
+ }
753
+
754
+ protected override renderTailDecorations(treeViewNode: TreeViewNode, props: NodeProps): React.ReactNode {
755
+ return this.contextKeys.with({ view: this.id, viewItem: treeViewNode.contextValue }, () => {
756
+ const menu = this.menus.getMenu(VIEW_ITEM_INLINE_MENU);
757
+ const args = this.toContextMenuArgs(treeViewNode);
758
+ const inlineCommands = menu.children.filter((item): item is ActionMenuNode => item instanceof ActionMenuNode);
759
+ const tailDecorations = super.renderTailDecorations(treeViewNode, props);
760
+ return <React.Fragment>
761
+ {inlineCommands.length > 0 && <div className={TREE_NODE_SEGMENT_CLASS + ' flex'}>
762
+ {inlineCommands.map((item, index) => this.renderInlineCommand(item, index, this.focusService.hasFocus(treeViewNode), args))}
763
+ </div>}
764
+ {tailDecorations !== undefined && <div className={TREE_NODE_SEGMENT_CLASS + ' flex'}>{tailDecorations}</div>}
765
+ </React.Fragment>;
766
+ });
767
+ }
768
+
769
+ toTreeViewItemReference(treeNode: TreeNode): TreeViewItemReference {
770
+ return { viewId: this.id, itemId: treeNode.id };
771
+ }
772
+
773
+ protected resolveKeybindingForCommand(command: string | undefined): string {
774
+ let result = '';
775
+ if (command) {
776
+ const bindings = this.keybindings.getKeybindingsForCommand(command);
777
+ let found = false;
778
+ if (bindings && bindings.length > 0) {
779
+ bindings.forEach(binding => {
780
+ if (!found && this.keybindings.isEnabledInScope(binding, this.node)) {
781
+ found = true;
782
+ result = ` (${this.keybindings.acceleratorFor(binding, '+')})`;
783
+ }
784
+ });
785
+ }
786
+ }
787
+ return result;
788
+ }
789
+
790
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
791
+ protected renderInlineCommand(actionMenuNode: ActionMenuNode, index: number, tabbable: boolean, args: any[]): React.ReactNode {
792
+ if (!actionMenuNode.icon || !this.commands.isVisible(actionMenuNode.command, ...args) || !actionMenuNode.when || !this.contextKeys.match(actionMenuNode.when)) {
793
+ return false;
794
+ }
795
+ const className = [TREE_NODE_SEGMENT_CLASS, TREE_NODE_TAIL_CLASS, actionMenuNode.icon, ACTION_ITEM, 'theia-tree-view-inline-action'].join(' ');
796
+ const tabIndex = tabbable ? 0 : undefined;
797
+ const titleString = actionMenuNode.label + this.resolveKeybindingForCommand(actionMenuNode.command);
798
+
799
+ return <div key={index} className={className} title={titleString} tabIndex={tabIndex} onClick={e => {
800
+ e.stopPropagation();
801
+ this.commands.executeCommand(actionMenuNode.command, ...args);
802
+ }} />;
803
+ }
804
+
805
+ protected override toContextMenuArgs(target: SelectableTreeNode): [TreeViewItemReference, TreeViewItemReference[]] | [TreeViewItemReference] {
806
+ if (this.options.multiSelect) {
807
+ return [this.toTreeViewItemReference(target), this.model.selectedNodes.map(node => this.toTreeViewItemReference(node))];
808
+ } else {
809
+ return [this.toTreeViewItemReference(target)];
810
+ }
811
+ }
812
+
813
+ override setFlag(flag: Widget.Flag): void {
814
+ super.setFlag(flag);
815
+ if (flag === Widget.Flag.IsVisible) {
816
+ this.onDidChangeVisibilityEmitter.fire(this.isVisible);
817
+ }
818
+ }
819
+
820
+ override clearFlag(flag: Widget.Flag): void {
821
+ super.clearFlag(flag);
822
+ if (flag === Widget.Flag.IsVisible) {
823
+ this.onDidChangeVisibilityEmitter.fire(this.isVisible);
824
+ }
825
+ }
826
+
827
+ override handleEnter(event: KeyboardEvent): void {
828
+ super.handleEnter(event);
829
+ this.tryExecuteCommand();
830
+ }
831
+
832
+ protected override tapNode(node?: TreeNode): void {
833
+ super.tapNode(node);
834
+ this.findCommands(node).then(commandMap => {
835
+ if (commandMap.size > 0) {
836
+ this.tryExecuteCommandMap(commandMap);
837
+ } else if (node && this.isExpandable(node)) {
838
+ this.model.toggleNodeExpansion(node);
839
+ }
840
+ });
841
+ }
842
+
843
+ // execute TreeItem.command if present
844
+ protected async tryExecuteCommand(node?: TreeNode): Promise<void> {
845
+ this.tryExecuteCommandMap(await this.findCommands(node));
846
+ }
847
+
848
+ protected tryExecuteCommandMap(commandMap: Map<string, unknown[]>): void {
849
+ commandMap.forEach((args, commandId) => {
850
+ this.commands.executeCommand(commandId, ...args);
851
+ });
852
+ }
853
+
854
+ protected async findCommands(node?: TreeNode): Promise<Map<string, unknown[]>> {
855
+ const commandMap = new Map<string, unknown[]>();
856
+ const treeNodes = (node ? [node] : this.model.selectedNodes) as TreeViewNode[];
857
+ if (await this.model.hasTreeItemResolve) {
858
+ const cancellationToken = new CancellationTokenSource().token;
859
+ // Resolve all resolvable nodes that don't have a command and haven't been resolved.
860
+ const allResolved = Promise.all(treeNodes.map(maybeNeedsResolve => {
861
+ if (!maybeNeedsResolve.command && maybeNeedsResolve instanceof ResolvableTreeViewNode && !maybeNeedsResolve.resolved) {
862
+ return maybeNeedsResolve.resolve(cancellationToken).catch(err => {
863
+ console.error(`Failed to resolve tree item '${maybeNeedsResolve.id}'`, err);
864
+ });
865
+ }
866
+ return Promise.resolve(maybeNeedsResolve);
867
+ }));
868
+ // Only need to wait but don't need the values because tree items are resolved in place.
869
+ await allResolved;
870
+ }
871
+ for (const treeNode of treeNodes) {
872
+ if (treeNode && treeNode.command) {
873
+ commandMap.set(treeNode.command.id, treeNode.command.arguments || []);
874
+ }
875
+ }
876
+ return commandMap;
877
+ }
878
+
879
+ private _message: string | undefined;
880
+ get message(): string | undefined {
881
+ return this._message;
882
+ }
883
+
884
+ set message(message: string | undefined) {
885
+ this._message = message;
886
+ this.update();
887
+ }
888
+
889
+ protected override render(): React.ReactNode {
890
+ return React.createElement('div', this.createContainerAttributes(), this.renderSearchInfo(), this.renderTree(this.model));
891
+ }
892
+
893
+ protected renderSearchInfo(): React.ReactNode {
894
+ if (this._message) {
895
+ return <div className='theia-TreeViewInfo'>{this._message}</div>;
896
+ }
897
+ return undefined;
898
+ }
899
+
900
+ override shouldShowWelcomeView(): boolean {
901
+ return (this.model.proxy === undefined || this.model.isTreeEmpty) && this.message === undefined;
902
+ }
903
+
904
+ protected override handleContextMenuEvent(node: TreeNode | undefined, event: React.MouseEvent<HTMLElement, MouseEvent>): void {
905
+ if (SelectableTreeNode.is(node)) {
906
+ // Keep the selection for the context menu, if the widget support multi-selection and the right click happens on an already selected node.
907
+ if (!this.props.multiSelect || !node.selected) {
908
+ const type = !!this.props.multiSelect && this.hasCtrlCmdMask(event) ? TreeSelection.SelectionType.TOGGLE : TreeSelection.SelectionType.DEFAULT;
909
+ this.model.addSelection({ node, type });
910
+ }
911
+ this.focusService.setFocus(node);
912
+ const contextMenuPath = this.props.contextMenuPath;
913
+ if (contextMenuPath) {
914
+ const { x, y } = event.nativeEvent;
915
+ const args = this.toContextMenuArgs(node);
916
+ const contextKeyService = this.contextKeyService.createOverlay([
917
+ ['viewItem', (TreeViewNode.is(node) && node.contextValue) || undefined],
918
+ ['view', this.options.id]
919
+ ]);
920
+ setTimeout(() => this.contextMenuRenderer.render({
921
+ menuPath: contextMenuPath,
922
+ anchor: { x, y },
923
+ args,
924
+ contextKeyService
925
+ }), 10);
926
+ }
927
+ }
928
+ event.stopPropagation();
929
+ event.preventDefault();
930
+ }
931
+ }