diff --git a/crates/project_panel2/src/project_panel.rs b/crates/project_panel2/src/project_panel.rs index 4d1a6ee8f7..0550fc7bd2 100644 --- a/crates/project_panel2/src/project_panel.rs +++ b/crates/project_panel2/src/project_panel.rs @@ -371,7 +371,7 @@ impl ProjectPanel { _entry_id: ProjectEntryId, _cx: &mut ViewContext, ) { - todo!() + // todo!() // let project = self.project.read(cx); // let worktree_id = if let Some(id) = project.worktree_id_for_entry(entry_id, cx) { diff --git a/crates/terminal_view2/src/terminal_view.rs b/crates/terminal_view2/src/terminal_view.rs index 5a5f74f9e1..9f3ed31388 100644 --- a/crates/terminal_view2/src/terminal_view.rs +++ b/crates/terminal_view2/src/terminal_view.rs @@ -31,7 +31,7 @@ use workspace::{ notifications::NotifyResultExt, register_deserializable_item, searchable::{SearchEvent, SearchOptions, SearchableItem}, - ui::{ContextMenu, Icon, IconElement, Label, ListItem}, + ui::{ContextMenu, Icon, IconElement, Label}, CloseActiveItem, NewCenterTerminal, Pane, ToolbarItemLocation, Workspace, WorkspaceId, }; @@ -299,11 +299,8 @@ impl TerminalView { cx: &mut ViewContext, ) { self.context_menu = Some(ContextMenu::build(cx, |menu, _| { - menu.action(ListItem::new("clear", Label::new("Clear")), Box::new(Clear)) - .action( - ListItem::new("close", Label::new("Close")), - Box::new(CloseActiveItem { save_intent: None }), - ) + menu.action("Clear", Box::new(Clear)) + .action("Close", Box::new(CloseActiveItem { save_intent: None })) })); dbg!(&position); // todo!() diff --git a/crates/ui2/src/components/context_menu.rs b/crates/ui2/src/components/context_menu.rs index 8bb5b2e5d2..2473bff610 100644 --- a/crates/ui2/src/components/context_menu.rs +++ b/crates/ui2/src/components/context_menu.rs @@ -1,7 +1,7 @@ use std::cell::RefCell; use std::rc::Rc; -use crate::{prelude::*, v_stack, List}; +use crate::{prelude::*, v_stack, Label, List}; use crate::{ListItem, ListSeparator, ListSubHeader}; use gpui::{ overlay, px, Action, AnchorCorner, AnyElement, AppContext, Bounds, ClickEvent, DispatchPhase, @@ -10,9 +10,9 @@ use gpui::{ }; pub enum ContextMenuItem { - Separator(ListSeparator), - Header(ListSubHeader), - Entry(ListItem, Rc), + Separator, + Header(SharedString), + Entry(SharedString, Rc), } pub struct ContextMenu { @@ -46,29 +46,30 @@ impl ContextMenu { } pub fn header(mut self, title: impl Into) -> Self { - self.items - .push(ContextMenuItem::Header(ListSubHeader::new(title))); + self.items.push(ContextMenuItem::Header(title.into())); self } pub fn separator(mut self) -> Self { - self.items.push(ContextMenuItem::Separator(ListSeparator)); + self.items.push(ContextMenuItem::Separator); self } pub fn entry( mut self, - view: ListItem, + label: impl Into, on_click: impl Fn(&ClickEvent, &mut WindowContext) + 'static, ) -> Self { self.items - .push(ContextMenuItem::Entry(view, Rc::new(on_click))); + .push(ContextMenuItem::Entry(label.into(), Rc::new(on_click))); self } - pub fn action(self, view: ListItem, action: Box) -> Self { + pub fn action(self, label: impl Into, action: Box) -> Self { // todo: add the keybindings to the list entry - self.entry(view, move |_, cx| cx.dispatch_action(action.boxed_clone())) + self.entry(label.into(), move |_, cx| { + cx.dispatch_action(action.boxed_clone()) + }) } pub fn confirm(&mut self, _: &menu::Confirm, cx: &mut ViewContext) { @@ -104,16 +105,16 @@ impl Render for ContextMenu { // .border_color(cx.theme().colors().border) .child( List::new().children(self.items.iter().map(|item| match item { - ContextMenuItem::Separator(separator) => { - separator.clone().render_into_any() + ContextMenuItem::Separator => ListSeparator::new().render_into_any(), + ContextMenuItem::Header(header) => { + ListSubHeader::new(header.clone()).render_into_any() } - ContextMenuItem::Header(header) => header.clone().render_into_any(), ContextMenuItem::Entry(entry, callback) => { let callback = callback.clone(); let dismiss = cx.listener(|_, _, cx| cx.emit(Manager::Dismiss)); - entry - .clone() + ListItem::new(entry.clone()) + .child(Label::new(entry.clone())) .on_click(move |event, cx| { callback(event, cx); dismiss(event, cx) diff --git a/crates/ui2/src/components/list.rs b/crates/ui2/src/components/list.rs index 0266ae3342..7319640b9e 100644 --- a/crates/ui2/src/components/list.rs +++ b/crates/ui2/src/components/list.rs @@ -245,45 +245,28 @@ pub struct ListItem { // TODO: Reintroduce this // disclosure_control_style: DisclosureControlVisibility, indent_level: u32, - label: Label, left_slot: Option, overflow: OverflowStyle, size: ListEntrySize, toggle: Toggle, variant: ListItemVariant, on_click: Option>, -} - -impl Clone for ListItem { - fn clone(&self) -> Self { - Self { - id: self.id.clone(), - disabled: self.disabled, - indent_level: self.indent_level, - label: self.label.clone(), - left_slot: self.left_slot.clone(), - overflow: self.overflow, - size: self.size, - toggle: self.toggle, - variant: self.variant, - on_click: self.on_click.clone(), - } - } + children: SmallVec<[AnyElement; 2]>, } impl ListItem { - pub fn new(id: impl Into, label: Label) -> Self { + pub fn new(id: impl Into) -> Self { Self { id: id.into(), disabled: false, indent_level: 0, - label, left_slot: None, overflow: OverflowStyle::Hidden, size: ListEntrySize::default(), toggle: Toggle::NotToggleable, variant: ListItemVariant::default(), on_click: Default::default(), + children: SmallVec::new(), } } @@ -394,11 +377,17 @@ impl Component for ListItem { .relative() .child(disclosure_control(self.toggle)) .children(left_content) - .child(self.label), + .children(self.children), ) } } +impl ParentElement for ListItem { + fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { + &mut self.children + } +} + #[derive(RenderOnce, Clone)] pub struct ListSeparator; diff --git a/crates/ui2/src/components/stories/context_menu.rs b/crates/ui2/src/components/stories/context_menu.rs index dd0bc03a21..98faea70aa 100644 --- a/crates/ui2/src/components/stories/context_menu.rs +++ b/crates/ui2/src/components/stories/context_menu.rs @@ -2,7 +2,7 @@ use gpui::{actions, Action, AnchorCorner, Div, Render, View}; use story::Story; use crate::prelude::*; -use crate::{menu_handle, ContextMenu, Label, ListItem}; +use crate::{menu_handle, ContextMenu, Label}; actions!(PrintCurrentDate, PrintBestFood); @@ -10,17 +10,13 @@ fn build_menu(cx: &mut WindowContext, header: impl Into) -> View