diff --git a/electron/main/index.ts b/electron/main/index.ts index d161377..4d1f51b 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -109,7 +109,6 @@ if (!app.requestSingleInstanceLock()) { interface Workspace { projectPath?: string; - files: { path: string; active: boolean }[]; window: BrowserWindow; } @@ -244,27 +243,7 @@ ipcMain.handle("open-win", (e, arg) => { ipcMain.handle("ready-to-show", (e) => { const workspace = windows.find((v) => v.window.webContents.id === e.sender.id); if (workspace && workspace.projectPath) { - workspace.window.webContents.send("open-project", workspace.projectPath, workspace.files); - } -}); - -ipcMain.handle("open-file", (e, path: string) => { - const workspace = windows.find((v) => v.window.webContents.id === e.sender.id); - if (workspace) { - const entry = workspace.files.find((v) => v.path === path); - workspace.files.forEach((v) => (v.active = false)); - if (entry) { - entry.active = true; - } else { - workspace.files.push({ path, active: true }); - } - } -}); - -ipcMain.handle("close-file", (e, path: string) => { - const workspace = windows.find((v) => v.window.webContents.id === e.sender.id); - if (workspace) { - workspace.files = workspace.files.filter((v) => v.path !== path); + workspace.window.webContents.send("open-project", workspace.projectPath); } }); diff --git a/src/components/editor.tsx b/src/components/editor.tsx index dee4fb6..2577d22 100644 --- a/src/components/editor.tsx +++ b/src/components/editor.tsx @@ -144,7 +144,7 @@ export const Editor: FC = ({ onChange, data: editor, ...props }) => e.preventDefault(); e.stopImmediatePropagation(); e.stopPropagation(); - editor.dispatch(hotkeyMap[key]); + editor.dispatch?.(hotkeyMap[key]); } ); @@ -153,7 +153,7 @@ export const Editor: FC = ({ onChange, data: editor, ...props }) => return; } e.stopPropagation(); - editor.dispatch(hotkeyMap[key]); + editor.dispatch?.(hotkeyMap[key]); }); const searchInputRef = useRef(null); @@ -493,7 +493,7 @@ export const Editor: FC = ({ onChange, data: editor, ...props }) => )} editor.dispatch(info.key as EditEvent) }} + menu={{ items: menuItems, onClick: (info) => editor.dispatch?.(info.key as EditEvent) }} trigger={["contextMenu"]} >
diff --git a/src/components/explorer.tsx b/src/components/explorer.tsx index ef09d8a..4ca2ce9 100644 --- a/src/components/explorer.tsx +++ b/src/components/explorer.tsx @@ -105,11 +105,11 @@ const renameFile = (oldPath: string, newPath: string) => { for (const editor of workspace.editors) { if (isDirectory) { if (editor.path.startsWith(oldPath)) { - editor.dispatch("rename", editor.path.replace(oldPath, newPath)); + editor.dispatch?.("rename", editor.path.replace(oldPath, newPath)); } } else { if (editor.path === oldPath) { - editor.dispatch("rename", newPath); + editor.dispatch?.("rename", newPath); } } } @@ -406,12 +406,12 @@ const doMoveFile = (path: string, newPath: string) => { fs.renameSync(path, newPath); for (const editor of workspace.editors) { if (editor.path.startsWith(path)) { - editor.dispatch("rename", destDir + "/" + Path.basename(editor.path)); + editor.dispatch?.("rename", destDir + "/" + Path.basename(editor.path)); } console.log("editor move", editor.path === newPath, editor.path, newPath); if (editor.path.startsWith(newPath)) { console.log("editor reload", editor.path === newPath, editor.path, newPath); - editor.dispatch("refresh"); + editor.dispatch?.("refresh"); } } }; diff --git a/src/components/inspector.tsx b/src/components/inspector.tsx index 4232276..965b506 100644 --- a/src/components/inspector.tsx +++ b/src/components/inspector.tsx @@ -105,7 +105,7 @@ const VarDeclItem: FC = ({ name, onChange, onRemove, disabled, ... borderTop: "1px solid #3d506c", borderBottom: "1px solid #3d506c", }} - onClick={() => value.name && editing?.dispatch("clickVar", value.name)} + onClick={() => value.name && editing?.dispatch?.("clickVar", value.name)} > {value?.count ?? 0} @@ -254,7 +254,7 @@ const TreeInspector: FC = () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const finish = (values: any) => { - workspace.editing?.dispatch("updateTree", { + workspace.editing?.dispatch?.("updateTree", { name: values.name, desc: values.desc, export: values.export, @@ -812,7 +812,7 @@ const NodeInspector: FC = () => { data.output = []; } - workspace.editing?.dispatch("updateNode", { + workspace.editing?.dispatch?.("updateNode", { data: data, } as EditNode); }; @@ -1500,7 +1500,7 @@ const NodeInspector: FC = () => { type="primary" style={{ width: "100%" }} icon={} - onClick={() => workspace.editing?.dispatch("editSubtree")} + onClick={() => workspace.editing?.dispatch?.("editSubtree")} > {t("editSubtree")} diff --git a/src/components/menu.tsx b/src/components/menu.tsx index e3ec4e5..1d7386b 100644 --- a/src/components/menu.tsx +++ b/src/components/menu.tsx @@ -29,8 +29,8 @@ const getFocusedWebContents = () => { return BrowserWindow.getFocusedWindow()?.webContents; }; -ipcRenderer.on("open-project", (_, dir, files) => { - useWorkspace.getState().init(dir, files); +ipcRenderer.on("open-project", (_, dir) => { + useWorkspace.getState().init(dir); }); ipcRenderer.on("refresh-app-men", () => { diff --git a/src/components/workspace.tsx b/src/components/workspace.tsx index 53352fa..713644f 100644 --- a/src/components/workspace.tsx +++ b/src/components/workspace.tsx @@ -80,12 +80,12 @@ export const Workspace: FC = () => { useKeyDown(Hotkey.SearchNode, keysRef, (event) => { event.preventDefault(); - workspace.editing?.dispatch("searchNode"); + workspace.editing?.dispatch?.("searchNode"); }); useKeyDown(Hotkey.JumpNode, keysRef, (event) => { event.preventDefault(); - workspace.editing?.dispatch("jumpNode"); + workspace.editing?.dispatch?.("jumpNode"); }); useEffect(() => { @@ -118,7 +118,7 @@ export const Workspace: FC = () => { type="primary" onClick={() => { editor.alertReload = false; - editor.dispatch("reload"); + editor.dispatch?.("reload"); alert.destroy(); keysRef.current?.focus(); setShowingAlert(false); @@ -164,7 +164,7 @@ export const Workspace: FC = () => {