diff --git a/crates/project_panel2/src/project_panel.rs b/crates/project_panel2/src/project_panel.rs index 2ee2e3ab1fe52ad2e4e234ca100def9f96205340..891355ea1f90c2ba16ecf2a9dec5e40ed25bed3f 100644 --- a/crates/project_panel2/src/project_panel.rs +++ b/crates/project_panel2/src/project_panel.rs @@ -398,6 +398,7 @@ impl ProjectPanel { menu = menu.action( "Add Folder to Project", Box::new(workspace::AddFolderToProject), + cx, ); if is_root { menu = menu.entry( @@ -412,35 +413,35 @@ impl ProjectPanel { } menu = menu - .action("New File", Box::new(NewFile)) - .action("New Folder", Box::new(NewDirectory)) + .action("New File", Box::new(NewFile), cx) + .action("New Folder", Box::new(NewDirectory), cx) .separator() - .action("Cut", Box::new(Cut)) - .action("Copy", Box::new(Copy)); + .action("Cut", Box::new(Cut), cx) + .action("Copy", Box::new(Copy), cx); if let Some(clipboard_entry) = self.clipboard_entry { if clipboard_entry.worktree_id() == worktree_id { - menu = menu.action("Paste", Box::new(Paste)); + menu = menu.action("Paste", Box::new(Paste), cx); } } menu = menu .separator() - .action("Copy Path", Box::new(CopyPath)) - .action("Copy Relative Path", Box::new(CopyRelativePath)) + .action("Copy Path", Box::new(CopyPath), cx) + .action("Copy Relative Path", Box::new(CopyRelativePath), cx) .separator() - .action("Reveal in Finder", Box::new(RevealInFinder)); + .action("Reveal in Finder", Box::new(RevealInFinder), cx); if is_dir { menu = menu - .action("Open in Terminal", Box::new(OpenInTerminal)) - .action("Search Inside", Box::new(NewSearchInDirectory)) + .action("Open in Terminal", Box::new(OpenInTerminal), cx) + .action("Search Inside", Box::new(NewSearchInDirectory), cx) } - menu = menu.separator().action("Rename", Box::new(Rename)); + menu = menu.separator().action("Rename", Box::new(Rename), cx); if !is_root { - menu = menu.action("Delete", Box::new(Delete)); + menu = menu.action("Delete", Box::new(Delete), cx); } menu @@ -658,7 +659,6 @@ impl ProjectPanel { } fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext) { - dbg!("odd"); self.edit_state = None; self.update_visible_entries(None, cx); cx.focus(&self.focus_handle); @@ -1385,7 +1385,7 @@ impl ProjectPanel { }) .child( if let (Some(editor), true) = (Some(&self.filename_editor), show_editor) { - div().w_full().child(editor.clone()) + div().h_full().w_full().child(editor.clone()) } else { div() .text_color(filename_text_color) diff --git a/crates/terminal_view2/src/terminal_view.rs b/crates/terminal_view2/src/terminal_view.rs index 9f3ed313880989631c25b7cb7f9fe1460c9224c3..b007d58c34bcb2163f42bd2b88e1979a18152f56 100644 --- a/crates/terminal_view2/src/terminal_view.rs +++ b/crates/terminal_view2/src/terminal_view.rs @@ -298,9 +298,12 @@ impl TerminalView { position: gpui::Point, cx: &mut ViewContext, ) { - self.context_menu = Some(ContextMenu::build(cx, |menu, _| { - menu.action("Clear", Box::new(Clear)) - .action("Close", Box::new(CloseActiveItem { save_intent: None })) + self.context_menu = Some(ContextMenu::build(cx, |menu, cx| { + menu.action("Clear", Box::new(Clear), cx).action( + "Close", + Box::new(CloseActiveItem { save_intent: None }), + cx, + ) })); dbg!(&position); // todo!() diff --git a/crates/ui2/src/components/context_menu.rs b/crates/ui2/src/components/context_menu.rs index 3510256c0ce50b2c73d8b091a06e433be42f8ff7..b5ef8cf160839674c3a3e452975ab45fee4d1996 100644 --- a/crates/ui2/src/components/context_menu.rs +++ b/crates/ui2/src/components/context_menu.rs @@ -1,4 +1,4 @@ -use crate::{prelude::*, v_stack, Label, List, ListItem, ListSeparator, ListSubHeader}; +use crate::{prelude::*, v_stack, KeyBinding, Label, List, ListItem, ListSeparator, ListSubHeader}; use gpui::{ overlay, px, Action, AnchorCorner, AnyElement, AppContext, Bounds, ClickEvent, DismissEvent, DispatchPhase, Div, EventEmitter, FocusHandle, FocusableView, IntoElement, LayoutId, @@ -9,7 +9,11 @@ use std::{cell::RefCell, rc::Rc}; pub enum ContextMenuItem { Separator, Header(SharedString), - Entry(SharedString, Rc), + Entry { + label: SharedString, + click_handler: Rc, + key_binding: Option, + }, } pub struct ContextMenu { @@ -57,16 +61,26 @@ impl ContextMenu { label: impl Into, on_click: impl Fn(&ClickEvent, &mut WindowContext) + 'static, ) -> Self { - self.items - .push(ContextMenuItem::Entry(label.into(), Rc::new(on_click))); + self.items.push(ContextMenuItem::Entry { + label: label.into(), + click_handler: Rc::new(on_click), + key_binding: None, + }); self } - pub fn action(self, label: impl Into, action: Box) -> Self { - // todo: add the keybindings to the list entry - self.entry(label.into(), move |_, cx| { - cx.dispatch_action(action.boxed_clone()) - }) + pub fn action( + mut self, + label: impl Into, + action: Box, + cx: &mut WindowContext, + ) -> Self { + self.items.push(ContextMenuItem::Entry { + label: label.into(), + key_binding: KeyBinding::for_action(&*action, cx), + click_handler: Rc::new(move |_, cx| cx.dispatch_action(action.boxed_clone())), + }); + self } pub fn confirm(&mut self, _: &menu::Confirm, cx: &mut ViewContext) { @@ -106,12 +120,17 @@ impl Render for ContextMenu { ContextMenuItem::Header(header) => { ListSubHeader::new(header.clone()).into_any_element() } - ContextMenuItem::Entry(entry, callback) => { + ContextMenuItem::Entry { + label: entry, + click_handler: callback, + key_binding, + } => { let callback = callback.clone(); let dismiss = cx.listener(|_, _, cx| cx.emit(DismissEvent::Dismiss)); ListItem::new(entry.clone()) .child(Label::new(entry.clone())) + .children(key_binding.clone()) .on_click(move |event, cx| { callback(event, cx); dismiss(event, cx)