diff --git a/package-lock.json b/package-lock.json index aaa6f35..e53605a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "zustand": "^5.0.3" }, "devDependencies": { + "@types/electron": "^1.4.38", "@types/node": "^16.11.6", "@types/react": "^19.0.4", "@types/react-dom": "^19.0.2", @@ -671,6 +672,16 @@ "@types/tern": "*" } }, + "node_modules/@types/electron": { + "version": "1.4.38", + "resolved": "https://registry.npmjs.org/@types/electron/-/electron-1.4.38.tgz", + "integrity": "sha512-Cu6laqBamT6VSPi0LLlF9vE9Os8EbTaI/5eJSsd7CPoLUG3Znjh04u9TxMhQYPF1wGFM14Z8TFQ2914JZ+rGLg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/estree": { "version": "1.0.6", "resolved": "https://registry.npmmirror.com/@types/estree/-/estree-1.0.6.tgz", diff --git a/package.json b/package.json index 8209f5f..1210c6e 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "author": "", "license": "MIT", "devDependencies": { + "@types/electron": "^1.4.38", "@types/node": "^16.11.6", "@types/react": "^19.0.4", "@types/react-dom": "^19.0.2", diff --git a/src/components/File/Content.tsx b/src/components/File/Content.tsx index debf7c9..ff43bef 100644 --- a/src/components/File/Content.tsx +++ b/src/components/File/Content.tsx @@ -1,5 +1,6 @@ import classNames from "classnames"; -import { Menu, TFile } from "obsidian"; +import { shell } from "electron"; +import { Menu, normalizePath, TFile } from "obsidian"; import { useRef } from "react"; import { useShallow } from "zustand/react/shallow"; @@ -120,6 +121,28 @@ const FileContent = ({ file }: FileProps) => { await createFileWithDefaultName(folder); }; + const _getOpenInFileManagerTitle = () => { + const isEn = language == "en"; + const isWin = process.platform === "win32"; + if (isEn) { + return isWin ? "Show in Explorer" : "Reveal in Finder"; + } else { + return isWin ? "在资源管理器中显示" : "在访达中显示"; + } + } + + const openInFileManager = (menu: Menu) => { + addMenuItem(menu, { + title: _getOpenInFileManagerTitle(), + icon: "move-up-right", + action: () => { + const vaultPath = plugin.app.vault.adapter.getBasePath(); + const abs = normalizePath(`${vaultPath}/${file.path}`); + shell.showItemInFolder(abs); + }, + }); + }; + const onShowContextMenu = (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); @@ -136,6 +159,9 @@ const FileContent = ({ file }: FileProps) => { addMoveMenuItem(menu, onShowTargetFoldersList); menu.addSeparator(); + openInFileManager(menu); + menu.addSeparator(); + addRenameMenuItem(menu, nameRef.current?.onStartEditingName ?? noop); addDeleteMenuItem(menu, () => trashFile(file));