新建&删除节点

This commit is contained in:
zhandouxiaojiji committed 2020-11-07 15:12:02 +08:00
1 parent 84a354274d
commit 0c5d62157b
4 files changed
+53 -20

No files matched your search

+19
View File
@@ -291,6 +291,25 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
this.changeWithoutAnim();
}
deleteNode() {
console.log("editor delete node");
const { curNodeId } = this.state;
if (!curNodeId) {
return;
}
if(curNodeId == '1') {
message.warn("根节点不能删除!");
return;
}
this.onSelectNode(null);
const rootData = this.graph.findDataById('1');
const parentData = Utils.findParent(rootData, curNodeId);
parentData.children = parentData.children.filter(e => e.id != curNodeId);
this.changeWithoutAnim();
}
updateNode(id: string) {
this.graph.changeData();
this.graph.layout();
+18 -12
View File
@@ -1,5 +1,3 @@
import * as ReactDOM from "react-dom";
import Editor from "./Editor";
import React, { Component } from "react";
import { Layout, Tabs, message } from 'antd';
@@ -9,7 +7,6 @@ import * as path from 'path';
import 'antd/dist/antd.dark.css';
import MainEventType from "../common/MainEventType";
const { Header, Sider, Content, Footer } = Layout;
const { TabPane } = Tabs;
interface TreeTabsProps {
@@ -32,17 +29,18 @@ export default class TreeTabs extends Component<TreeTabsProps, TreeTabsState> {
componentDidMount() {
ipcRenderer.on(MainEventType.CREATE_NODE, (event: any, name: any) => {
const {curPath} = this.state;
if(!curPath) {
return;
}
const editor = this.editors[curPath];
editor.createNode(name);
const editor = this.getCurEditor();
editor?.createNode(name);
});
ipcRenderer.on(MainEventType.DELETE_NODE, () => {
const editor = this.getCurEditor();
editor?.deleteNode();
})
ipcRenderer.on(MainEventType.SAVE, (event: any) => {
const {curPath} = this.state;
if(!curPath) {
const { curPath } = this.state;
if (!curPath) {
return;
}
const editor = this.editors[curPath];
@@ -51,7 +49,7 @@ export default class TreeTabs extends Component<TreeTabsProps, TreeTabsState> {
});
ipcRenderer.on(MainEventType.SAVE_ALL, (event: any) => {
for(let k in this.editors){
for (let k in this.editors) {
let editor = this.editors[k];
editor.save();
}
@@ -59,6 +57,14 @@ export default class TreeTabs extends Component<TreeTabsProps, TreeTabsState> {
});
}
getCurEditor() {
const { curPath } = this.state;
if (!curPath) {
return;
}
return this.editors[curPath];
}
openFile(path: string) {
console.log("on open file", path);
if (this.state.filepaths.indexOf(path) < 0) {