Skip to content

Commit 6ff75f1

Browse files
committed
Add comments to tree dnd proposal
Part of #32592
1 parent daabfff commit 6ff75f1

File tree

1 file changed

+50
-7
lines changed

1 file changed

+50
-7
lines changed

src/vscode-dts/vscode.proposed.treeViewDragAndDrop.d.ts

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,85 @@ declare module 'vscode' {
2626
dragAndDropController?: DragAndDropController<T>;
2727
}
2828

29+
/**
30+
* A class for encapsulating data transferred during a tree drag and drop event.
31+
*
32+
* If your `DragAndDropController` implements `onWillDrop`, you can extend `TreeDataTransferItem` and return
33+
* an instance of your new class for easy access to the source tree items.
34+
*
35+
* ```ts
36+
* class TestViewObjectTransferItem extends vscode.TreeDataTransferItem {
37+
* constructor(private _nodes: Node[]) {
38+
* super(_nodes);
39+
* }
40+
*
41+
* asObject(): Node[] {
42+
* return this._nodes;
43+
* }
44+
* }
45+
* ```
46+
*/
2947
export class TreeDataTransferItem {
3048
asString(): Thenable<string>;
3149

3250
constructor(value: any);
3351
}
3452

53+
/**
54+
* A map containing a mapping of the mime type of the corresponding transferred data.
55+
* Trees that support drag and drop can implement `DragAndDropController.onWillDrop` to add additional mime types
56+
* when the drop occurs on an item in the same tree.
57+
*/
3558
export class TreeDataTransfer<T extends TreeDataTransferItem = TreeDataTransferItem> {
3659
/**
37-
* A map containing a mapping of the mime type of the corresponding data.
38-
* Trees that support drag and drop can implement `DragAndDropController.onWillDrop` to add additional mime types
39-
* when the drop occurs on an item in the same tree.
60+
* Retrieves the data transfer item for a given mime type.
61+
* @param mimeType The mime type to get the data transfer item for.
4062
*/
4163
get(mimeType: string): T | undefined;
64+
65+
/**
66+
* Sets a mime type to data transfer item mapping.
67+
* @param mimeType The mime type to set the data for.
68+
* @param value The data transfer item for the given mime type.
69+
*/
4270
set(mimeType: string, value: T): void;
71+
72+
/**
73+
* Allows iteration through the data transfer items.
74+
* @param callbackfn Callback for iteration through the data transfer items.
75+
*/
4376
forEach(callbackfn: (value: T, key: string) => void): void;
4477
}
4578

79+
/**
80+
* Provides support for drag and drop in `TreeView`.
81+
*/
4682
export interface DragAndDropController<T> extends Disposable {
83+
84+
/**
85+
* The mime types that this `DragAndDropController` supports. This could be well-defined, existing, mime types,
86+
* and also mime types defined by the extension that are returned in the `TreeDataTransfer` from `onWillDrop`.
87+
*/
4788
readonly supportedMimeTypes: string[];
4889

4990
/**
5091
* When the user drops an item from this DragAndDropController on **another tree item** in **the same tree**,
51-
* `onWillDrop` will be called with the dropped tree item. This is the DragAndDropController's opportunity to
92+
* `onWillDrop` will be called with the dropped tree items. This is the DragAndDropController's opportunity to
5293
* package the data from the dropped tree item into whatever format they want the target tree item to receive.
5394
*
5495
* The returned `TreeDataTransfer` will be merged with the original`TreeDataTransfer` for the operation.
5596
*
56-
* @param source
97+
* @param source The source items for the drag and drop operation.
5798
*/
5899
onWillDrop(source: T[]): Thenable<TreeDataTransfer>;
59100

60101
/**
102+
* Called when a drag and drop action results in a drop on the tree that this `DragAndDropController` belongs too.
103+
*
61104
* Extensions should fire `TreeDataProvider.onDidChangeTreeData` for any elements that need to be refreshed.
62105
*
63-
* @param source
64-
* @param target
106+
* @param source The data transfer items of the source of the drag.
107+
* @param target The target tree element that the drop is occuring on.
65108
*/
66109
onDrop(source: TreeDataTransfer, target: T): Thenable<void>;
67110
}

0 commit comments

Comments
 (0)