test event
This commit is contained in:
1 parent
aa5a0fc62e
commit
69a284cc16
5 files changed
+37
-11
No files matched your search
@@ -8,7 +8,7 @@ let createWindow = function () {
|
|||||||
width: 1280,
|
width: 1280,
|
||||||
height: 800,
|
height: 800,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
// nodeIntegration: true
|
nodeIntegration: true
|
||||||
}
|
}
|
||||||
// fullscreenable:false,
|
// fullscreenable:false,
|
||||||
// maximizable:false
|
// maximizable:false
|
||||||
@@ -18,6 +18,7 @@ let createWindow = function () {
|
|||||||
mainWindow.on('closed', function () {
|
mainWindow.on('closed', function () {
|
||||||
mainWindow = null
|
mainWindow = null
|
||||||
});
|
});
|
||||||
|
initMenu(mainWindow);
|
||||||
}
|
}
|
||||||
app.on('ready', createWindow)
|
app.on('ready', createWindow)
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
@@ -31,5 +32,3 @@ app.on('activate', () => {
|
|||||||
createWindow()
|
createWindow()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
initMenu();
|
|
||||||
+16
-6
@@ -1,20 +1,30 @@
|
|||||||
import { BrowserView, Menu, app, shell, dialog, BrowserWindow, MenuItem } from 'electron';
|
import { BrowserView, Menu, app, shell, dialog, BrowserWindow, MenuItem } from 'electron';
|
||||||
|
import EventType from './EventType';
|
||||||
|
|
||||||
export function initMenu() {
|
export function initMenu(mainWindow: BrowserWindow) {
|
||||||
const menu: Menu = new Menu();
|
const menu: Menu = new Menu();
|
||||||
const fileMenu: MenuItem = new MenuItem({
|
const fileMenu: MenuItem = new MenuItem({
|
||||||
label: "行为树",
|
label: "行为树",
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
label: "打开文件",
|
label: "打开文件",
|
||||||
accelerator: "Ctrl+O"
|
accelerator: "Ctrl+O",
|
||||||
|
click: () => {
|
||||||
|
(async () => {
|
||||||
|
const res = await dialog.showOpenDialog({
|
||||||
|
properties: ['openFile', 'openDirectory']
|
||||||
|
});
|
||||||
|
console.log("open res", res);
|
||||||
|
mainWindow.webContents.send(EventType.MAIN_OPEN_FILE, res);
|
||||||
|
})();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "打开目录",
|
label: "打开目录",
|
||||||
accelerator: "Ctrl+Shift+O"
|
accelerator: "Ctrl+Shift+O"
|
||||||
|
|
||||||
},
|
},
|
||||||
{ type: 'separator'},
|
{ type: 'separator' },
|
||||||
{
|
{
|
||||||
label: "最近打开",
|
label: "最近打开",
|
||||||
submenu: []
|
submenu: []
|
||||||
@@ -22,11 +32,11 @@ export function initMenu() {
|
|||||||
{
|
{
|
||||||
label: "最近目录",
|
label: "最近目录",
|
||||||
submenu: [
|
submenu: [
|
||||||
{label: "master"},
|
{ label: "master" },
|
||||||
{label: "分支0908"},
|
{ label: "分支0908" },
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{ type: 'separator'},
|
{ type: 'separator' },
|
||||||
{
|
{
|
||||||
label: "关闭",
|
label: "关闭",
|
||||||
click: () => {
|
click: () => {
|
||||||
|
|||||||
@@ -1,7 +1,23 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { DatePicker } from 'antd';
|
import { DatePicker } from 'antd';
|
||||||
|
import { ipcRenderer } from 'electron';
|
||||||
|
import EventType from "../EventType";
|
||||||
|
|
||||||
|
interface EditorState {
|
||||||
|
workspace: string;
|
||||||
|
}
|
||||||
|
|
||||||
export default class Editor extends Component {
|
export default class Editor extends Component {
|
||||||
|
state: EditorState = {
|
||||||
|
workspace: ''
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
ipcRenderer.on(EventType.MAIN_OPEN_FILE, (event: any, path: any) => {
|
||||||
|
console.log("on", event, path);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<DatePicker />
|
<DatePicker />
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export default {
|
||||||
|
MAIN_OPEN_FILE: "MAIN_OPEN_FILE",
|
||||||
|
}
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as ReactDOM from "react-dom";
|
import * as ReactDOM from "react-dom";
|
||||||
import Hello from "./components/Hello";
|
|
||||||
import Editor from "./Editor";
|
import Editor from "./Editor";
|
||||||
import 'antd/dist/antd.dark.css';
|
import 'antd/dist/antd.dark.css';
|
||||||
import './index.css';
|
import './index.css';
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<Editor />,
|
<Editor />,
|
||||||
// <div className="test">hello!!!!!</div>,
|
|
||||||
document.getElementById('root') as HTMLElement
|
document.getElementById('root') as HTMLElement
|
||||||
);
|
);
|
||||||
Reference in new issue
Block a user