keymap_ui: Add context menu for table rows (#33747)

Closes #ISSUE

Adds a right click context menu to table rows, refactoring the table API
to support more general row rendering in the process, and creating
actions for the couple of operations available in the context menu.

Additionally includes an only partially related change to the context
menu API, which makes it easier to have actions that are disabled based
on a boolean value.

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Ben Kunkle 2025-07-01 22:06:45 -05:00 committed by GitHub
parent faca128304
commit 79f3cb1225
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 308 additions and 204 deletions

View file

@ -122,40 +122,29 @@ fn git_panel_context_menu(
ContextMenu::build(window, cx, move |context_menu, _, _| {
context_menu
.context(focus_handle)
.map(|menu| {
if state.has_unstaged_changes {
menu.action("Stage All", StageAll.boxed_clone())
} else {
menu.disabled_action("Stage All", StageAll.boxed_clone())
}
})
.map(|menu| {
if state.has_staged_changes {
menu.action("Unstage All", UnstageAll.boxed_clone())
} else {
menu.disabled_action("Unstage All", UnstageAll.boxed_clone())
}
})
.action_disabled_when(
!state.has_unstaged_changes,
"Stage All",
StageAll.boxed_clone(),
)
.action_disabled_when(
!state.has_staged_changes,
"Unstage All",
UnstageAll.boxed_clone(),
)
.separator()
.action("Open Diff", project_diff::Diff.boxed_clone())
.separator()
.map(|menu| {
if state.has_tracked_changes {
menu.action("Discard Tracked Changes", RestoreTrackedFiles.boxed_clone())
} else {
menu.disabled_action(
"Discard Tracked Changes",
RestoreTrackedFiles.boxed_clone(),
)
}
})
.map(|menu| {
if state.has_new_changes {
menu.action("Trash Untracked Files", TrashUntrackedFiles.boxed_clone())
} else {
menu.disabled_action("Trash Untracked Files", TrashUntrackedFiles.boxed_clone())
}
})
.action_disabled_when(
!state.has_tracked_changes,
"Discard Tracked Changes",
RestoreTrackedFiles.boxed_clone(),
)
.action_disabled_when(
!state.has_new_changes,
"Trash Untracked Files",
TrashUntrackedFiles.boxed_clone(),
)
})
}