diff --git a/render-process/Editor/index.tsx b/render-process/Editor/index.tsx index 5eb7307..1dc9d00 100644 --- a/render-process/Editor/index.tsx +++ b/render-process/Editor/index.tsx @@ -1,7 +1,7 @@ import * as React from "react"; import * as fs from "fs"; import * as path from "path"; -import { Row, Col, message } from "antd"; +import { Row, Col, message, Card } from "antd"; import NodePanel from "./NodePanel"; import G6, { TreeGraph } from "@antv/g6"; import { G6GraphEvent } from "@antv/g6/lib/interface/behavior"; @@ -16,7 +16,6 @@ import Settings from "../../main-process/Settings"; import "./Editor.css"; import { clipboard } from "electron"; -import { TreeGraphData } from "@antv/g6/lib/types"; export interface EditorProps { filepath: string; @@ -24,7 +23,6 @@ export interface EditorProps { interface EditorState { curNodeId?: string; - treeModel?: BehaviorTreeModel; } export default class Editor extends React.Component { @@ -47,8 +45,8 @@ export default class Editor extends React.Component { this.settings = Utils.getRemoteSettings(); const str = fs.readFileSync(this.props.filepath, "utf8"); - let tree: BehaviorTreeModel = JSON.parse(str); - this.data = Utils.createTreeData(tree.root, this.settings); + this.treeModel = JSON.parse(str); + this.data = Utils.createTreeData(this.treeModel.root, this.settings); this.autoId = Utils.refreshNodeId(this.data); } @@ -389,7 +387,8 @@ export default class Editor extends React.Component { useStackData(data: BehaviorNodeModel) { this.graph.set("animate", false); this.graph.changeData(Utils.createTreeData(data, this.settings)); - this.graph.layout(true); + this.graph.layout(); + this.graph.fitCenter(); this.graph.set("animate", true); } @@ -425,7 +424,8 @@ export default class Editor extends React.Component { } render() { - const { curNodeId, treeModel } = this.state; + console.log("render tree"); + const { curNodeId } = this.state; var curNode: any; if (curNodeId) { curNode = this.graph.findDataById(curNodeId); @@ -455,7 +455,7 @@ export default class Editor extends React.Component { }} /> ) : ( - + )} diff --git a/render-process/TreeTabs.tsx b/render-process/TreeTabs.tsx index 36cb54b..952b961 100644 --- a/render-process/TreeTabs.tsx +++ b/render-process/TreeTabs.tsx @@ -112,13 +112,10 @@ export default class TreeTabs extends Component { } closeFile(path: string) { - const index = this.state.filepaths.indexOf(path); - if (index >= 0) { - const filepaths = this.state.filepaths; - filepaths.splice(index, 1); - const length = filepaths.length; - this.setState({ filepaths, curPath: length > 0 ? filepaths[length - 1] : null }); - } + let filepaths = this.state.filepaths; + filepaths = filepaths.filter((filepath) => (filepath != path)); + const length = filepaths.length; + this.setState({ filepaths, curPath: length > 0 ? filepaths[0] : null }); } render() { @@ -140,13 +137,7 @@ export default class TreeTabs extends Component { }} onEdit={(targetKey, action) => { if (action == "remove") { - const idx = filepaths.indexOf(targetKey as string); - if (idx < 0) { - return; - } - filepaths.splice(idx, 1); - const nextPath = filepaths[idx - 1]; - this.setState({ filepaths, curPath: nextPath }); + this.closeFile(targetKey as string); } }} > diff --git a/render-process/index.tsx b/render-process/index.tsx index 45712c7..0acf475 100644 --- a/render-process/index.tsx +++ b/render-process/index.tsx @@ -70,10 +70,12 @@ export default class Main extends Component { }) console.log("workdir", this.settings.curWorkspace.getWorkdir()); - this.setState({ - workdir: this.settings.curWorkspace.getWorkdir(), - workspace: this.settings.curWorkspace.getFilepath(), - }); + setTimeout(() => { + this.setState({ + workdir: this.settings.curWorkspace.getWorkdir(), + workspace: this.settings.curWorkspace.getFilepath(), + }); + }, 50); } updateSettings() {