Skip to content

Commit f90d9d2

Browse files
authored
Prefer to disable options over hiding (git panel entry context menu) (#44102)
When adding the File History option here, I used the pattern to hide the option, since that's what another option was already doing here, but I see other menus in the git panel (`...`) that use disabling over hiding, which is what I think is a nicer experience (allows you to learn of actions, the full range of actions is always visible, don't have to worry about how multiple hidden items might interact in various configurations, etc). <img width="336" height="241" alt="SCR-20251203-pnpy" src="https://github.com/user-attachments/assets/0da90b9a-c230-4ce3-87b9-553ffb83604f" /> <img width="332" height="265" alt="SCR-20251203-pobg" src="https://github.com/user-attachments/assets/5da95c7d-faa9-4f0f-a069-f1d099f952b9" /> In general, I think it would be good to move to being more consistent with disabling over hiding - there are other places in the app that are hiding - some might be valid, but others might just choices made on a whim. Release Notes: - N/A
1 parent 40a611b commit f90d9d2

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

crates/git_ui/src/git_panel.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4004,28 +4004,21 @@ impl GitPanel {
40044004
"Restore File"
40054005
};
40064006
let context_menu = ContextMenu::build(window, cx, |context_menu, _, _| {
4007-
let mut context_menu = context_menu
4007+
let is_created = entry.status.is_created();
4008+
context_menu
40084009
.context(self.focus_handle.clone())
40094010
.action(stage_title, ToggleStaged.boxed_clone())
4010-
.action(restore_title, git::RestoreFile::default().boxed_clone());
4011-
4012-
if entry.status.is_created() {
4013-
context_menu =
4014-
context_menu.action("Add to .gitignore", git::AddToGitignore.boxed_clone())
4015-
}
4016-
4017-
context_menu = context_menu
4011+
.action(restore_title, git::RestoreFile::default().boxed_clone())
4012+
.action_disabled_when(
4013+
!is_created,
4014+
"Add to .gitignore",
4015+
git::AddToGitignore.boxed_clone(),
4016+
)
40184017
.separator()
40194018
.action("Open Diff", Confirm.boxed_clone())
4020-
.action("Open File", SecondaryConfirm.boxed_clone());
4021-
4022-
if !entry.status.is_created() {
4023-
context_menu = context_menu
4024-
.separator()
4025-
.action("File History", Box::new(git::FileHistory));
4026-
}
4027-
4028-
context_menu
4019+
.action("Open File", SecondaryConfirm.boxed_clone())
4020+
.separator()
4021+
.action_disabled_when(is_created, "File History", Box::new(git::FileHistory))
40294022
});
40304023
self.selected_entry = Some(ix);
40314024
self.set_context_menu(context_menu, position, window, cx);

0 commit comments

Comments
 (0)