可以拖动&在自定义VS代码树视图之间下降?

发布于 2025-01-24 20:46:18 字数 670 浏览 3 评论 0 原文

1.66(2022年3月)版本引入A

但是,在对象说:

拖动降落控制器{@link treedraganddropcontroller.handledrag handledrag }可以将其他MIME类型添加到数据传输中。这些附加的MIME类型仅在 handledRop 中包括在同一拖放控制器中的元素时。

这是否意味着您无法拖动&在自定义树视图之间放置,因为它们通常具有自定义拖动&每个视图下降控制器?或者您打算重新使用阻力&树视图之间的下降控制器,以启用拖动&在视图之间落下?

我尝试了各种组合,并且无法成功获得完整的阻力&在两个树视图之间掉落。在某些情况下,我确实看到了控制台上的错误,但仅此而已。

The 1.66 (March 2022) release introduces a TreeDragAndDropController API which allows for handling drag & drop events for custom tree views.

However in the docs for the DataTransfer object is says:

Drag and drop controllers that implement {@link TreeDragAndDropController.handleDrag handleDrag} can add additional mime types to the data transfer. These additional mime types will only be included in the handleDrop when the the drag was initiated from an element in the same drag and drop controller.

Does this mean that you cannot drag & drop between custom tree views as they would typically have a custom drag & drop controller per view? Or that you're meant to re-use a drag & drop controller between tree views in order to enable dragging & dropping between views?

I have tried various combinations and been unsuccessful in getting a full drag & drop between two tree views. I do see an error in the console on drop in some situations but that is about it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独守阴晴ぅ圆缺 2025-01-31 20:46:19

我花了一段时间才弄清楚如何获得Drag&在两个不同的树视图之间工作。对我来说,问题是:

  • 误解 dragmimetypes < / code>的误解 /用法。
  • 误解 treedatatransfer.set()< / code>的目的 /用法。
  • 使用不正确的MIME类型的命名约定。

这可能是通过示例最好描述的。
让我们假设我们只会从 treeview_a 拖动,我们只能落到 treeview_b 上。

对于 treeview_a

  • dropmimetypes 可以是一个空数组,因为我们不希望收到任何滴滴​​。
  • 我们真的不需要andledRop()方法,我们再次不希望收到任何掉落。
  • dragmimetypes 需要包括我们要落到的树景的MIME类型(即 treeview_b )。这里有一个警告,此必须 application/vnd.code.tree。因此,在此示例中,它将读取类似的内容:
dragMimeTypes = ['application/vnd.code.tree.treeView_b'];
  • wandledrag()方法需要使用目标树视图的MIME类型( treeview_b )设置,(请记住lowerCase!)
    public async handleDrag(source: TreeItem[], treeDataTransfer: vscode.DataTransfer, token: vscode.CancellationToken): Promise<void> {
        treeDataTransfer.set('application/vnd.code.tree.treeView_b', new vscode.DataTransferItem(source));
    }

如果您在基础代码中阅读评论,那么小写的要求似乎更像是一个建议……但是根据我的经验,这似乎更像是一项要求。我有很多好久了!

对于 treeview_b

  • dragmimetypes 可以是一个空数组,因为我们不会从这里拖动任何东西。
  • 同样,我们实际上也不需要 handledrag()方法。
  • dropmimetypes 需要包括我们要落到(即treeview, treeview_b )的树景的MIME
dropMimeTypes = ['application/vnd.code.tree.treeView_b'];
  • 类型方法需要获取正确的MIME类型(您猜对了,小写中的 treeview_b )。在这种方法中,我只是登录到主机。
    public async handleDrop(target: TreeItem | undefined, sources: vscode.DataTransfer): Promise<void> {
        const transferItemAppContent = sources.get('application/vnd.code.tree.treeView_b');
        if (transferItemAppContent) {
            console.log(JSON.stringify(transferItemAppContent));
            return;
        }
    }

我仍然不确定我已经100%了解应该如何实现这一点,但是我可以告诉您上述方法有效。希望它有帮助。

It took me a while to figure out how to get drag & drop to work between two different treeviews. For me, the problem was a combination of:

  • Misunderstanding the purpose / usage of dragMimeTypes.
  • Misunderstanding the purpose / usage of treeDataTransfer.set().
  • Using an incorrect naming convention for mime types.

This is probably best described by way of example.
Let's assume we're only going to drag from TreeView_A and we'll only drop onto TreeView_B.

For TreeView_A

  • dropMimeTypes can be an empty array as we're not expecting to receive any drops.
  • We don't really need a handleDrop() method, again we're not expecting to receive any drops.
  • dragMimeTypes needs to include the mime type of the treeview that we're going to drop onto (i.e. TreeView_B). A word of warning here, this MUST be in the format application/vnd.code.tree.<treeidlowercase>. So, for this example it would read something like this:
dragMimeTypes = ['application/vnd.code.tree.treeView_b'];
  • handleDrag() method needs to set using a mime type of the target treeview (Treeview_B), (remember lowercase!)
    public async handleDrag(source: TreeItem[], treeDataTransfer: vscode.DataTransfer, token: vscode.CancellationToken): Promise<void> {
        treeDataTransfer.set('application/vnd.code.tree.treeView_b', new vscode.DataTransferItem(source));
    }

The lowercase requirement seems more like a suggestion if you read the comments in the underlying code... but no from my experience it seems more like a requirement. Had me stumped for ages!

For TreeView_B

  • dragMimeTypes can be an empty array as we won't be dragging anything from here.
  • similarly, we don't really need a handleDrag() method.
  • dropMimeTypes needs to include the mime type of the treeview that we're going to drop onto (i.e. this treeview, TreeView_B)
dropMimeTypes = ['application/vnd.code.tree.treeView_b'];
  • the handleDrop() method needs to get the correct mime type (you guessed it, Treeview_B in lowercase). In this method, I just log to console.
    public async handleDrop(target: TreeItem | undefined, sources: vscode.DataTransfer): Promise<void> {
        const transferItemAppContent = sources.get('application/vnd.code.tree.treeView_b');
        if (transferItemAppContent) {
            console.log(JSON.stringify(transferItemAppContent));
            return;
        }
    }

I'm still not sure that I've 100% understood how this is supposed to be implemented, but I can tell you that the above method works. Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文