feat(workspace): allow alternative actions to open files and symbols in split

Co-authored-by: Mikayla Maki <mikayla@zed.dev>
This commit is contained in:
Alex Viscreanu 2023-07-14 21:41:23 +02:00
parent 369ccc725c
commit c7669317ec
No known key found for this signature in database
25 changed files with 277 additions and 80 deletions

View file

@ -7,7 +7,7 @@ use gpui::{
AnyElement, AnyViewHandle, AppContext, Axis, Entity, MouseState, Task, View, ViewContext,
ViewHandle,
};
use menu::{Cancel, Confirm, SelectFirst, SelectLast, SelectNext, SelectPrev};
use menu::{Cancel, Confirm, SecondaryConfirm, SelectFirst, SelectLast, SelectNext, SelectPrev};
use parking_lot::Mutex;
use std::{cmp, sync::Arc};
use util::ResultExt;
@ -34,7 +34,7 @@ pub trait PickerDelegate: Sized + 'static {
fn selected_index(&self) -> usize;
fn set_selected_index(&mut self, ix: usize, cx: &mut ViewContext<Picker<Self>>);
fn update_matches(&mut self, query: String, cx: &mut ViewContext<Picker<Self>>) -> Task<()>;
fn confirm(&mut self, cx: &mut ViewContext<Picker<Self>>);
fn confirm(&mut self, secondary: bool, cx: &mut ViewContext<Picker<Self>>);
fn dismissed(&mut self, cx: &mut ViewContext<Picker<Self>>);
fn render_match(
&self,
@ -118,8 +118,8 @@ impl<D: PickerDelegate> View for Picker<D> {
// Capture mouse events
.on_down(MouseButton::Left, |_, _, _| {})
.on_up(MouseButton::Left, |_, _, _| {})
.on_click(MouseButton::Left, move |_, picker, cx| {
picker.select_index(ix, cx);
.on_click(MouseButton::Left, move |click, picker, cx| {
picker.select_index(ix, click.cmd, cx);
})
.with_cursor_style(CursorStyle::PointingHand)
.into_any()
@ -175,6 +175,7 @@ impl<D: PickerDelegate> Picker<D> {
cx.add_action(Self::select_next);
cx.add_action(Self::select_prev);
cx.add_action(Self::confirm);
cx.add_action(Self::secondary_confirm);
cx.add_action(Self::cancel);
}
@ -288,11 +289,11 @@ impl<D: PickerDelegate> Picker<D> {
cx.notify();
}
pub fn select_index(&mut self, index: usize, cx: &mut ViewContext<Self>) {
pub fn select_index(&mut self, index: usize, cmd: bool, cx: &mut ViewContext<Self>) {
if self.delegate.match_count() > 0 {
self.confirmed = true;
self.delegate.set_selected_index(index, cx);
self.delegate.confirm(cx);
self.delegate.confirm(cmd, cx);
}
}
@ -330,7 +331,12 @@ impl<D: PickerDelegate> Picker<D> {
pub fn confirm(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) {
self.confirmed = true;
self.delegate.confirm(cx);
self.delegate.confirm(false, cx);
}
pub fn secondary_confirm(&mut self, _: &SecondaryConfirm, cx: &mut ViewContext<Self>) {
self.confirmed = true;
self.delegate.confirm(true, cx);
}
fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) {