소스 검색

FavoritesTree: add drag & drop

LeoVgr 2 주 전
부모
커밋
da4d4c6151
1개의 변경된 파일59개의 추가작업 그리고 0개의 파일을 삭제
  1. 59 0
      hide/view/FileBrowser.hx

+ 59 - 0
hide/view/FileBrowser.hx

@@ -601,6 +601,65 @@ class FileBrowser extends hide.ui.View<FileBrowserState> {
 				}
 			}
 		}
+		favoritesTree.dragAndDropInterface = {
+			onDragStart: function(file: FavoriteEntry, e: hide.tools.DragAndDrop.DragData) : Bool {
+				var selection = favoritesTree.getSelectedItems();
+				if (selection.length <= 0)
+					return false;
+
+				var fileEntries = [];
+				for (s in selection) {
+					if (s.ref != null)
+						fileEntries.push(s.ref);
+				}
+
+				e.data.set("drag/filetree", fileEntries);
+				ide.setData("drag/filetree", cast fileEntries);
+				return true;
+			},
+			getItemDropFlags: function(target: FavoriteEntry, e: hide.tools.DragAndDrop.DragData) : hide.comp.FancyTree.DropFlags {
+				if (target == null)
+					return Reorder;
+
+				var fileEntries : Array<FileEntry> = cast e.data.get("drag/filetree") ?? [];
+				fileEntries = fileEntries.copy();
+				var containsFiles = fileEntries != null && fileEntries.length > 0;
+
+				if (!containsFiles)
+					return hide.comp.FancyTree.DropFlags.ofInt(0);
+
+				// Can't drop a file on itself
+				fileEntries.remove(target.ref);
+
+				if (fileEntries.length == 0)
+					return hide.comp.FancyTree.DropFlags.ofInt(0);
+
+				if (target.ref.kind == Dir)
+					return (Reorder:hide.comp.FancyTree.DropFlags) | Reparent;
+
+				return Reorder;
+			},
+			onDrop: function(target: FavoriteEntry, operation: hide.comp.FancyTree.DropOperation, e: hide.tools.DragAndDrop.DragData) : Bool {
+				if (target.ref.kind != Dir)
+					target = target.parent;
+
+				var fileEntries : Array<FileEntry> = cast e.data.get("drag/filetree") ?? [];
+				fileEntries = fileEntries.copy();
+				fileEntries.remove(target.ref);
+
+				var files = [ for (f in fileEntries) f.path ];
+				if (files.length == 0)
+					return false;
+
+				if(!ide.confirm('Really move files :\n${files.join("\n")}\nto target folder :\n${target.ref.getRelPath()}\n?\n(This could take a long time)')) {
+					return true;
+				}
+
+				moveFiles(target.ref.getRelPath(), files);
+
+				return true;
+			}
+		}
 
 		favoritesTree.rebuildTree();