From f0b785a16849730976ec2f3e2a24b7a79e555bc7 Mon Sep 17 00:00:00 2001 From: zhandouxiaojiji Date: Wed, 11 Nov 2020 10:46:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=8D=E5=88=B6=E7=B2=98=E8=B4=B4=E8=8A=82?= =?UTF-8?q?=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/MainEventType.ts | 2 ++ main-process/AppMenu.ts | 16 +++++++++++++++ render-process/Editor/index.tsx | 35 +++++++++++++++++++++++++++++++++ render-process/TreeTabs.tsx | 12 ++++++++++- 4 files changed, 64 insertions(+), 1 deletion(-) diff --git a/common/MainEventType.ts b/common/MainEventType.ts index 4aa6145..6fde49e 100644 --- a/common/MainEventType.ts +++ b/common/MainEventType.ts @@ -5,6 +5,8 @@ export default { CREATE_TREE: 'CREATE_TREE', CREATE_NODE: 'CREATE_NODE', DELETE_NODE: 'DELETE_NODE', + COPY_NODE: 'COPY_NODE', + PASTE_NODE: 'PASTE_NODE', SAVE: 'SAVE', SAVE_ALL: 'SAVE_ALL', } \ No newline at end of file diff --git a/main-process/AppMenu.ts b/main-process/AppMenu.ts index 437a8f1..b82f125 100644 --- a/main-process/AppMenu.ts +++ b/main-process/AppMenu.ts @@ -117,6 +117,22 @@ export default class AppMenu { this.webContents.send(MainEventType.DELETE_NODE); } }, + { type: 'separator' }, + { + label: '复制节点', + accelerator: 'ctrl+shift+c', + role: 'copy', + click: () => { + this.webContents.send(MainEventType.COPY_NODE); + } + }, + { + label: '粘贴节点', + accelerator: 'ctrl+shift+v', + click: () => { + this.webContents.send(MainEventType.PASTE_NODE); + } + } ] }); } diff --git a/render-process/Editor/index.tsx b/render-process/Editor/index.tsx index cdec80e..c7ebda8 100644 --- a/render-process/Editor/index.tsx +++ b/render-process/Editor/index.tsx @@ -11,6 +11,7 @@ import TreePanel from './TreePanel'; import Settings from '../../main-process/Settings'; import './Editor.css'; +import { clipboard } from 'electron'; export interface EditorProps { filepath: string; @@ -332,6 +333,40 @@ export default class Editor extends React.Component { })); } + copyNode() { + console.log("editor copy node"); + const { curNodeId } = this.state; + if (!curNodeId) { + return; + } + const data = this.graph.findDataById(curNodeId); + clipboard.writeText(JSON.stringify(data, null, 2)); + } + + pasteNode() { + const { curNodeId } = this.state; + if (!curNodeId) { + message.warn("未选中节点"); + return; + } + const curNodeData = this.graph.findDataById(curNodeId); + try { + const str = clipboard.readText(); + if(!str || str == '') { + return; + } + const data = JSON.parse(str); + if(!curNodeData.children) { + curNodeData.children = []; + } + curNodeData.children.push(data); + this.autoId = Utils.refreshNodeId(this.graph.findDataById('1') as GraphNodeModel); + this.changeWithoutAnim(); + } catch (error) { + message.error("粘贴数据有误"); + } + } + render() { const { curNodeId, treeModel, settings } = this.state; var curNode: any; diff --git a/render-process/TreeTabs.tsx b/render-process/TreeTabs.tsx index 899d57b..4c2f34e 100644 --- a/render-process/TreeTabs.tsx +++ b/render-process/TreeTabs.tsx @@ -36,7 +36,17 @@ export default class TreeTabs extends Component { ipcRenderer.on(MainEventType.DELETE_NODE, () => { const editor = this.getCurEditor(); editor?.deleteNode(); - }) + }); + + ipcRenderer.on(MainEventType.COPY_NODE, () => { + const editor = this.getCurEditor(); + editor?.copyNode(); + }); + + ipcRenderer.on(MainEventType.PASTE_NODE, () => { + const editor = this.getCurEditor(); + editor?.pasteNode(); + }); ipcRenderer.on(MainEventType.SAVE, (event: any) => { const { curPath } = this.state;