gpui: Add to support check state to MenuItem (#39876)

Release Notes:

- N/A

---


https://github.com/user-attachments/assets/d46b77ae-88ba-43da-93ad-3656a7fecaf9

The system menu is only support for macOS, so here just modify the macOS
platform special code.

The Windows, Linux used `ApplicationMenu`, I have already added
`checked` option to Zed's ContextMenu.

Then later when this PR merged, we can improve "View" menu to show check
state to panels (Project Panel, Outline Panel, ...).
This commit is contained in:
Jason Lee
2025-11-07 09:42:55 +00:00
committed by GitHub
parent 760747f127
commit 29cc3d0e18
6 changed files with 137 additions and 20 deletions
+15 -2
View File
@@ -542,9 +542,22 @@ impl ContextMenu {
self
}
pub fn action(mut self, label: impl Into<SharedString>, action: Box<dyn Action>) -> Self {
pub fn action(self, label: impl Into<SharedString>, action: Box<dyn Action>) -> Self {
self.action_checked(label, action, false)
}
pub fn action_checked(
mut self,
label: impl Into<SharedString>,
action: Box<dyn Action>,
checked: bool,
) -> Self {
self.items.push(ContextMenuItem::Entry(ContextMenuEntry {
toggle: None,
toggle: if checked {
Some((IconPosition::Start, true))
} else {
None
},
label: label.into(),
action: Some(action.boxed_clone()),
handler: Rc::new(move |context, window, cx| {