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

+9 -6
View File
@@ -142,11 +142,12 @@ export default class AppMenu {
private createWorkspaceMenu() { private createWorkspaceMenu() {
const openWorkspace = (path: string) => { const openWorkspace = (path: string) => {
this.settings.curWorkspace.setFilepath(path); const curWorkspace = this.settings.curWorkspace;
this.settings.curWorkspace.load(); curWorkspace.setFilepath(path);
curWorkspace.load();
this.settings.pushRecentWorkspace(path); this.settings.pushRecentWorkspace(path);
this.mainProcess.rebuildMenu(); 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 = () => { const saveToNewPath = () => {
(async () => { (async () => {
@@ -159,6 +160,7 @@ export default class AppMenu {
if (!res.canceled) { if (!res.canceled) {
this.settings.curWorkspace.setFilepath(res.filePath); this.settings.curWorkspace.setFilepath(res.filePath);
this.settings.curWorkspace.save(); this.settings.curWorkspace.save();
openWorkspace(res.filePath);
} }
})(); })();
} }
@@ -225,10 +227,11 @@ export default class AppMenu {
properties: ['openDirectory'] properties: ['openDirectory']
}); });
if (res.filePaths.length > 0) { if (res.filePaths.length > 0) {
const curWorkspace = this.settings.curWorkspace;
const path = res.filePaths[0]; const path = res.filePaths[0];
this.settings.curWorkspace.setWorkdir(path); curWorkspace.setWorkdir(path);
this.settings.curWorkspace.save(); curWorkspace.save();
this.webContents.send(MainEventType.OPEN_DIR, path); this.webContents.send(MainEventType.OPEN_DIR, path, curWorkspace.getFilepath());
} }
})(); })();
} }
+15 -15
View File
@@ -13,7 +13,7 @@ export interface TreeFile {
} }
export interface PropertiesProps { export interface PropertiesProps {
workspace: string; workdir: string;
onOpenTree: (path: string) => void; onOpenTree: (path: string) => void;
} }
@@ -26,11 +26,11 @@ export default class Properties extends Component<PropertiesProps> {
treeList: [] treeList: []
}; };
curWorkspace: string = ''; curWorkdir: string = '';
shouldComponentUpdate(nextProps: PropertiesProps) { shouldComponentUpdate(nextProps: PropertiesProps) {
const shouldUpdate = this.curWorkspace != nextProps.workspace; const shouldUpdate = this.curWorkdir != nextProps.workdir;
this.curWorkspace = nextProps.workspace; this.curWorkdir = nextProps.workdir;
return shouldUpdate; return shouldUpdate;
} }
@@ -41,28 +41,28 @@ export default class Properties extends Component<PropertiesProps> {
this.forceUpdate(); this.forceUpdate();
}); });
var workspace = this.props.workspace; var workdir = this.props.workdir;
if (workspace == '') { if (workdir == '') {
return; return;
} }
this.setState({ treeList: this.getTreeList(workspace) }); this.setState({ treeList: this.getTreeList(workdir) });
} }
getTreeList(workspace: string) { getTreeList(workdir: string) {
if (workspace == '' || !fs.existsSync(workspace)) { if (workdir == '' || !fs.existsSync(workdir)) {
console.log("workspace not exist", workspace); console.log("workdir not exist", workdir);
return []; return [];
} }
const files = fs.readdirSync(workspace); const files = fs.readdirSync(workdir);
const list: TreeFile[] = []; const list: TreeFile[] = [];
files.forEach((filename) => { files.forEach((filename) => {
const stat = fs.statSync(path.join(workspace, filename)) const stat = fs.statSync(path.join(workdir, filename))
if (stat.isFile()) { if (stat.isFile()) {
var name = filename.slice(0, -5) var name = filename.slice(0, -5)
list.push({ list.push({
name, name,
path: workspace + '/' + name + '.json' path: workdir + '/' + name + '.json'
}); });
} }
}) })
@@ -71,8 +71,8 @@ export default class Properties extends Component<PropertiesProps> {
render() { render() {
console.log("render Properties"); console.log("render Properties");
const { onOpenTree, workspace } = this.props; const { onOpenTree, workdir } = this.props;
const treeList = this.getTreeList(workspace); const treeList = this.getTreeList(workdir);
return ( return (
<div> <div>
<Search <Search
+13 -8
View File
@@ -24,11 +24,13 @@ const { TabPane } = Tabs;
interface MainState { interface MainState {
workdir: string; workdir: string;
workspace: string;
} }
export default class Main extends Component { export default class Main extends Component {
state: MainState = { state: MainState = {
workdir: '', workdir: '',
workspace: '',
} }
settings: Settings; settings: Settings;
@@ -44,14 +46,17 @@ export default class Main extends Component {
this.setState({ curPath: path }); this.setState({ curPath: path });
}); });
ipcRenderer.on(MainEventType.OPEN_DIR, (event: any, workdir: any) => { ipcRenderer.on(MainEventType.OPEN_DIR, (event: any, workdir: any, workspace: string) => {
console.log("on open workspace", workdir); console.log("on open workspace", workspace);
document.title = workdir; document.title = workspace;
this.setState({ workdir }); this.setState({ workdir, workspace });
}); });
console.log("workdir", this.settings.curWorkspace.getWorkdir()); 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() { updateSettings() {
@@ -60,13 +65,13 @@ export default class Main extends Component {
render() { render() {
console.log("render main"); console.log("render main");
const { workdir } = this.state; const { workdir, workspace } = this.state;
document.title = `行为树编辑器 - ${workdir}`; document.title = `行为树编辑器 - ${workspace}`;
return ( return (
<Layout className="body"> <Layout className="body">
<Sider className="sider" width={250}> <Sider className="sider" width={250}>
<Properties <Properties
workspace={this.state.workdir} workdir={workdir}
onOpenTree={(path) => { onOpenTree={(path) => {
this.tabs.openFile(path); this.tabs.openFile(path);
}} }}