Add value to TreeDataTransferItem dnd API

This commit is contained in:
Alex Ross
2022-02-02 15:02:27 +01:00
parent 2c3d342cf7
commit 972ef3c8f0
5 changed files with 11 additions and 19 deletions
+2 -2
View File
@@ -2315,10 +2315,10 @@ export enum TreeItemCollapsibleState {
@es5ClassCompat
export class TreeDataTransferItem {
async asString(): Promise<string> {
return JSON.stringify(this._value);
return JSON.stringify(this.value);
}
constructor(private readonly _value: any) { }
constructor(public readonly value: any) { }
}
@es5ClassCompat
@@ -19,7 +19,8 @@ export namespace TreeDataTransferConverter {
const newDataTransfer: ITreeDataTransfer = new Map<string, ITreeDataTransferItem>();
value.types.forEach((type, index) => {
newDataTransfer.set(type, {
asString: async () => value.items[index].asString
asString: async () => value.items[index].asString,
value: undefined
});
});
return newDataTransfer;
@@ -1382,7 +1382,8 @@ export class CustomTreeViewDragAndDrop implements ITreeDragAndDrop<ITreeItem> {
willDropUuid = dataValue;
} else {
treeDataTransfer.set(type, {
asString: () => Promise.resolve(dataValue)
asString: () => Promise.resolve(dataValue),
value: undefined
});
}
decrementStringCount();
+1
View File
@@ -637,6 +637,7 @@ export interface IViewDescriptorService {
export interface ITreeDataTransferItem {
asString(): Thenable<string>;
value: any;
}
export type ITreeDataTransfer = Map<string, ITreeDataTransferItem>;
+4 -15
View File
@@ -29,24 +29,13 @@ declare module 'vscode' {
/**
* A class for encapsulating data transferred during a tree drag and drop event.
*
* If your `DragAndDropController` implements `handleDrag`, you can extend `TreeDataTransferItem` and return
* an instance of your new class for easy access to the source tree items.
*
* ```ts
* class TestViewObjectTransferItem extends vscode.TreeDataTransferItem {
* constructor(private _nodes: Node[]) {
* super(_nodes);
* }
*
* asObject(): Node[] {
* return this._nodes;
* }
* }
* ```
* 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.
*/
export class TreeDataTransferItem {
asString(): Thenable<string>;
readonly value: any;
constructor(value: any);
}