open file & workspace path
This commit is contained in:
1 parent
84e1e376b9
commit
001d122e5a
5 files changed
+46
-16
No files matched your search
@@ -1,3 +0,0 @@
|
|||||||
export default {
|
|
||||||
MAIN_OPEN_FILE: "MAIN_OPEN_FILE",
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export default {
|
||||||
|
OPEN_FILE: "OPEN_FILE",
|
||||||
|
OPEN_WORKSPACE: "OPEN_WORKSPACE",
|
||||||
|
}
|
||||||
+17
-5
@@ -1,5 +1,5 @@
|
|||||||
import { BrowserView, Menu, app, shell, dialog, BrowserWindow, MenuItem } from 'electron';
|
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) {
|
export function initMenu(mainWindow: BrowserWindow) {
|
||||||
const menu: Menu = new Menu();
|
const menu: Menu = new Menu();
|
||||||
@@ -12,17 +12,29 @@ export function initMenu(mainWindow: BrowserWindow) {
|
|||||||
click: () => {
|
click: () => {
|
||||||
(async () => {
|
(async () => {
|
||||||
const res = await dialog.showOpenDialog({
|
const res = await dialog.showOpenDialog({
|
||||||
properties: ['openFile', 'openDirectory']
|
properties: ['openFile'],
|
||||||
|
filters: [
|
||||||
|
{name: "Json", extensions:['json']}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
console.log("open res", res);
|
console.log("open res", res);
|
||||||
mainWindow.webContents.send(EventType.MAIN_OPEN_FILE, res);
|
mainWindow.webContents.send(MainEventType.OPEN_FILE, res.filePaths[0]);
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "打开目录",
|
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' },
|
{ type: 'separator' },
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "behavior3editor",
|
"name": "behavior3editor",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"description": "行为树编辑器",
|
"description": "行为树编辑器",
|
||||||
"main": "./dist/main.js",
|
"main": "./dist/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prestart": "webpack --config webpack.config.js",
|
"prestart": "webpack --config webpack.config.js",
|
||||||
"start": "electron .",
|
"start": "electron .",
|
||||||
"build": "electron-packager ./ behavior3editor --platform=win32 --arch=x64 --out=./build"
|
"build": "electron-packager ./ behavior3editor --platform=win32 --arch=x64 --out=./build --overwrite"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -1,26 +1,43 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { DatePicker } from 'antd';
|
import { DatePicker } from 'antd';
|
||||||
import { ipcRenderer } from 'electron';
|
import { ipcRenderer } from 'electron';
|
||||||
import EventType from "../../common/EventType";
|
import MainEventType from "../../common/MainEventType";
|
||||||
|
|
||||||
interface EditorState {
|
interface EditorState {
|
||||||
workspace: string;
|
workspace: string;
|
||||||
|
filepaths: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Editor extends Component {
|
export default class Editor extends Component {
|
||||||
state: EditorState = {
|
state: EditorState = {
|
||||||
workspace: ''
|
workspace: '',
|
||||||
|
filepaths: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
ipcRenderer.on(EventType.MAIN_OPEN_FILE, (event: any, path: any) => {
|
ipcRenderer.on(MainEventType.OPEN_FILE, (event: any, path: any) => {
|
||||||
console.log("on", event, path);
|
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() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<DatePicker />
|
<div>
|
||||||
|
<div>
|
||||||
|
当前目录:{this.state.workspace}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
当前文件:{this.state.filepaths.join("\n")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user