store open files in history

This commit is contained in:
codetypes committed 2025-04-15 10:36:08 +08:00
1 parent 5fb19c5c08
commit 3b1091cf87
8 files changed
+119 -62

No files matched your search

+3 -3
View File
@@ -144,7 +144,7 @@ export const Editor: FC<EditorProps> = ({ 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<EditorProps> = ({ onChange, data: editor, ...props }) =>
return;
}
e.stopPropagation();
editor.dispatch(hotkeyMap[key]);
editor.dispatch?.(hotkeyMap[key]);
});
const searchInputRef = useRef<InputRef>(null);
@@ -493,7 +493,7 @@ export const Editor: FC<EditorProps> = ({ onChange, data: editor, ...props }) =>
)}
<Dropdown
menu={{ items: menuItems, onClick: (info) => editor.dispatch(info.key as EditEvent) }}
menu={{ items: menuItems, onClick: (info) => editor.dispatch?.(info.key as EditEvent) }}
trigger={["contextMenu"]}
>
<div tabIndex={-1} style={{ width: "100%", height: "100%" }} ref={graphRef} />
+4 -4
View File
@@ -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");
}
}
};
+4 -4
View File
@@ -105,7 +105,7 @@ const VarDeclItem: FC<VarItemProps> = ({ 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)}
>
<AimOutlined />
<span style={{ marginLeft: 4 }}>{value?.count ?? 0}</span>
@@ -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={<EditOutlined />}
onClick={() => workspace.editing?.dispatch("editSubtree")}
onClick={() => workspace.editing?.dispatch?.("editSubtree")}
>
{t("editSubtree")}
</Button>
+2 -2
View File
@@ -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", () => {
+5 -5
View File
@@ -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 = () => {
<Button
type="primary"
onClick={() => {
editor.dispatch("save");
editor.dispatch?.("save");
workspace.close(editor.path);
alert.destroy();
keysRef.current?.focus();
@@ -232,7 +232,7 @@ export const Workspace: FC = () => {
<Button
type="primary"
onClick={() => {
unsaves.forEach((editor) => editor.dispatch("save"));
unsaves.forEach((editor) => editor.dispatch?.("save"));
alert.destroy();
window.close();
setShowingAlert(false);