From 5ef5b75099b3f366f7b0b0c0beb195d54e557d18 Mon Sep 17 00:00:00 2001 From: Swiftaff Date: Fri, 24 Jan 2025 03:53:07 +0800 Subject: [PATCH] Disable Copy Permalink context menu item when not in git repo (#23350) Closes #13979 Please review this approach to hide the permalink, or alternatively to disable it instead? Release Notes: - The Copy Permalink menu item is now disabled when not in a Git repository. --------- Co-authored-by: Marshall Bowers --- crates/editor/src/mouse_context_menu.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/editor/src/mouse_context_menu.rs b/crates/editor/src/mouse_context_menu.rs index 6861d424ec47c860530d6c65bf5820efece7b629..9d18b2d92b15e3042a23dfb0001bb2853d9fcce6 100644 --- a/crates/editor/src/mouse_context_menu.rs +++ b/crates/editor/src/mouse_context_menu.rs @@ -155,6 +155,11 @@ pub fn deploy_context_menu( .all::(cx) .into_iter() .any(|s| !s.is_empty()); + let has_git_repo = editor.project.as_ref().map_or(false, |project| { + project.update(cx, |project, cx| { + project.get_first_worktree_root_repo(cx).is_some() + }) + }); ui::ContextMenu::build(cx, |menu, _cx| { let builder = menu @@ -190,7 +195,14 @@ pub fn deploy_context_menu( } }) .action("Open in Terminal", Box::new(OpenInTerminal)) - .action("Copy Permalink", Box::new(CopyPermalinkToLine)); + .map(|builder| { + const COPY_PERMALINK_LABEL: &str = "Copy Permalink"; + if has_git_repo { + builder.action(COPY_PERMALINK_LABEL, Box::new(CopyPermalinkToLine)) + } else { + builder.disabled_action(COPY_PERMALINK_LABEL, Box::new(CopyPermalinkToLine)) + } + }); match focus { Some(focus) => builder.context(focus), None => builder,