From 6f9ddce97464d058fcf5c3643aa5b3ef45072b00 Mon Sep 17 00:00:00 2001 From: zhandouxiaojiji Date: Thu, 12 Nov 2020 15:16:39 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=E5=B7=A5=E4=BD=9C=E5=8C=BA=E5=8F=A6?= =?UTF-8?q?=E5=AD=98=E4=B8=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main-process/AppMenu.ts | 15 +++++++++------ render-process/Properties.tsx | 30 +++++++++++++++--------------- render-process/index.tsx | 21 +++++++++++++-------- 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/main-process/AppMenu.ts b/main-process/AppMenu.ts index a789a37..e87975a 100644 --- a/main-process/AppMenu.ts +++ b/main-process/AppMenu.ts @@ -142,11 +142,12 @@ export default class AppMenu { private createWorkspaceMenu() { const openWorkspace = (path: string) => { - this.settings.curWorkspace.setFilepath(path); - this.settings.curWorkspace.load(); + const curWorkspace = this.settings.curWorkspace; + curWorkspace.setFilepath(path); + curWorkspace.load(); this.settings.pushRecentWorkspace(path); this.mainProcess.rebuildMenu(); - this.webContents.send(MainEventType.OPEN_DIR, this.settings.curWorkspace.getWorkdir()); + this.webContents.send(MainEventType.OPEN_DIR, curWorkspace.getWorkdir(), curWorkspace.getFilepath()); }; const saveToNewPath = () => { (async () => { @@ -159,6 +160,7 @@ export default class AppMenu { if (!res.canceled) { this.settings.curWorkspace.setFilepath(res.filePath); this.settings.curWorkspace.save(); + openWorkspace(res.filePath); } })(); } @@ -225,10 +227,11 @@ export default class AppMenu { properties: ['openDirectory'] }); if (res.filePaths.length > 0) { + const curWorkspace = this.settings.curWorkspace; const path = res.filePaths[0]; - this.settings.curWorkspace.setWorkdir(path); - this.settings.curWorkspace.save(); - this.webContents.send(MainEventType.OPEN_DIR, path); + curWorkspace.setWorkdir(path); + curWorkspace.save(); + this.webContents.send(MainEventType.OPEN_DIR, path, curWorkspace.getFilepath()); } })(); } diff --git a/render-process/Properties.tsx b/render-process/Properties.tsx index fff908f..bdd3ded 100644 --- a/render-process/Properties.tsx +++ b/render-process/Properties.tsx @@ -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 { 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 { 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 { 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 (
{ - 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 ( { this.tabs.openFile(path); }}