mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-06-13 07:10:26 +08:00
Update tree view sample to use onWillDrop
This commit is contained in:
@ -55,7 +55,11 @@ export class TestViewDragAndDrop implements vscode.TreeDataProvider<Node>, vscod
|
||||
// Drag and drop controller
|
||||
|
||||
public async onDrop(sources: vscode.TreeDataTransfer, target: Node): Promise<void> {
|
||||
const treeItems = JSON.parse(await sources.items.get('text/treeitems')!.asString());
|
||||
const transferItem = sources.items.get('text/treeitems');
|
||||
if (!transferItem) {
|
||||
return;
|
||||
}
|
||||
const treeItems = JSON.parse(await transferItem.asString());
|
||||
let roots = this._getLocalRoots(treeItems);
|
||||
// Remove nodes that are already target's parent nodes
|
||||
roots = roots.filter(r => !this._isChild(this._getTreeElement(r.key), target));
|
||||
@ -67,6 +71,14 @@ export class TestViewDragAndDrop implements vscode.TreeDataProvider<Node>, vscod
|
||||
}
|
||||
}
|
||||
|
||||
public async onWillDrop(source: Node[]): Promise<vscode.TreeDataTransfer> {
|
||||
const items = new Map<string, vscode.TreeDataTransferItem>();
|
||||
items.set('text/treeitems', {asString: async () => JSON.stringify(source)});
|
||||
return {
|
||||
items
|
||||
};
|
||||
}
|
||||
|
||||
// Helper methods
|
||||
|
||||
_isChild(node: Node, child: Node): boolean {
|
||||
|
||||
Reference in New Issue
Block a user