keymap_ui: Add context menu for table rows (#33747)
Closes #ISSUE Adds a right click context menu to table rows, refactoring the table API to support more general row rendering in the process, and creating actions for the couple of operations available in the context menu. Additionally includes an only partially related change to the context menu API, which makes it easier to have actions that are disabled based on a boolean value. Release Notes: - N/A *or* Added/Fixed/Improved ...
This commit is contained in:
parent
faca128304
commit
79f3cb1225
12 changed files with 308 additions and 204 deletions
|
@ -503,8 +503,9 @@ impl ContextMenu {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn disabled_action(
|
||||
pub fn action_disabled_when(
|
||||
mut self,
|
||||
disabled: bool,
|
||||
label: impl Into<SharedString>,
|
||||
action: Box<dyn Action>,
|
||||
) -> Self {
|
||||
|
@ -522,7 +523,7 @@ impl ContextMenu {
|
|||
icon_size: IconSize::Small,
|
||||
icon_position: IconPosition::End,
|
||||
icon_color: None,
|
||||
disabled: true,
|
||||
disabled,
|
||||
documentation_aside: None,
|
||||
end_slot_icon: None,
|
||||
end_slot_title: None,
|
||||
|
|
|
@ -9,7 +9,7 @@ use gpui::{
|
|||
|
||||
pub struct RightClickMenu<M: ManagedView> {
|
||||
id: ElementId,
|
||||
child_builder: Option<Box<dyn FnOnce(bool) -> AnyElement + 'static>>,
|
||||
child_builder: Option<Box<dyn FnOnce(bool, &mut Window, &mut App) -> AnyElement + 'static>>,
|
||||
menu_builder: Option<Rc<dyn Fn(&mut Window, &mut App) -> Entity<M> + 'static>>,
|
||||
anchor: Option<Corner>,
|
||||
attach: Option<Corner>,
|
||||
|
@ -23,11 +23,11 @@ impl<M: ManagedView> RightClickMenu<M> {
|
|||
|
||||
pub fn trigger<F, E>(mut self, e: F) -> Self
|
||||
where
|
||||
F: FnOnce(bool) -> E + 'static,
|
||||
F: FnOnce(bool, &mut Window, &mut App) -> E + 'static,
|
||||
E: IntoElement + 'static,
|
||||
{
|
||||
self.child_builder = Some(Box::new(move |is_menu_active| {
|
||||
e(is_menu_active).into_any_element()
|
||||
self.child_builder = Some(Box::new(move |is_menu_active, window, cx| {
|
||||
e(is_menu_active, window, cx).into_any_element()
|
||||
}));
|
||||
self
|
||||
}
|
||||
|
@ -149,10 +149,9 @@ impl<M: ManagedView> Element for RightClickMenu<M> {
|
|||
element
|
||||
});
|
||||
|
||||
let mut child_element = this
|
||||
.child_builder
|
||||
.take()
|
||||
.map(|child_builder| (child_builder)(element_state.menu.borrow().is_some()));
|
||||
let mut child_element = this.child_builder.take().map(|child_builder| {
|
||||
(child_builder)(element_state.menu.borrow().is_some(), window, cx)
|
||||
});
|
||||
|
||||
let child_layout_id = child_element
|
||||
.as_mut()
|
||||
|
|
|
@ -47,12 +47,12 @@ impl Render for ContextMenuStory {
|
|||
.justify_between()
|
||||
.child(
|
||||
right_click_menu("test2")
|
||||
.trigger(|_| Label::new("TOP LEFT"))
|
||||
.trigger(|_, _, _| Label::new("TOP LEFT"))
|
||||
.menu(move |window, cx| build_menu(window, cx, "top left")),
|
||||
)
|
||||
.child(
|
||||
right_click_menu("test1")
|
||||
.trigger(|_| Label::new("BOTTOM LEFT"))
|
||||
.trigger(|_, _, _| Label::new("BOTTOM LEFT"))
|
||||
.anchor(Corner::BottomLeft)
|
||||
.attach(Corner::TopLeft)
|
||||
.menu(move |window, cx| build_menu(window, cx, "bottom left")),
|
||||
|
@ -65,13 +65,13 @@ impl Render for ContextMenuStory {
|
|||
.justify_between()
|
||||
.child(
|
||||
right_click_menu("test3")
|
||||
.trigger(|_| Label::new("TOP RIGHT"))
|
||||
.trigger(|_, _, _| Label::new("TOP RIGHT"))
|
||||
.anchor(Corner::TopRight)
|
||||
.menu(move |window, cx| build_menu(window, cx, "top right")),
|
||||
)
|
||||
.child(
|
||||
right_click_menu("test4")
|
||||
.trigger(|_| Label::new("BOTTOM RIGHT"))
|
||||
.trigger(|_, _, _| Label::new("BOTTOM RIGHT"))
|
||||
.anchor(Corner::BottomRight)
|
||||
.attach(Corner::TopRight)
|
||||
.menu(move |window, cx| build_menu(window, cx, "bottom right")),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue