Reimplement drag and drop with the new interface (#21037)

* re enable drag and drop in book tree view
This commit is contained in:
Barbara Valdez
2022-10-31 10:12:23 -07:00
committed by GitHub
parent 68b91089db
commit 275a772496
2 changed files with 31 additions and 31 deletions

View File

@@ -44,7 +44,8 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
public viewId: string;
public books: BookModel[] = [];
public currentBook: BookModel | undefined;
supportedTypes = ['text/treeitems'];
dropMimeTypes = ['application/vnd.code.tree.BookTreeViewProvider'];
dragMimeTypes = ['text/uri-list'];
constructor(workspaceFolders: vscode.WorkspaceFolder[], extensionContext: vscode.ExtensionContext, openAsUntitled: boolean, view: string, public providerId: string) {
this._openAsUntitled = openAsUntitled;
@@ -762,33 +763,31 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
return sourcesByBook;
}
// {{SQL CARBON MERGE TODO}} -- need to reimplement drag-and-drop with current interface
// async onDrop(sources: vscode.TreeDataTransfer, target: BookTreeItem): Promise<void> {
// if (target.contextValue === BookTreeItemType.savedBook || target.contextValue === BookTreeItemType.section) {
// sendNotebookActionEvent(NbTelemetryView.Book, NbTelemetryAction.DragAndDrop);
// // gets the tree items that are dragged and dropped
// let treeItems = JSON.parse(await sources.items.get(this.supportedTypes[0])!.asString()) as BookTreeItem[];
// let rootItems = this.getLocalRoots(treeItems);
// rootItems = rootItems.filter(item => item.resourceUri !== target.resourceUri);
// if (rootItems && target) {
// let sourcesByBook = this.groupTreeItemsByBookModel(rootItems);
// const targetBook = this.books.find(book => book.bookPath === target.book.root);
// for (let [book, items] of sourcesByBook) {
// this.bookTocManager = new BookTocManager(book, targetBook);
// this.bookTocManager.enableDnd = true;
// await this.bookTocManager.updateBook(items, target);
// }
// }
// }
// }
// new dnd interface
readonly dropMimeTypes: readonly string[];
readonly dragMimeTypes: readonly string[];
handleDrag(treeItems: readonly BookTreeItem[], dataTransfer: vscode.DataTransfer, token: vscode.CancellationToken): Thenable<void> | void {
return undefined; // not implemented
dataTransfer.set('application/vnd.code.tree.BookTreeViewProvider', new vscode.DataTransferItem(treeItems));
}
handleDrop(target: BookTreeItem | undefined, dataTransfer: vscode.DataTransfer, token: vscode.CancellationToken): Thenable<void> | void {
async handleDrop(target: BookTreeItem | undefined, sources: vscode.DataTransfer, token: vscode.CancellationToken): Promise<void> {
const transferItem = sources.get('application/vnd.code.tree.BookTreeViewProvider');
if (!transferItem) {
return;
}
if (target.contextValue === BookTreeItemType.savedBook || target.contextValue === BookTreeItemType.section) {
sendNotebookActionEvent(NbTelemetryView.Book, NbTelemetryAction.DragAndDrop);
// gets the tree items that are dragged and dropped
const treeItems: BookTreeItem[] = transferItem.value;
let rootItems = this.getLocalRoots(treeItems);
rootItems = rootItems.filter(item => item.resourceUri !== target.resourceUri);
if (rootItems && target) {
let sourcesByBook = this.groupTreeItemsByBookModel(rootItems);
const targetBook = this.books.find(book => book.bookPath === target.book.root);
for (let [book, items] of sourcesByBook) {
this.bookTocManager = new BookTocManager(book, targetBook);
this.bookTocManager.enableDnd = true;
await this.bookTocManager.updateBook(items, target);
}
}
}
}
/**

View File

@@ -311,14 +311,15 @@ export class ExtHostTreeView<T> extends Disposable {
this.dataProvider = options.treeDataProvider;
this.dndController = options.dragAndDropController;
// {{SQL CARBON MERGE TODO}}
// {{SQL CARBON EDIT}}
const dropMimeTypes = options.dragAndDropController?.dropMimeTypes ?? [];
const dragMimeTypes = options.dragAndDropController?.dragMimeTypes ?? [];
const hasHandleDrag = !!options.dragAndDropController?.handleDrag;
const hasHandleDrop = !!options.dragAndDropController?.handleDrop;
if (this.proxy) {
this.proxy.$registerTreeViewDataProvider(viewId, {
showCollapseAll: !!options.showCollapseAll, canSelectMany: !!options.canSelectMany,
dropMimeTypes: undefined, dragMimeTypes: undefined,
hasHandleDrag: options.dragAndDropController !== undefined,
hasHandleDrop: options.dragAndDropController !== undefined
showCollapseAll: !!options.showCollapseAll, canSelectMany: !!options.canSelectMany, dropMimeTypes, dragMimeTypes, hasHandleDrag, hasHandleDrop
});
}
this.dndController = options.dragAndDropController;