Keybaord shortcut context menu

This commit is contained in:
Conrad Irwin 2023-11-29 23:04:33 -07:00
parent a37f86f294
commit 54cfcef0aa
2 changed files with 87 additions and 70 deletions

View file

@ -385,10 +385,6 @@ enum ListEntry {
ContactPlaceholder, ContactPlaceholder,
} }
// impl Entity for CollabPanel {
// type Event = Event;
// }
impl CollabPanel { impl CollabPanel {
pub fn new(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> { pub fn new(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> {
cx.build_view(|cx| { cx.build_view(|cx| {
@ -1687,8 +1683,6 @@ impl CollabPanel {
ix: usize, ix: usize,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) { ) {
// self.context_menu_on_selected = position.is_none();
let clipboard_channel_name = self.channel_clipboard.as_ref().and_then(|clipboard| { let clipboard_channel_name = self.channel_clipboard.as_ref().and_then(|clipboard| {
self.channel_store self.channel_store
.read(cx) .read(cx)
@ -1779,7 +1773,13 @@ impl CollabPanel {
}); });
cx.focus_view(&context_menu); cx.focus_view(&context_menu);
let subscription = cx.subscribe(&context_menu, |this, _, _: &DismissEvent, cx| { let subscription =
cx.subscribe(&context_menu, |this, _, _: &DismissEvent, cx| {
if this.context_menu.as_ref().is_some_and(|context_menu| {
context_menu.0.focus_handle(cx).contains_focused(cx)
}) {
cx.focus_self();
}
this.context_menu.take(); this.context_menu.take();
cx.notify(); cx.notify();
}); });
@ -2147,8 +2147,15 @@ impl CollabPanel {
let Some(channel) = self.selected_channel() else { let Some(channel) = self.selected_channel() else {
return; return;
}; };
let Some(bounds) = self
.selection
.and_then(|ix| self.scroll_handle.bounds_for_item(ix))
else {
return;
};
self.deploy_channel_context_menu(todo!(), channel.id, self.selection.unwrap(), cx); self.deploy_channel_context_menu(bounds.center(), channel.id, self.selection.unwrap(), cx);
cx.stop_propagation();
} }
fn selected_channel(&self) -> Option<&Arc<Channel>> { fn selected_channel(&self) -> Option<&Arc<Channel>> {
@ -3258,6 +3265,12 @@ impl Render for CollabPanel {
} else { } else {
self.render_signed_in(cx) self.render_signed_in(cx)
}) })
.children(self.context_menu.as_ref().map(|(menu, position, _)| {
overlay()
.position(*position)
.anchor(gpui::AnchorCorner::TopLeft)
.child(menu.clone())
}))
} }
} }

View file

@ -1492,6 +1492,10 @@ impl ScrollHandle {
} }
} }
pub fn bounds_for_item(&self, ix: usize) -> Option<Bounds<Pixels>> {
self.0.borrow().child_bounds.get(ix).cloned()
}
/// scroll_to_item scrolls the minimal amount to ensure that the item is /// scroll_to_item scrolls the minimal amount to ensure that the item is
/// fully visible /// fully visible
pub fn scroll_to_item(&self, ix: usize) { pub fn scroll_to_item(&self, ix: usize) {