diff --git a/common/EventType.ts b/common/EventType.ts
deleted file mode 100644
index c59a7dd..0000000
--- a/common/EventType.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export default {
- MAIN_OPEN_FILE: "MAIN_OPEN_FILE",
-}
\ No newline at end of file
diff --git a/common/MainEventType.ts b/common/MainEventType.ts
new file mode 100644
index 0000000..09a8011
--- /dev/null
+++ b/common/MainEventType.ts
@@ -0,0 +1,4 @@
+export default {
+ OPEN_FILE: "OPEN_FILE",
+ OPEN_WORKSPACE: "OPEN_WORKSPACE",
+}
\ No newline at end of file
diff --git a/main-process/AppMenu.ts b/main-process/AppMenu.ts
index bdd3efa..21ae9c3 100644
--- a/main-process/AppMenu.ts
+++ b/main-process/AppMenu.ts
@@ -1,5 +1,5 @@
import { BrowserView, Menu, app, shell, dialog, BrowserWindow, MenuItem } from 'electron';
-import EventType from '../common/EventType';
+import MainEventType from '../common/MainEventType';
export function initMenu(mainWindow: BrowserWindow) {
const menu: Menu = new Menu();
@@ -12,17 +12,29 @@ export function initMenu(mainWindow: BrowserWindow) {
click: () => {
(async () => {
const res = await dialog.showOpenDialog({
- properties: ['openFile', 'openDirectory']
+ properties: ['openFile'],
+ filters: [
+ {name: "Json", extensions:['json']}
+ ]
});
console.log("open res", res);
- mainWindow.webContents.send(EventType.MAIN_OPEN_FILE, res);
+ mainWindow.webContents.send(MainEventType.OPEN_FILE, res.filePaths[0]);
})();
}
},
{
label: "打开目录",
- accelerator: "Ctrl+Shift+O"
-
+ accelerator: "Ctrl+Shift+O",
+ click: () => {
+ (async () => {
+ const res = await dialog.showOpenDialog({
+ properties: ['openDirectory']
+ });
+ if (res.filePaths.length > 0) {
+ mainWindow.webContents.send(MainEventType.OPEN_WORKSPACE, res.filePaths[0]);
+ }
+ })();
+ }
},
{ type: 'separator' },
{
diff --git a/package.json b/package.json
index 81fed88..734e531 100644
--- a/package.json
+++ b/package.json
@@ -1,12 +1,12 @@
{
"name": "behavior3editor",
- "version": "0.0.1",
+ "version": "0.0.2",
"description": "行为树编辑器",
"main": "./dist/main.js",
"scripts": {
"prestart": "webpack --config webpack.config.js",
"start": "electron .",
- "build": "electron-packager ./ behavior3editor --platform=win32 --arch=x64 --out=./build"
+ "build": "electron-packager ./ behavior3editor --platform=win32 --arch=x64 --out=./build --overwrite"
},
"repository": {
"type": "git",
diff --git a/render-process/Editor/index.tsx b/render-process/Editor/index.tsx
index 637a844..42b898a 100644
--- a/render-process/Editor/index.tsx
+++ b/render-process/Editor/index.tsx
@@ -1,26 +1,43 @@
import React, { Component } from "react";
import { DatePicker } from 'antd';
import { ipcRenderer } from 'electron';
-import EventType from "../../common/EventType";
+import MainEventType from "../../common/MainEventType";
interface EditorState {
workspace: string;
+ filepaths: string[];
}
export default class Editor extends Component {
state: EditorState = {
- workspace: ''
+ workspace: '',
+ filepaths: [],
}
componentDidMount() {
- ipcRenderer.on(EventType.MAIN_OPEN_FILE, (event: any, path: any) => {
- console.log("on", event, path);
- })
+ ipcRenderer.on(MainEventType.OPEN_FILE, (event: any, path: any) => {
+ console.log("on open file", path);
+ const filepaths = this.state.filepaths;
+ filepaths.push(path);
+ this.setState({filepaths});
+ });
+
+ ipcRenderer.on(MainEventType.OPEN_WORKSPACE, (event: any, workspace: any) => {
+ console.log("on open workspace", workspace);
+ this.setState({workspace});
+ });
}
render() {
return (
-