Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DnD of files from OS Explorer into Tree Views #12409

Merged
merged 2 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ export class DataTransferFileDTO {

export interface TreeViewsExt {
$dragStarted(treeViewId: string, treeItemIds: string[], token: CancellationToken): Promise<UriComponents[] | undefined>;
$dragEnd(treeViewId: string): Promise<void>;
$drop(treeViewId: string, treeItemId: string | undefined, dataTransferItems: [string, string | DataTransferFileDTO][], token: CancellationToken): Promise<void>;
$getChildren(treeViewId: string, treeItemId: string | undefined): Promise<TreeViewItem[] | undefined>;
$hasResolveTreeItem(treeViewId: string): Promise<boolean>;
Expand Down
12 changes: 11 additions & 1 deletion packages/plugin-ext/src/main/browser/view/tree-view-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -632,13 +632,23 @@ export class TreeViewWidget extends TreeViewWelcomeWidget {

handleDragEnd(node: TreeViewNode, event: React.DragEvent<HTMLElement>): void {
this.applicationShell.clearAdditionalDraggedEditorUris();
this.model.proxy!.$dragEnd(this.id);
}

handleDragOver(event: React.DragEvent<HTMLElement>): void {
const hasFiles = (items: DataTransferItemList) => {
for (let i = 0; i < items.length; i++) {
if (items[i].kind === 'file') {
return true;
}
}
return false;
};

if (event.dataTransfer) {
const canDrop = event.dataTransfer.types.some(type => this.options.dropMimeTypes!.includes(type)) ||
event.dataTransfer.types.includes(this.treeDragType) ||
this.options.dropMimeTypes!.includes('files') && event.dataTransfer.files.length > 0;
this.options.dropMimeTypes!.includes('files') && hasFiles(event.dataTransfer.items);
if (canDrop) {
event.preventDefault();
event.dataTransfer.dropEffect = 'move';
Expand Down
8 changes: 8 additions & 0 deletions packages/plugin-ext/src/plugin/tree/tree-views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export class TreeViewsExtImpl implements TreeViewsExt {
return this.getTreeView(treeViewId).onDragStarted(treeItemIds, token);
}

$dragEnd(treeViewId: string): Promise<void> {
return this.getTreeView(treeViewId).dragEnd();
}

$drop(treeViewId: string, treeItemId: string | undefined, dataTransferItems: [string, string | DataTransferFileDTO][], token: CancellationToken): Promise<void> {
return this.getTreeView(treeViewId).handleDrop!(treeItemId, dataTransferItems, token);
}
Expand Down Expand Up @@ -606,6 +610,10 @@ class TreeViewExtImpl<T> implements Disposable {
return undefined;
}

async dragEnd(): Promise<void> {
this.localDataTransfer.clear();
}

async handleDrop(treeItemId: string | undefined, dataTransferItems: [string, string | DataTransferFileDTO][], token: CancellationToken): Promise<void> {
const treeItem = treeItemId ? this.getElement(treeItemId) : undefined;
const dropTransfer = new DataTransfer();
Expand Down