Fix tree view sample to run on older versions of VS Code

Fixes https://github.com/microsoft/vscode-extension-samples/issues/531
This commit is contained in:
Alex Ross
2021-12-03 14:18:23 +01:00
parent 71b2eb133a
commit 598e911678
2 changed files with 16 additions and 3 deletions

View File

@ -36,6 +36,9 @@ export function activate(context: vscode.ExtensionContext) {
// Test View
new TestView(context);
// Drag and Drop sample
new TestViewDragAndDrop(context);
// 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') {
new TestViewDragAndDrop(context);
}
}

View File

@ -1,6 +1,16 @@
import * as vscode from 'vscode';
class TestViewObjectTransferItem extends vscode.TreeDataTransferItem {
// TestTreeDataTransferItem is for older versions of VS Code that don't have the most up-to-date tree drag and drop API proposal.
const TestTreeDataTransferItem = (typeof vscode.TreeDataTransferItem === 'function') ? vscode.TreeDataTransferItem : class MockItem {
async asString(): Promise<string> {
return 'mock';
}
constructor(_value: any) { /* this is a mock constructor */ }
};
class TestViewObjectTransferItem extends TestTreeDataTransferItem {
constructor(private _nodes: Node[]) {
super(_nodes);
}