Fix dropping async oe tree item onto root (#11934)

This commit is contained in:
Charles Gagnon
2020-08-24 18:07:42 -07:00
committed by GitHub
parent 969932743a
commit 52ec96e4f1
3 changed files with 32 additions and 16 deletions

View File

@@ -10,15 +10,15 @@ import { TreeUpdateUtils } from 'sql/workbench/services/objectExplorer/browser/t
import { IDragAndDropData } from 'vs/base/browser/dnd'; import { IDragAndDropData } from 'vs/base/browser/dnd';
import { ITreeDragAndDrop, ITreeDragOverReaction, TreeDragOverReactions } from 'vs/base/browser/ui/tree/tree'; import { ITreeDragAndDrop, ITreeDragOverReaction, TreeDragOverReactions } from 'vs/base/browser/ui/tree/tree';
import { ServerTreeDragAndDrop } from 'sql/workbench/services/objectExplorer/browser/dragAndDropController'; import { ServerTreeDragAndDrop } from 'sql/workbench/services/objectExplorer/browser/dragAndDropController';
import { IDragAndDrop } from 'vs/base/parts/tree/browser/tree'; import { ServerTreeElement, AsyncServerTree } from 'sql/workbench/services/objectExplorer/browser/asyncServerTree';
import { ServerTreeElement } from 'sql/workbench/services/objectExplorer/browser/asyncServerTree';
/** /**
* Implements drag and drop for the server tree * Implements drag and drop for the server tree
*/ */
export class AsyncServerTreeDragAndDrop implements ITreeDragAndDrop<ServerTreeElement> { export class AsyncServerTreeDragAndDrop implements ITreeDragAndDrop<ServerTreeElement> {
private _dragAndDrop: IDragAndDrop; private _dragAndDrop: ServerTreeDragAndDrop;
private _tree: AsyncServerTree | undefined;
constructor( constructor(
@IConnectionManagementService connectionManagementService: IConnectionManagementService, @IConnectionManagementService connectionManagementService: IConnectionManagementService,
@@ -26,19 +26,26 @@ export class AsyncServerTreeDragAndDrop implements ITreeDragAndDrop<ServerTreeEl
this._dragAndDrop = new ServerTreeDragAndDrop(connectionManagementService); this._dragAndDrop = new ServerTreeDragAndDrop(connectionManagementService);
} }
/**
* Sets the tree context for this drag and drop controller
*/
public set tree(value: AsyncServerTree) {
this._tree = value;
}
/** /**
* Returns a uri if the given element should be allowed to drag. * Returns a uri if the given element should be allowed to drag.
* Returns null, otherwise. * Returns null, otherwise.
*/ */
public getDragURI(element: ServerTreeElement): string { public getDragURI(element: ServerTreeElement): string {
return this._dragAndDrop.getDragURI(undefined, element); return this._dragAndDrop.getDragURI(this._tree, element);
} }
/** /**
* Returns a label(name) to display when dragging the element. * Returns a label(name) to display when dragging the element.
*/ */
public getDragLabel(elements: ServerTreeElement[]): string { public getDragLabel(elements: ServerTreeElement[]): string {
return this._dragAndDrop.getDragLabel(undefined, elements); return this._dragAndDrop.getDragLabel(this._tree, elements);
} }
/** /**
@@ -47,13 +54,17 @@ export class AsyncServerTreeDragAndDrop implements ITreeDragAndDrop<ServerTreeEl
public onDragStart(dragAndDropData: IDragAndDropData, originalEvent: DragEvent): void { public onDragStart(dragAndDropData: IDragAndDropData, originalEvent: DragEvent): void {
// Force the event cast while in preview - we don't use any of the mouse properties on the // Force the event cast while in preview - we don't use any of the mouse properties on the
// implementation so this is fine for now // implementation so this is fine for now
return this._dragAndDrop.onDragStart(undefined, dragAndDropData, <any>originalEvent); return this._dragAndDrop.onDragStart(this._tree, dragAndDropData, <any>originalEvent);
} }
public onDragOver(data: IDragAndDropData, targetElement: ServerTreeElement, targetIndex: number, originalEvent: DragEvent): boolean | ITreeDragOverReaction { public onDragOver(data: IDragAndDropData, targetElement: ServerTreeElement, targetIndex: number, originalEvent: DragEvent): boolean | ITreeDragOverReaction {
// Dropping onto an empty space (undefined targetElement) we treat as wanting to move into the root connection group
if (!targetElement) {
targetElement = this._tree?.getInput();
}
// Force the event cast while in preview - we don't use any of the mouse properties on the // Force the event cast while in preview - we don't use any of the mouse properties on the
// implementation so this is fine for now // implementation so this is fine for now
const canDragOver = this._dragAndDrop.onDragOver(undefined, data, targetElement, <any>originalEvent); const canDragOver = this._dragAndDrop.onDragOver(this._tree, data, targetElement, <any>originalEvent);
if (canDragOver.accept) { if (canDragOver.accept) {
return TreeDragOverReactions.acceptBubbleDown(canDragOver.autoExpand); return TreeDragOverReactions.acceptBubbleDown(canDragOver.autoExpand);
@@ -66,11 +77,13 @@ export class AsyncServerTreeDragAndDrop implements ITreeDragAndDrop<ServerTreeEl
* Handle a drop in the server tree. * Handle a drop in the server tree.
*/ */
public drop(data: IDragAndDropData, targetElement: ServerTreeElement, targetIndex: number, originalEvent: DragEvent): void { public drop(data: IDragAndDropData, targetElement: ServerTreeElement, targetIndex: number, originalEvent: DragEvent): void {
// Dropping onto an empty space (undefined targetElement) we treat as wanting to move into the root connection group
if (!targetElement) {
targetElement = this._tree?.getInput();
}
// Force the event cast while in preview - we don't use any of the mouse properties on the // Force the event cast while in preview - we don't use any of the mouse properties on the
// implementation so this is fine for now // implementation so this is fine for now
this._dragAndDrop.drop(this._tree, data, targetElement, <any>originalEvent);
// TODO: chgagnon Drop on root node
this._dragAndDrop.drop(undefined, data, targetElement, <any>originalEvent);
} }
public onDragEnd(originalEvent: DragEvent): void { public onDragEnd(originalEvent: DragEvent): void {

View File

@@ -12,6 +12,7 @@ import { TreeUpdateUtils } from 'sql/workbench/services/objectExplorer/browser/t
import { UNSAVED_GROUP_ID } from 'sql/platform/connection/common/constants'; import { UNSAVED_GROUP_ID } from 'sql/platform/connection/common/constants';
import { DataTransfers, IDragAndDropData } from 'vs/base/browser/dnd'; import { DataTransfers, IDragAndDropData } from 'vs/base/browser/dnd';
import { TreeNode } from 'sql/workbench/services/objectExplorer/common/treeNode'; import { TreeNode } from 'sql/workbench/services/objectExplorer/common/treeNode';
import { AsyncServerTree } from 'sql/workbench/services/objectExplorer/browser/asyncServerTree';
export function supportsNodeNameDrop(nodeId: string): boolean { export function supportsNodeNameDrop(nodeId: string): boolean {
if (nodeId === 'Table' || nodeId === 'Column' || nodeId === 'View') { if (nodeId === 'Table' || nodeId === 'Column' || nodeId === 'View') {
@@ -45,7 +46,7 @@ export class ServerTreeDragAndDrop implements IDragAndDrop {
* Returns a uri if the given element should be allowed to drag. * Returns a uri if the given element should be allowed to drag.
* Returns null, otherwise. * Returns null, otherwise.
*/ */
public getDragURI(tree: ITree, element: any): string { public getDragURI(tree: AsyncServerTree | ITree, element: any): string {
if (element) { if (element) {
if (element instanceof ConnectionProfile) { if (element instanceof ConnectionProfile) {
return (<ConnectionProfile>element).id; return (<ConnectionProfile>element).id;
@@ -67,7 +68,7 @@ export class ServerTreeDragAndDrop implements IDragAndDrop {
/** /**
* Returns a label(name) to display when dragging the element. * Returns a label(name) to display when dragging the element.
*/ */
public getDragLabel(tree: ITree, elements: any[]): string { public getDragLabel(tree: AsyncServerTree | ITree, elements: any[]): string {
if (elements) { if (elements) {
if (elements[0] instanceof ConnectionProfile) { if (elements[0] instanceof ConnectionProfile) {
return (<ConnectionProfile>elements[0]).serverName; return (<ConnectionProfile>elements[0]).serverName;
@@ -88,7 +89,7 @@ export class ServerTreeDragAndDrop implements IDragAndDrop {
/** /**
* Called when the drag operation starts. * Called when the drag operation starts.
*/ */
public onDragStart(tree: ITree, dragAndDropData: IDragAndDropData, originalEvent: DragMouseEvent): void { public onDragStart(tree: AsyncServerTree | ITree, dragAndDropData: IDragAndDropData, originalEvent: DragMouseEvent): void {
let escapedSchema, escapedName, finalString; let escapedSchema, escapedName, finalString;
TreeUpdateUtils.isInDragAndDrop = true; TreeUpdateUtils.isInDragAndDrop = true;
const data = dragAndDropData.getData(); const data = dragAndDropData.getData();
@@ -136,7 +137,7 @@ export class ServerTreeDragAndDrop implements IDragAndDrop {
* dropped into target or some parent of the target. * dropped into target or some parent of the target.
* Returns DRAG_OVER_ACCEPT_BUBBLE_DOWN when element is a connection group or connection * Returns DRAG_OVER_ACCEPT_BUBBLE_DOWN when element is a connection group or connection
*/ */
public onDragOver(tree: ITree, data: IDragAndDropData, targetElement: any, originalEvent: DragMouseEvent): IDragOverReaction { public onDragOver(tree: AsyncServerTree | ITree, data: IDragAndDropData, targetElement: any, originalEvent: DragMouseEvent): IDragOverReaction {
let canDragOver: boolean = true; let canDragOver: boolean = true;
if (targetElement instanceof ConnectionProfile || targetElement instanceof ConnectionProfileGroup) { if (targetElement instanceof ConnectionProfile || targetElement instanceof ConnectionProfileGroup) {
@@ -174,7 +175,7 @@ export class ServerTreeDragAndDrop implements IDragAndDrop {
/** /**
* Handle a drop in the server tree. * Handle a drop in the server tree.
*/ */
public drop(tree: ITree, data: IDragAndDropData, targetElement: any, originalEvent: DragMouseEvent): void { public drop(tree: AsyncServerTree | ITree, data: IDragAndDropData, targetElement: any, originalEvent: DragMouseEvent): void {
TreeUpdateUtils.isInDragAndDrop = false; TreeUpdateUtils.isInDragAndDrop = false;
let targetConnectionProfileGroup: ConnectionProfileGroup = this.getTargetGroup(targetElement); let targetConnectionProfileGroup: ConnectionProfileGroup = this.getTargetGroup(targetElement);

View File

@@ -104,7 +104,7 @@ export class TreeCreationUtils {
identityProvider: identityProvider identityProvider: identityProvider
}; };
return instantiationService.createInstance( const tree = instantiationService.createInstance(
AsyncServerTree, AsyncServerTree,
'ServerTreeView', 'ServerTreeView',
treeContainer, treeContainer,
@@ -117,6 +117,8 @@ export class TreeCreationUtils {
dataSource, dataSource,
treeOptions treeOptions
); );
dnd.tree = tree;
return tree;
} else { } else {
const dataSource = instantiationService.createInstance(ServerTreeDataSource); const dataSource = instantiationService.createInstance(ServerTreeDataSource);
const actionProvider = instantiationService.createInstance(ServerTreeActionProvider); const actionProvider = instantiationService.createInstance(ServerTreeActionProvider);