open file & workspace path

This commit is contained in:
zhandouxiaojiji committed 2020-10-14 15:08:36 +08:00
1 parent 84e1e376b9
commit 001d122e5a
5 files changed
+46 -16

No files matched your search

-3
View File
@@ -1,3 +0,0 @@
export default {
MAIN_OPEN_FILE: "MAIN_OPEN_FILE",
}
+4
View File
@@ -0,0 +1,4 @@
export default {
OPEN_FILE: "OPEN_FILE",
OPEN_WORKSPACE: "OPEN_WORKSPACE",
}
+17 -5
View File
@@ -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' },
{
+2 -2
View File
@@ -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",
+23 -6
View File
@@ -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 (
<DatePicker />
<div>
<div>
当前目录:{this.state.workspace}
</div>
<div>
当前文件:{this.state.filepaths.join("\n")}
</div>
</div>
)
}
};