From 598e91167868cf92dd2c79693b62311eb9f6f023 Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Fri, 3 Dec 2021 14:18:23 +0100 Subject: [PATCH] Fix tree view sample to run on older versions of VS Code Fixes https://github.com/microsoft/vscode-extension-samples/issues/531 --- tree-view-sample/src/extension.ts | 7 +++++-- tree-view-sample/src/testViewDragAndDrop.ts | 12 +++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/tree-view-sample/src/extension.ts b/tree-view-sample/src/extension.ts index 83350e6f..55a51c75 100644 --- a/tree-view-sample/src/extension.ts +++ b/tree-view-sample/src/extension.ts @@ -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); + } } \ No newline at end of file diff --git a/tree-view-sample/src/testViewDragAndDrop.ts b/tree-view-sample/src/testViewDragAndDrop.ts index 682470c4..e83e25cf 100644 --- a/tree-view-sample/src/testViewDragAndDrop.ts +++ b/tree-view-sample/src/testViewDragAndDrop.ts @@ -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 { + return 'mock'; + } + + constructor(_value: any) { /* this is a mock constructor */ } +}; + + +class TestViewObjectTransferItem extends TestTreeDataTransferItem { constructor(private _nodes: Node[]) { super(_nodes); }