-
-
Notifications
You must be signed in to change notification settings - Fork 310
feat(messages): add file-link context menu with reveal #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,8 @@ | ||
| import { useCallback } from "react"; | ||
| import type { MouseEvent } from "react"; | ||
| import { Menu, MenuItem, PredefinedMenuItem } from "@tauri-apps/api/menu"; | ||
| import { LogicalPosition } from "@tauri-apps/api/dpi"; | ||
| import { getCurrentWindow } from "@tauri-apps/api/window"; | ||
| import { revealItemInDir } from "@tauri-apps/plugin-opener"; | ||
| import { openWorkspaceIn } from "../../../services/tauri"; | ||
| import { getStoredOpenAppId } from "../../app/utils/openApp"; | ||
|
|
@@ -35,8 +39,22 @@ function stripLineSuffix(path: string) { | |
| return match ? match[1] : path; | ||
| } | ||
|
|
||
| function revealLabel() { | ||
| const platform = | ||
| (navigator as Navigator & { userAgentData?: { platform?: string } }) | ||
| .userAgentData?.platform ?? navigator.platform ?? ""; | ||
| const normalized = platform.toLowerCase(); | ||
| if (normalized.includes("mac")) { | ||
| return "Reveal in Finder"; | ||
| } | ||
| if (normalized.includes("win")) { | ||
| return "Show in Explorer"; | ||
| } | ||
| return "Reveal in File Manager"; | ||
| } | ||
|
|
||
| export function useFileLinkOpener(workspacePath?: string | null) { | ||
| return useCallback( | ||
| const openFileLink = useCallback( | ||
| async (rawPath: string) => { | ||
| const openAppId = getStoredOpenAppId(); | ||
| const target = OPEN_TARGETS[openAppId] ?? OPEN_TARGETS.vscode; | ||
|
|
@@ -53,4 +71,66 @@ export function useFileLinkOpener(workspacePath?: string | null) { | |
| }, | ||
| [workspacePath], | ||
| ); | ||
|
|
||
| const showFileLinkMenu = useCallback( | ||
| async (event: MouseEvent, rawPath: string) => { | ||
| event.preventDefault(); | ||
| event.stopPropagation(); | ||
| const openAppId = getStoredOpenAppId(); | ||
| const target = OPEN_TARGETS[openAppId] ?? OPEN_TARGETS.vscode; | ||
| const resolvedPath = resolveFilePath(stripLineSuffix(rawPath), workspacePath); | ||
| const openLabel = | ||
| target.id === "finder" | ||
| ? "Open in Finder" | ||
| : target.appName | ||
| ? `Open in ${target.appName}` | ||
| : "Open Link"; | ||
| const items = [ | ||
| await MenuItem.new({ | ||
| text: openLabel, | ||
| action: async () => { | ||
| await openFileLink(rawPath); | ||
| }, | ||
| }), | ||
| await MenuItem.new({ | ||
| text: "Open Link in New Window", | ||
| action: async () => { | ||
| await openFileLink(rawPath); | ||
| }, | ||
|
Comment on lines
+95
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new context-menu item labeled “Open Link in New Window” invokes the same Useful? React with 👍 / 👎. |
||
| }), | ||
| await MenuItem.new({ | ||
| text: revealLabel(), | ||
| action: async () => { | ||
| await revealItemInDir(resolvedPath); | ||
| }, | ||
| }), | ||
| await MenuItem.new({ | ||
| text: "Download Linked File", | ||
| enabled: false, | ||
| }), | ||
| await MenuItem.new({ | ||
| text: "Copy Link", | ||
| action: async () => { | ||
| const link = | ||
| resolvedPath.startsWith("/") ? `file://${resolvedPath}` : resolvedPath; | ||
| try { | ||
| await navigator.clipboard.writeText(link); | ||
| } catch { | ||
| // Clipboard failures are non-fatal here. | ||
| } | ||
| }, | ||
| }), | ||
| await PredefinedMenuItem.new({ item: "Separator" }), | ||
| await PredefinedMenuItem.new({ item: "Services" }), | ||
| ]; | ||
|
|
||
| const menu = await Menu.new({ items }); | ||
| const window = getCurrentWindow(); | ||
| const position = new LogicalPosition(event.clientX, event.clientY); | ||
| await menu.popup(position, window); | ||
| }, | ||
| [openFileLink, workspacePath], | ||
| ); | ||
|
|
||
| return { openFileLink, showFileLinkMenu }; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new context menu item labeled “Open Link in New Window” executes the exact same action as “Open Link” (
openFileLink(rawPath)), so users will never get a distinct new-window behavior. BecauseopenFileLinkultimately delegates toopen_workspace_in(which just callsopen -a <app> <path>), this menu item is misleading and provides no added functionality; consider removing it or wiring a separate command/flag (e.g.,open -n -aon macOS) to match the label.Useful? React with 👍 / 👎.