复制粘贴节点

This commit is contained in:
zhandouxiaojiji committed 2020-11-11 10:46:38 +08:00
1 parent 0c5d62157b
commit f0b785a168
4 files changed
+64 -1

No files matched your search

+2
View File
@@ -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',
}
+16
View File
@@ -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);
}
}
]
});
}
+35
View File
@@ -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<EditorProps, EditorState> {
}));
}
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;
+11 -1
View File
@@ -36,7 +36,17 @@ export default class TreeTabs extends Component<TreeTabsProps, TreeTabsState> {
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;