From 9be22a47092e7e62e6cfc38e0b52e483b18f580d Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Mon, 7 Mar 2022 12:37:11 +0100 Subject: [PATCH] Update tree dnd sample (#567) --- tree-view-sample/src/extension.ts | 2 +- tree-view-sample/src/testViewDragAndDrop.ts | 10 +++--- .../vscode.proposed.treeViewDragAndDrop.d.ts | 31 ++++++------------- 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/tree-view-sample/src/extension.ts b/tree-view-sample/src/extension.ts index 55a51c75..d33e96b8 100644 --- a/tree-view-sample/src/extension.ts +++ b/tree-view-sample/src/extension.ts @@ -38,7 +38,7 @@ export function activate(context: vscode.ExtensionContext) { // Drag and Drop proposed API sample // This check is for older versions of VS Code that don't have the most up-to-date tree drag and drop API proposal. - if (typeof vscode.TreeDataTransferItem === 'function') { + if (typeof vscode.DataTransferItem === 'function') { new TestViewDragAndDrop(context); } } \ No newline at end of file diff --git a/tree-view-sample/src/testViewDragAndDrop.ts b/tree-view-sample/src/testViewDragAndDrop.ts index d85239f4..e9b80b07 100644 --- a/tree-view-sample/src/testViewDragAndDrop.ts +++ b/tree-view-sample/src/testViewDragAndDrop.ts @@ -6,8 +6,8 @@ export class TestViewDragAndDrop implements vscode.TreeDataProvider, vscod dropMimeTypes = ['application/vnd.code.tree.testViewDragAndDrop']; dragMimeTypes = ['text/uri-list']; private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); - // We want to use an array as the event type, so we use the proposed onDidChangeTreeData2. - public onDidChangeTreeData2: vscode.Event = this._onDidChangeTreeData.event; + // We want to use an array as the event type, but the API for this is currently being finalized. Until it's finalized, use any. + public onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; public tree = { 'a': { 'aa': { @@ -57,7 +57,7 @@ export class TestViewDragAndDrop implements vscode.TreeDataProvider, vscod // Drag and drop controller - public async handleDrop(target: Node, sources: vscode.TreeDataTransfer, token: vscode.CancellationToken): Promise { + public async handleDrop(target: Node, sources: vscode.DataTransfer, token: vscode.CancellationToken): Promise { const transferItem = sources.get('application/vnd.code.tree.testViewDragAndDrop'); if (!transferItem) { return; @@ -74,8 +74,8 @@ export class TestViewDragAndDrop implements vscode.TreeDataProvider, vscod } } - public async handleDrag(source: Node[], treeDataTransfer: vscode.TreeDataTransfer, token: vscode.CancellationToken): Promise { - treeDataTransfer.set('application/vnd.code.tree.testViewDragAndDrop', new vscode.TreeDataTransferItem(source)); + public async handleDrag(source: Node[], treeDataTransfer: vscode.DataTransfer, token: vscode.CancellationToken): Promise { + treeDataTransfer.set('application/vnd.code.tree.testViewDragAndDrop', new vscode.DataTransferItem(source)); } // Helper methods diff --git a/tree-view-sample/vscode.proposed.treeViewDragAndDrop.d.ts b/tree-view-sample/vscode.proposed.treeViewDragAndDrop.d.ts index cf7e6850..7efcdcb3 100644 --- a/tree-view-sample/vscode.proposed.treeViewDragAndDrop.d.ts +++ b/tree-view-sample/vscode.proposed.treeViewDragAndDrop.d.ts @@ -7,17 +7,6 @@ declare module 'vscode' { // https://github.com/microsoft/vscode/issues/32592 - /** - * A data provider that provides tree data - */ - export interface TreeDataProvider { - /** - * An optional event to signal that an element or root has changed. - * This will trigger the view to update the changed element/root and its children recursively (if shown). - * To signal that root has changed, do not pass any argument or pass `undefined` or `null`. - */ - onDidChangeTreeData2?: Event; - } export interface TreeViewOptions { /** @@ -27,13 +16,12 @@ declare module 'vscode' { } /** - * A class for encapsulating data transferred during a tree drag and drop event. + * A class for encapsulating data transferred during a drag and drop event. * - * If your `DragAndDropController` implements `handleDrag`, you can use the `value` of the `TreeDataTransferItem` - * to get back the object you put into it so long as the extension that created the `TreeDataTransferItem` runs in the same - * extension host. + * You can use the `value` of the `DataTransferItem` to get back the object you put into it + * so long as the extension that created the `DataTransferItem` runs in the same extension host. */ - export class TreeDataTransferItem { + export class DataTransferItem { asString(): Thenable; readonly value: any; constructor(value: any); @@ -41,10 +29,11 @@ declare module 'vscode' { /** * A map containing a mapping of the mime type of the corresponding transferred data. - * Trees that support drag and drop can implement `DragAndDropController.handleDrag` to add additional mime types - * when the drop occurs on an item in the same tree. + * Drag and drop controllers that implement `handleDrag` can 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. */ - export class TreeDataTransfer { + export class DataTransfer { /** * Retrieves the data transfer item for a given mime type. * @param mimeType The mime type to get the data transfer item for. @@ -105,7 +94,7 @@ declare module 'vscode' { * @param treeDataTransfer The data transfer associated with this drag. * @param token A cancellation token indicating that drag has been cancelled. */ - handleDrag?(source: T[], treeDataTransfer: TreeDataTransfer, token: CancellationToken): Thenable | void; + handleDrag?(source: T[], treeDataTransfer: DataTransfer, token: CancellationToken): Thenable | void; /** * Called when a drag and drop action results in a drop on the tree that this `DragAndDropController` belongs too. @@ -116,6 +105,6 @@ declare module 'vscode' { * @param target The target tree element that the drop is occurring on. * @param token A cancellation token indicating that the drop has been cancelled. */ - handleDrop(target: T, source: TreeDataTransfer, token: CancellationToken): Thenable | void; + handleDrop?(target: T, source: DataTransfer, token: CancellationToken): Thenable | void; } }