fix: TreeTabs close

This commit is contained in:
zhandouxiaojiji committed 2020-12-04 15:53:58 +08:00
1 parent 909d643ea5
commit b61196a7f7
3 files changed
+14 -21

No files matched your search

+8 -8
View File
@@ -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<EditorProps, EditorState> {
@@ -47,8 +45,8 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
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<EditorProps, EditorState> {
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<EditorProps, EditorState> {
}
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<EditorProps, EditorState> {
}}
/>
) : (
<TreePanel model={treeModel} />
<TreePanel model={this.treeModel} />
)}
</Col>
</Row>
+4 -13
View File
@@ -112,13 +112,10 @@ export default class TreeTabs extends Component<TreeTabsProps, TreeTabsState> {
}
closeFile(path: string) {
const index = this.state.filepaths.indexOf(path);
if (index >= 0) {
const filepaths = this.state.filepaths;
filepaths.splice(index, 1);
let filepaths = this.state.filepaths;
filepaths = filepaths.filter((filepath) => (filepath != path));
const length = filepaths.length;
this.setState({ filepaths, curPath: length > 0 ? filepaths[length - 1] : null });
}
this.setState({ filepaths, curPath: length > 0 ? filepaths[0] : null });
}
render() {
@@ -140,13 +137,7 @@ export default class TreeTabs extends Component<TreeTabsProps, TreeTabsState> {
}}
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);
}
}}
>
+2
View File
@@ -70,10 +70,12 @@ export default class Main extends Component {
})
console.log("workdir", this.settings.curWorkspace.getWorkdir());
setTimeout(() => {
this.setState({
workdir: this.settings.curWorkspace.getWorkdir(),
workspace: this.settings.curWorkspace.getFilepath(),
});
}, 50);
}
updateSettings() {