diff --git a/src/components/File/Content.tsx b/src/components/File/Content.tsx index ff43bef..ca13dc9 100644 --- a/src/components/File/Content.tsx +++ b/src/components/File/Content.tsx @@ -1,6 +1,6 @@ import classNames from "classnames"; import { shell } from "electron"; -import { Menu, normalizePath, TFile } from "obsidian"; +import { FileSystemAdapter, Menu, normalizePath, TFile } from "obsidian"; import { useRef } from "react"; import { useShallow } from "zustand/react/shallow"; @@ -129,14 +129,16 @@ const FileContent = ({ file }: FileProps) => { } else { return isWin ? "在资源管理器中显示" : "在访达中显示"; } - } + }; const openInFileManager = (menu: Menu) => { addMenuItem(menu, { title: _getOpenInFileManagerTitle(), icon: "move-up-right", action: () => { - const vaultPath = plugin.app.vault.adapter.getBasePath(); + const vaultPath = ( + plugin.app.vault.adapter as FileSystemAdapter + ).getBasePath(); const abs = normalizePath(`${vaultPath}/${file.path}`); shell.showItemInFolder(abs); }, diff --git a/src/components/Folder/Content.tsx b/src/components/Folder/Content.tsx index c22ab88..6361956 100644 --- a/src/components/Folder/Content.tsx +++ b/src/components/Folder/Content.tsx @@ -1,4 +1,5 @@ -import { Menu, TFolder } from "obsidian"; +import { shell } from "electron"; +import { FileSystemAdapter, Menu, normalizePath, TFolder } from "obsidian"; import { useRef } from "react"; import { useShallow } from "zustand/react/shallow"; @@ -85,6 +86,30 @@ const FolderContent = ({ folder }: Props) => { }); }; + 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 openFolderInFileManager = (menu: Menu) => { + addMenuItem(menu, { + title: _getOpenInFileManagerTitle(), + icon: "move-up-right", + action: () => { + const vaultPath = ( + plugin.app.vault.adapter as FileSystemAdapter + ).getBasePath(); + const abs = normalizePath(`${vaultPath}/${folder.path}`); + shell.showItemInFolder(abs); + }, + }); + }; + const onShowContextMenu = (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); @@ -105,6 +130,9 @@ const FolderContent = ({ folder }: Props) => { addMoveMenuItem(menu, onShowTargetFoldersList, isRootFolder); menu.addSeparator(); + openFolderInFileManager(menu); + menu.addSeparator(); + addRenameMenuItem( menu, nameRef?.current?.onStartEditingName ?? noop,