fix: TreeTabs close
This commit is contained in:
1 parent
909d643ea5
commit
b61196a7f7
3 files changed
+19
-26
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import { Row, Col, message } from "antd";
|
import { Row, Col, message, Card } from "antd";
|
||||||
import NodePanel from "./NodePanel";
|
import NodePanel from "./NodePanel";
|
||||||
import G6, { TreeGraph } from "@antv/g6";
|
import G6, { TreeGraph } from "@antv/g6";
|
||||||
import { G6GraphEvent } from "@antv/g6/lib/interface/behavior";
|
import { G6GraphEvent } from "@antv/g6/lib/interface/behavior";
|
||||||
@@ -16,7 +16,6 @@ import Settings from "../../main-process/Settings";
|
|||||||
|
|
||||||
import "./Editor.css";
|
import "./Editor.css";
|
||||||
import { clipboard } from "electron";
|
import { clipboard } from "electron";
|
||||||
import { TreeGraphData } from "@antv/g6/lib/types";
|
|
||||||
|
|
||||||
export interface EditorProps {
|
export interface EditorProps {
|
||||||
filepath: string;
|
filepath: string;
|
||||||
@@ -24,7 +23,6 @@ export interface EditorProps {
|
|||||||
|
|
||||||
interface EditorState {
|
interface EditorState {
|
||||||
curNodeId?: string;
|
curNodeId?: string;
|
||||||
treeModel?: BehaviorTreeModel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Editor extends React.Component<EditorProps, EditorState> {
|
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();
|
this.settings = Utils.getRemoteSettings();
|
||||||
const str = fs.readFileSync(this.props.filepath, "utf8");
|
const str = fs.readFileSync(this.props.filepath, "utf8");
|
||||||
let tree: BehaviorTreeModel = JSON.parse(str);
|
this.treeModel = JSON.parse(str);
|
||||||
this.data = Utils.createTreeData(tree.root, this.settings);
|
this.data = Utils.createTreeData(this.treeModel.root, this.settings);
|
||||||
this.autoId = Utils.refreshNodeId(this.data);
|
this.autoId = Utils.refreshNodeId(this.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,7 +387,8 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
|
|||||||
useStackData(data: BehaviorNodeModel) {
|
useStackData(data: BehaviorNodeModel) {
|
||||||
this.graph.set("animate", false);
|
this.graph.set("animate", false);
|
||||||
this.graph.changeData(Utils.createTreeData(data, this.settings));
|
this.graph.changeData(Utils.createTreeData(data, this.settings));
|
||||||
this.graph.layout(true);
|
this.graph.layout();
|
||||||
|
this.graph.fitCenter();
|
||||||
this.graph.set("animate", true);
|
this.graph.set("animate", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,7 +424,8 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { curNodeId, treeModel } = this.state;
|
console.log("render tree");
|
||||||
|
const { curNodeId } = this.state;
|
||||||
var curNode: any;
|
var curNode: any;
|
||||||
if (curNodeId) {
|
if (curNodeId) {
|
||||||
curNode = this.graph.findDataById(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>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|||||||
@@ -112,13 +112,10 @@ export default class TreeTabs extends Component<TreeTabsProps, TreeTabsState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
closeFile(path: string) {
|
closeFile(path: string) {
|
||||||
const index = this.state.filepaths.indexOf(path);
|
let filepaths = this.state.filepaths;
|
||||||
if (index >= 0) {
|
filepaths = filepaths.filter((filepath) => (filepath != path));
|
||||||
const filepaths = this.state.filepaths;
|
const length = filepaths.length;
|
||||||
filepaths.splice(index, 1);
|
this.setState({ filepaths, curPath: length > 0 ? filepaths[0] : null });
|
||||||
const length = filepaths.length;
|
|
||||||
this.setState({ filepaths, curPath: length > 0 ? filepaths[length - 1] : null });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -140,13 +137,7 @@ export default class TreeTabs extends Component<TreeTabsProps, TreeTabsState> {
|
|||||||
}}
|
}}
|
||||||
onEdit={(targetKey, action) => {
|
onEdit={(targetKey, action) => {
|
||||||
if (action == "remove") {
|
if (action == "remove") {
|
||||||
const idx = filepaths.indexOf(targetKey as string);
|
this.closeFile(targetKey as string);
|
||||||
if (idx < 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
filepaths.splice(idx, 1);
|
|
||||||
const nextPath = filepaths[idx - 1];
|
|
||||||
this.setState({ filepaths, curPath: nextPath });
|
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -70,10 +70,12 @@ export default class Main extends Component {
|
|||||||
})
|
})
|
||||||
|
|
||||||
console.log("workdir", this.settings.curWorkspace.getWorkdir());
|
console.log("workdir", this.settings.curWorkspace.getWorkdir());
|
||||||
this.setState({
|
setTimeout(() => {
|
||||||
workdir: this.settings.curWorkspace.getWorkdir(),
|
this.setState({
|
||||||
workspace: this.settings.curWorkspace.getFilepath(),
|
workdir: this.settings.curWorkspace.getWorkdir(),
|
||||||
});
|
workspace: this.settings.curWorkspace.getFilepath(),
|
||||||
|
});
|
||||||
|
}, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateSettings() {
|
updateSettings() {
|
||||||
|
|||||||
Reference in new issue
Block a user