Skip to content

feat: add "Open in Finder" menu option #7873

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion apps/desktop/src/components/ProjectSettingsMenuAction.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { ShortcutService } from '$lib/shortcuts/shortcutService.svelte';
import * as events from '$lib/utils/events';
import { unsubscribe } from '$lib/utils/unsubscribe';
import { getEditorUri, openExternalUrl } from '$lib/utils/url';
import { getEditorUri, openExternalFile, openExternalUrl } from '$lib/utils/url';
import { getContextStoreBySymbol } from '@gitbutler/shared/context';
import { getContext } from '@gitbutler/shared/context';
import { onMount } from 'svelte';
Expand All @@ -30,6 +30,10 @@
openExternalUrl(path);
});

shortcutService.on('open-in-finder', () => {
openExternalFile(project.path);
});

shortcutService.on('history', () => {
$showHistoryView = !$showHistoryView;
});
Expand Down
19 changes: 19 additions & 0 deletions apps/desktop/src/lib/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@ export async function openExternalUrl(href: string) {
}
}

export async function openExternalFile(path: string) {
try {
// Use the Opener plugin to reveal the folder in the native file explorer
await invoke('plugin:opener|reveal_item_in_dir', { path: path });
} catch (e) {
if (typeof e === 'string' || e instanceof String) {
const message = `
Failed to reveal directory in file explorer:

${path}
`;
showToast({ title: 'Explorer error', message, style: 'error' });
}

// Rethrowing for sentry and posthog
throw e;
}
}

// turn a git remote url into a web url (github, gitlab, bitbucket, etc)
export function convertRemoteToWebUrl(url: string): string {
const gitRemote = GitUrlParse(url);
Expand Down
6 changes: 6 additions & 0 deletions crates/gitbutler-tauri/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ pub fn build<R: Runtime>(handle: &AppHandle<R>) -> tauri::Result<tauri::menu::Me
.build(handle)?,
)
.text("project/open-in-vscode", "Open in Editor")
.text("project/open-in-finder", "Open in Finder")
.separator()
.text("project/settings", "Project Settings")
.build()?;
Expand Down Expand Up @@ -299,6 +300,11 @@ pub fn handle_event(webview: &WebviewWindow, event: &MenuEvent) {
return;
}

if event.id() == "project/open-in-finder" {
emit(webview, SHORTCUT_EVENT, "open-in-finder");
return;
}

if event.id() == "project/settings" {
emit(webview, SHORTCUT_EVENT, "project-settings");
return;
Expand Down
1 change: 1 addition & 0 deletions crates/gitbutler-tauri/src/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub(crate) fn open_that(path: &str) -> anyhow::Result<()> {
"zed",
"windsurf",
"cursor",
"file",
]
.contains(&target_url.scheme())
{
Expand Down