diff --git a/src/components/editor.tsx b/src/components/editor.tsx index 08401d4..93dfbd7 100644 --- a/src/components/editor.tsx +++ b/src/components/editor.tsx @@ -632,9 +632,9 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . }); editor.graph.on("node:drop", (e: G6GraphEvent) => { - const srcNodeId = editor.dragSrcId; const dstNode = e.item; + let srcNodeId = editor.dragSrcId; let dragDir; if (dstNode.hasState("dragRight")) { dragDir = "dragRight"; @@ -647,6 +647,39 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . clearDragSrcState(); clearDragDstState(); + if (e.originalEvent instanceof DragEvent) { + const dragEvent = e.originalEvent as DragEvent; + const exploreFile = dragEvent.dataTransfer?.getData("explore-file"); + const exploreNode = dragEvent.dataTransfer?.getData("explore-node"); + const dstData = findDataById(dstNode.getID()); + + if (exploreNode) { + const newTreeData: TreeGraphData = b3util.createTreeData( + { + id: editor.autoId++, + name: exploreNode, + }, + dstData.id + ); + dstData.children ||= []; + dstData.children.push(newTreeData); + srcNodeId = newTreeData.id; + } else if (exploreFile && exploreFile !== editor.path) { + const newTreeData: TreeGraphData = b3util.createTreeData( + { + id: editor.autoId++, + name: "unknow", + path: Path.relative(workspace.workdir, exploreFile).replaceAll(Path.sep, "/"), + }, + dstData.id + ); + dstData.children ||= []; + dstData.children.push(newTreeData); + srcNodeId = newTreeData.id; + editor.autoId = b3util.refreshTreeDataId(newTreeData, Number(srcNodeId)); + } + } + if (!srcNodeId) { console.log("no drag src"); return; diff --git a/src/components/explorer.tsx b/src/components/explorer.tsx index 75a9419..8c99f34 100644 --- a/src/components/explorer.tsx +++ b/src/components/explorer.tsx @@ -147,7 +147,7 @@ export const Explorer: FC = () => { @@ -696,6 +696,7 @@ export const Explorer: FC = () => { return ( { allowDrop={(options) => { return !options.dropNode.isLeaf; }} + onDragStart={(e) => { + e.event.dataTransfer.setData("explore-file", e.node.path); + }} defaultExpandedKeys={[workspace.fileTree.path]} draggable={newName !== null ? false : { icon: false }} expandedKeys={expandedKeys} @@ -793,6 +797,10 @@ export const Explorer: FC = () => { tabIndex={-1} fieldNames={{ key: "title" }} treeData={workspace.nodeTree ? [workspace.nodeTree] : []} + draggable={{ icon: false, nodeDraggable: (node) => !!node.isLeaf }} + onDragStart={(e) => { + e.event.dataTransfer.setData("explore-node", e.node.def?.name ?? ""); + }} switcherIcon={} /> diff --git a/src/components/menu.tsx b/src/components/menu.tsx index 2654dd1..eebeaf7 100644 --- a/src/components/menu.tsx +++ b/src/components/menu.tsx @@ -271,7 +271,6 @@ export const Menu: FC = () => { { id: "menu.view.zoomIn", label: t("zoomIn"), - role: "zoomIn", click: () => { const webContents = getFocusedWebContents(); if (webContents) { diff --git a/src/misc/b3util.ts b/src/misc/b3util.ts index 33167c7..2f8ea43 100644 --- a/src/misc/b3util.ts +++ b/src/misc/b3util.ts @@ -310,6 +310,8 @@ export const createTreeData = (node: NodeModel, parent?: string) => { treeData.lastModified = fs.statSync(subtreePath).mtimeMs; treeData.path = node.path; treeData.debug = node.debug; + treeData.parent = parent; + treeData.id = node.id.toFixed(); treeData.size = calcTreeDataSize(treeData); } catch (error) { message.error(`解析子树失败:${node.path}`);