复制粘贴节点
This commit is contained in:
1 parent
0c5d62157b
commit
f0b785a168
4 files changed
+64
-1
No files matched your search
@@ -5,6 +5,8 @@ export default {
|
|||||||
CREATE_TREE: 'CREATE_TREE',
|
CREATE_TREE: 'CREATE_TREE',
|
||||||
CREATE_NODE: 'CREATE_NODE',
|
CREATE_NODE: 'CREATE_NODE',
|
||||||
DELETE_NODE: 'DELETE_NODE',
|
DELETE_NODE: 'DELETE_NODE',
|
||||||
|
COPY_NODE: 'COPY_NODE',
|
||||||
|
PASTE_NODE: 'PASTE_NODE',
|
||||||
SAVE: 'SAVE',
|
SAVE: 'SAVE',
|
||||||
SAVE_ALL: 'SAVE_ALL',
|
SAVE_ALL: 'SAVE_ALL',
|
||||||
}
|
}
|
||||||
@@ -117,6 +117,22 @@ export default class AppMenu {
|
|||||||
this.webContents.send(MainEventType.DELETE_NODE);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import TreePanel from './TreePanel';
|
|||||||
import Settings from '../../main-process/Settings';
|
import Settings from '../../main-process/Settings';
|
||||||
|
|
||||||
import './Editor.css';
|
import './Editor.css';
|
||||||
|
import { clipboard } from 'electron';
|
||||||
|
|
||||||
export interface EditorProps {
|
export interface EditorProps {
|
||||||
filepath: string;
|
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() {
|
render() {
|
||||||
const { curNodeId, treeModel, settings } = this.state;
|
const { curNodeId, treeModel, settings } = this.state;
|
||||||
var curNode: any;
|
var curNode: any;
|
||||||
|
|||||||
@@ -36,7 +36,17 @@ export default class TreeTabs extends Component<TreeTabsProps, TreeTabsState> {
|
|||||||
ipcRenderer.on(MainEventType.DELETE_NODE, () => {
|
ipcRenderer.on(MainEventType.DELETE_NODE, () => {
|
||||||
const editor = this.getCurEditor();
|
const editor = this.getCurEditor();
|
||||||
editor?.deleteNode();
|
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) => {
|
ipcRenderer.on(MainEventType.SAVE, (event: any) => {
|
||||||
const { curPath } = this.state;
|
const { curPath } = this.state;
|
||||||
|
|||||||
Reference in new issue
Block a user