feat:文件正常打开
This commit is contained in:
parent
00b381ba86
commit
b7ac57f6a8
11
main.js
11
main.js
|
@ -19,6 +19,17 @@ const createWindow = () => {
|
||||||
win.loadURL('http://localhost:3000')
|
win.loadURL('http://localhost:3000')
|
||||||
// 打开开发工具
|
// 打开开发工具
|
||||||
win.webContents.openDevTools()
|
win.webContents.openDevTools()
|
||||||
|
win.webContents.on('before-input-event', (event, input) => {
|
||||||
|
// if (input.control && input.key.toLowerCase() === 's') {
|
||||||
|
// console.log('Pressed Control+s')
|
||||||
|
// event.preventDefault()
|
||||||
|
// }
|
||||||
|
console.log('Pressed ',input.key)
|
||||||
|
if (input.key==='f5'){
|
||||||
|
console.log('Pressed f5')
|
||||||
|
win.reload()
|
||||||
|
}
|
||||||
|
})
|
||||||
Menu.setApplicationMenu(Menu.buildFromTemplate(menuRebuild(win)))
|
Menu.setApplicationMenu(Menu.buildFromTemplate(menuRebuild(win)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"electron-squirrel-startup": "^1.0.0",
|
"electron-squirrel-startup": "^1.0.0",
|
||||||
"electron-store": "^8.1.0",
|
"electron-store": "^8.1.0",
|
||||||
|
"mousetrap": "^1.6.5",
|
||||||
"node-sass": "^7.0.3"
|
"node-sass": "^7.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -18478,6 +18479,11 @@
|
||||||
"node": "*"
|
"node": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/mousetrap": {
|
||||||
|
"version": "1.6.5",
|
||||||
|
"resolved": "https://registry.npmmirror.com/mousetrap/-/mousetrap-1.6.5.tgz",
|
||||||
|
"integrity": "sha512-QNo4kEepaIBwiT8CDhP98umTetp+JNfQYBWvC1pc6/OAibuXtRcxZ58Qz8skvEHYvURne/7R8T5VoOI7rDsEUA=="
|
||||||
|
},
|
||||||
"node_modules/ms": {
|
"node_modules/ms": {
|
||||||
"version": "2.1.2",
|
"version": "2.1.2",
|
||||||
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.2.tgz",
|
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.2.tgz",
|
||||||
|
|
|
@ -51,6 +51,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"electron-squirrel-startup": "^1.0.0",
|
"electron-squirrel-startup": "^1.0.0",
|
||||||
"electron-store": "^8.1.0",
|
"electron-store": "^8.1.0",
|
||||||
|
"mousetrap": "^1.6.5",
|
||||||
"node-sass": "^7.0.3"
|
"node-sass": "^7.0.3"
|
||||||
},
|
},
|
||||||
"browser": {
|
"browser": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import React, {useEffect, useMemo, useState} from 'react';
|
import React, {useEffect, useMemo, useState} from 'react';
|
||||||
import {Input, Tree} from 'antd';
|
import {Input, Tree} from 'antd';
|
||||||
import {FolderOutlined, FileMarkdownOutlined} from '@ant-design/icons';
|
import {FolderOutlined, FileMarkdownOutlined,FileOutlined} from '@ant-design/icons';
|
||||||
import "./index.less"
|
import "./index.less"
|
||||||
const {Search} = Input;
|
const {Search} = Input;
|
||||||
import store from "../../redux/store";
|
import store from "../../redux/store";
|
||||||
|
@ -43,10 +43,11 @@ function generateChildList(fileList) {
|
||||||
const result = []
|
const result = []
|
||||||
for (let i = 0; i < fileList.length; i++) {
|
for (let i = 0; i < fileList.length; i++) {
|
||||||
const {fileName, filePath, dirFlag} = fileList[i];
|
const {fileName, filePath, dirFlag} = fileList[i];
|
||||||
|
|
||||||
result.push({
|
result.push({
|
||||||
"key": filePath,
|
"key": filePath,
|
||||||
"title": fileName,
|
"title": fileName,
|
||||||
"icon": <FolderOutlined/>,
|
"icon": dirFlag?<FolderOutlined/>:fileName.endsWith(".md")?<FileMarkdownOutlined/>:<FileOutlined />,
|
||||||
"dirFlag": dirFlag,
|
"dirFlag": dirFlag,
|
||||||
"children": []
|
"children": []
|
||||||
});
|
});
|
||||||
|
|
|
@ -26,6 +26,9 @@ import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
|
||||||
import {importFile} from "../../../utils/File"
|
import {importFile} from "../../../utils/File"
|
||||||
import {CLEAR_HISTORY_COMMAND} from "lexical";
|
import {CLEAR_HISTORY_COMMAND} from "lexical";
|
||||||
import ActionPlugin from "../../../components/ActionPlug"
|
import ActionPlugin from "../../../components/ActionPlug"
|
||||||
|
import {func} from "prop-types";
|
||||||
|
|
||||||
|
|
||||||
function Placeholder() {
|
function Placeholder() {
|
||||||
return <div className="editor-placeholder">Enter some rich text...</div>;
|
return <div className="editor-placeholder">Enter some rich text...</div>;
|
||||||
}
|
}
|
||||||
|
@ -62,8 +65,28 @@ function OnChangePlugin({ onChange }) {
|
||||||
});
|
});
|
||||||
}, [editor, onChange]);
|
}, [editor, onChange]);
|
||||||
}
|
}
|
||||||
|
function ImportFilePlugin(props) {
|
||||||
|
const [editor] = useLexicalComposerContext();
|
||||||
|
useEffect(()=>{
|
||||||
|
importFile(props.filePath).then(value=>{
|
||||||
|
console.log('value.toString()',value.toString())
|
||||||
|
const editorState = editor.parseEditorState(
|
||||||
|
JSON.stringify(JSON.parse(value.toString()).editorState)
|
||||||
|
);
|
||||||
|
editor.setEditorState(editorState);
|
||||||
|
editor.dispatchCommand(CLEAR_HISTORY_COMMAND, undefined);
|
||||||
|
}).catch(error=>
|
||||||
|
console.error(error)
|
||||||
|
)
|
||||||
|
},[])
|
||||||
|
}
|
||||||
|
|
||||||
export default function Hlexical() {
|
// 从字符串化 JSON 设置编辑器状态
|
||||||
|
// const editorState = editor.parseEditorState(editorStateJSONString);
|
||||||
|
// editor.setEditorState(editorState);
|
||||||
|
|
||||||
|
export default function Hlexical(props) {
|
||||||
|
console.log("this.props.filePath:",props.filePath)
|
||||||
const [editorState, setEditorState] = useState();
|
const [editorState, setEditorState] = useState();
|
||||||
function onChange(editorState) {
|
function onChange(editorState) {
|
||||||
// Call toJSON on the EditorState object, which produces a serialization safe string
|
// Call toJSON on the EditorState object, which produces a serialization safe string
|
||||||
|
@ -72,7 +95,6 @@ export default function Hlexical() {
|
||||||
// However, we still have a JavaScript object, so we need to convert it to an actual string with JSON.stringify
|
// However, we still have a JavaScript object, so we need to convert it to an actual string with JSON.stringify
|
||||||
setEditorState(JSON.stringify(editorStateJSON));
|
setEditorState(JSON.stringify(editorStateJSON));
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LexicalComposer initialConfig={editorConfig}>
|
<LexicalComposer initialConfig={editorConfig}>
|
||||||
<div className="editor-container">
|
<div className="editor-container">
|
||||||
|
@ -95,7 +117,8 @@ export default function Hlexical() {
|
||||||
{/*<ListMaxIndentLevelPlugin maxDepth={7} />*/}
|
{/*<ListMaxIndentLevelPlugin maxDepth={7} />*/}
|
||||||
<MarkdownShortcutPlugin transformers={TRANSFORMERS} />
|
<MarkdownShortcutPlugin transformers={TRANSFORMERS} />
|
||||||
<OnChangePlugin onChange={onChange}/>
|
<OnChangePlugin onChange={onChange}/>
|
||||||
<ActionPlugin/>
|
<ImportFilePlugin filePath={props.filePath}/>
|
||||||
|
{/*<ActionPlugin/>*/}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</LexicalComposer>
|
</LexicalComposer>
|
||||||
|
|
|
@ -12,6 +12,7 @@ import ItemTree from "../../components/ItemTree";
|
||||||
import './index.less'
|
import './index.less'
|
||||||
import store from "../../redux/store";
|
import store from "../../redux/store";
|
||||||
import {isEmpty} from "../../utils/ObjectUtils";
|
import {isEmpty} from "../../utils/ObjectUtils";
|
||||||
|
|
||||||
const {Header, Sider, Content} = Layout;
|
const {Header, Sider, Content} = Layout;
|
||||||
const Note = () => {
|
const Note = () => {
|
||||||
const [collapsed, setCollapsed] = useState(false);
|
const [collapsed, setCollapsed] = useState(false);
|
||||||
|
@ -25,11 +26,14 @@ const Note = () => {
|
||||||
store.subscribe(() => {
|
store.subscribe(() => {
|
||||||
const openFile = store.getState().clickFileMessage.data;
|
const openFile = store.getState().clickFileMessage.data;
|
||||||
console.log("store.getState().clickFileMessage.data:",openFile,items)
|
console.log("store.getState().clickFileMessage.data:",openFile,items)
|
||||||
|
if (!isEmpty(openFile)&&activeKey!==openFile.filePath){
|
||||||
|
setActiveKey(openFile.filePath)
|
||||||
|
}
|
||||||
if (items.filter(fileItem => fileItem.key === openFile.filePath).length === 0&& !isEmpty(openFile)) {
|
if (items.filter(fileItem => fileItem.key === openFile.filePath).length === 0&& !isEmpty(openFile)) {
|
||||||
setItems([...items,
|
setItems([...items,
|
||||||
{
|
{
|
||||||
label: openFile.fileName,
|
label: openFile.fileName,
|
||||||
children: <div className="HlexicalName"><Hlexical/></div>,
|
children: <div className="HlexicalName"><Hlexical filePath={openFile.filePath} /></div>,
|
||||||
key: openFile.filePath,
|
key: openFile.filePath,
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
|
@ -4,5 +4,9 @@ import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
|
||||||
const fs = window.require("fs").promises
|
const fs = window.require("fs").promises
|
||||||
|
|
||||||
export async function importFile(pathName) {
|
export async function importFile(pathName) {
|
||||||
return await fs.readFile(pathName)
|
return await fs.readFile(pathName)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function overWriteFile(filePath) {
|
||||||
|
fs.writeFile(filePath,)
|
||||||
}
|
}
|
Loading…
Reference in New Issue