Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Remove `ContextMenu::element_item`

Antonio Scandurrad3b976d04480
diff --git a/crates/context_menu/src/context_menu.rs b/crates/context_menu/src/context_menu.rs
index e988684c9a3..fd5e1f1b099 100644
--- a/crates/context_menu/src/context_menu.rs
+++ b/crates/context_menu/src/context_menu.rs
@@ -37,6 +37,33 @@ pub enum ContextMenuItemLabel {
Element(ContextMenuItemBuilder),
}
+impl From<Cow<'static, str>> for ContextMenuItemLabel {
+ fn from(s: Cow<'static, str>) -> Self {
+ Self::String(s)
+ }
+}
+
+impl From<&'static str> for ContextMenuItemLabel {
+ fn from(s: &'static str) -> Self {
+ Self::String(s.into())
+ }
+}
+
+impl From<String> for ContextMenuItemLabel {
+ fn from(s: String) -> Self {
+ Self::String(s.into())
+ }
+}
+
+impl<T> From<T> for ContextMenuItemLabel
+where
+ T: 'static + Fn(&mut MouseState, &theme::ContextMenuItem) -> AnyElement<ContextMenu>,
+{
+ fn from(f: T) -> Self {
+ Self::Element(Box::new(f))
+ }
+}
+
pub enum ContextMenuItem {
Item {
label: ContextMenuItemLabel,
@@ -47,16 +74,9 @@ pub enum ContextMenuItem {
}
impl ContextMenuItem {
- pub fn element_item(label: ContextMenuItemBuilder, action: impl 'static + Action) -> Self {
- Self::Item {
- label: ContextMenuItemLabel::Element(label),
- action: Box::new(action),
- }
- }
-
- pub fn item(label: impl Into<Cow<'static, str>>, action: impl 'static + Action) -> Self {
+ pub fn item(label: impl Into<ContextMenuItemLabel>, action: impl 'static + Action) -> Self {
Self::Item {
- label: ContextMenuItemLabel::String(label.into()),
+ label: label.into(),
action: Box::new(action),
}
}
diff --git a/crates/copilot_button/src/copilot_button.rs b/crates/copilot_button/src/copilot_button.rs
index c8bfcc75501..a06e65db8df 100644
--- a/crates/copilot_button/src/copilot_button.rs
+++ b/crates/copilot_button/src/copilot_button.rs
@@ -317,16 +317,14 @@ impl CopilotButton {
menu_options.push(ContextMenuItem::Separator);
let icon_style = settings.theme.copilot.out_link_icon.clone();
- menu_options.push(ContextMenuItem::element_item(
- Box::new(
- move |state: &mut MouseState, style: &theme::ContextMenuItem| {
- Flex::row()
- .with_child(Label::new("Copilot Settings", style.label.clone()))
- .with_child(theme::ui::icon(icon_style.style_for(state, false)))
- .align_children_center()
- .into_any()
- },
- ),
+ menu_options.push(ContextMenuItem::item(
+ move |state: &mut MouseState, style: &theme::ContextMenuItem| {
+ Flex::row()
+ .with_child(Label::new("Copilot Settings", style.label.clone()))
+ .with_child(theme::ui::icon(icon_style.style_for(state, false)))
+ .align_children_center()
+ .into_any()
+ },
OsOpen::new(COPILOT_SETTINGS_URL),
));