bugfix:工作区另存为

This commit is contained in:
zhandouxiaojiji committed 2020-11-12 15:16:39 +08:00
1 parent 1d25e6c22e
commit 6f9ddce974
3 files changed
+37 -29

No files matched your search

+15 -15
View File
@@ -13,7 +13,7 @@ export interface TreeFile {
}
export interface PropertiesProps {
workspace: string;
workdir: string;
onOpenTree: (path: string) => void;
}
@@ -26,11 +26,11 @@ export default class Properties extends Component<PropertiesProps> {
treeList: []
};
curWorkspace: string = '';
curWorkdir: string = '';
shouldComponentUpdate(nextProps: PropertiesProps) {
const shouldUpdate = this.curWorkspace != nextProps.workspace;
this.curWorkspace = nextProps.workspace;
const shouldUpdate = this.curWorkdir != nextProps.workdir;
this.curWorkdir = nextProps.workdir;
return shouldUpdate;
}
@@ -41,28 +41,28 @@ export default class Properties extends Component<PropertiesProps> {
this.forceUpdate();
});
var workspace = this.props.workspace;
if (workspace == '') {
var workdir = this.props.workdir;
if (workdir == '') {
return;
}
this.setState({ treeList: this.getTreeList(workspace) });
this.setState({ treeList: this.getTreeList(workdir) });
}
getTreeList(workspace: string) {
if (workspace == '' || !fs.existsSync(workspace)) {
console.log("workspace not exist", workspace);
getTreeList(workdir: string) {
if (workdir == '' || !fs.existsSync(workdir)) {
console.log("workdir not exist", workdir);
return [];
}
const files = fs.readdirSync(workspace);
const files = fs.readdirSync(workdir);
const list: TreeFile[] = [];
files.forEach((filename) => {
const stat = fs.statSync(path.join(workspace, filename))
const stat = fs.statSync(path.join(workdir, filename))
if (stat.isFile()) {
var name = filename.slice(0, -5)
list.push({
name,
path: workspace + '/' + name + '.json'
path: workdir + '/' + name + '.json'
});
}
})
@@ -71,8 +71,8 @@ export default class Properties extends Component<PropertiesProps> {
render() {
console.log("render Properties");
const { onOpenTree, workspace } = this.props;
const treeList = this.getTreeList(workspace);
const { onOpenTree, workdir } = this.props;
const treeList = this.getTreeList(workdir);
return (
<div>
<Search
+13 -8
View File
@@ -24,11 +24,13 @@ const { TabPane } = Tabs;
interface MainState {
workdir: string;
workspace: string;
}
export default class Main extends Component {
state: MainState = {
workdir: '',
workspace: '',
}
settings: Settings;
@@ -44,14 +46,17 @@ export default class Main extends Component {
this.setState({ curPath: path });
});
ipcRenderer.on(MainEventType.OPEN_DIR, (event: any, workdir: any) => {
console.log("on open workspace", workdir);
document.title = workdir;
this.setState({ workdir });
ipcRenderer.on(MainEventType.OPEN_DIR, (event: any, workdir: any, workspace: string) => {
console.log("on open workspace", workspace);
document.title = workspace;
this.setState({ workdir, workspace });
});
console.log("workdir", this.settings.curWorkspace.getWorkdir());
this.setState({ workdir: this.settings.curWorkspace.getWorkdir() });
this.setState({
workdir: this.settings.curWorkspace.getWorkdir(),
workspace: this.settings.curWorkspace.getFilepath(),
});
}
updateSettings() {
@@ -60,13 +65,13 @@ export default class Main extends Component {
render() {
console.log("render main");
const { workdir } = this.state;
document.title = `行为树编辑器 - ${workdir}`;
const { workdir, workspace } = this.state;
document.title = `行为树编辑器 - ${workspace}`;
return (
<Layout className="body">
<Sider className="sider" width={250}>
<Properties
workspace={this.state.workdir}
workdir={workdir}
onOpenTree={(path) => {
this.tabs.openFile(path);
}}