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:
@@ -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| {
|
||||
|
||||
Reference in New Issue
Block a user