'Adding drag and drop support in a custom TreeView
I have successfully populated a TreeView
via creating a TreeDataProvider
and customized the icons and its collapse-able property. Now I want to be able to drag and drop its ViewItem
(s) onto a WebView. There are unfortunately no samples for drag and drop. Reading through the TreeView
source, ViewItem
(s) are created in HeightMap.OnInsertItems()
via the TreeView.createViewItem()
, from the derived class.
The public TreeView.onInsertItem()
would appear to be a great extension point, extending TreeView
and onInsertItem()
and capturing its ViewItem
parameter. This Unfortunately, the creation of the concrete class, ExtHostTreeView
, that is ultimately created, is buried in layers of private methods (createExtHostTreeViewer()
).
Strangely, the ViewItem
has a setter for draggable. However, how would you ever get a reference to the ViewItem
to set it? If there is a way to do this please point me at an example. If there is not, I would be glad to fork and implement it. Leaving the existing onInsertItem
and perhaps add an array of handlers to be added to with an addOnInsertItemListener()
method? Or perhaps use RxJS?
There are so many places this could be used. You could drag template fragments into documents or code, DSL rules into a expert system, configuration file values into parameters or right hand values (generating the code to retrieve the value). Thank you for any assistance.
Solution 1:[1]
It seems that drag and drop in custom views is currently not supported. There's a (fairly popular) feature request for it here:
Solution 2:[2]
As of version 1.66 (March 2022) there is a TreeDragAndDropController which can be used for some drag & drop actions.
In April 2022, their sample focuses on drag & drop within a tree view: https://github.com/microsoft/vscode-extension-samples/blob/main/tree-view-sample/src/testViewDragAndDrop.ts
It is also possible to use the text/url-list
type as described in the documentation to allow for dragging files to the editor panel: https://github.com/microsoft/vscode/blob/dc2f5d8dd1790ac4fc6054e11b44e36884caa4be/src/vscode-dts/vscode.d.ts#L9843-L9859
It is not clear to me yet whether it is possible to drag arbitrary data to webviews or to use standard HTML5 drag & drop API in a webview to allow dragging data to a custom tree view.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Gama11 |
Solution 2 |