commit
426d298173
8 changed files with 491 additions and 4 deletions
|
@ -16,6 +16,7 @@ menu = { package = "menu2", path = "../menu2" }
|
|||
settings = { package = "settings2", path = "../settings2" }
|
||||
util = { path = "../util" }
|
||||
theme = { package = "theme2", path = "../theme2" }
|
||||
workspace = { package = "workspace2", path = "../workspace2"}
|
||||
|
||||
parking_lot.workspace = true
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
use editor::Editor;
|
||||
use gpui::{
|
||||
div, prelude::*, rems, uniform_list, AnyElement, AppContext, DismissEvent, Div, EventEmitter,
|
||||
FocusHandle, FocusableView, MouseButton, MouseDownEvent, Render, Task, UniformListScrollHandle,
|
||||
View, ViewContext, WindowContext,
|
||||
FocusHandle, FocusableView, Length, MouseButton, MouseDownEvent, Render, Task,
|
||||
UniformListScrollHandle, View, ViewContext, WindowContext,
|
||||
};
|
||||
use std::{cmp, sync::Arc};
|
||||
use ui::{prelude::*, v_stack, Color, Divider, Label};
|
||||
use workspace::ModalView;
|
||||
|
||||
pub struct Picker<D: PickerDelegate> {
|
||||
pub delegate: D,
|
||||
|
@ -13,6 +14,7 @@ pub struct Picker<D: PickerDelegate> {
|
|||
editor: View<Editor>,
|
||||
pending_update_matches: Option<Task<()>>,
|
||||
confirm_on_update: Option<bool>,
|
||||
width: Option<Length>,
|
||||
}
|
||||
|
||||
pub trait PickerDelegate: Sized + 'static {
|
||||
|
@ -55,11 +57,17 @@ impl<D: PickerDelegate> Picker<D> {
|
|||
scroll_handle: UniformListScrollHandle::new(),
|
||||
pending_update_matches: None,
|
||||
confirm_on_update: None,
|
||||
width: None,
|
||||
};
|
||||
this.update_matches("".to_string(), cx);
|
||||
this
|
||||
}
|
||||
|
||||
pub fn width(mut self, width: impl Into<gpui::Length>) -> Self {
|
||||
self.width = Some(width.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn focus(&self, cx: &mut WindowContext) {
|
||||
self.editor.update(cx, |editor, cx| editor.focus(cx));
|
||||
}
|
||||
|
@ -197,6 +205,7 @@ impl<D: PickerDelegate> Picker<D> {
|
|||
}
|
||||
|
||||
impl<D: PickerDelegate> EventEmitter<DismissEvent> for Picker<D> {}
|
||||
impl<D: PickerDelegate> ModalView for Picker<D> {}
|
||||
|
||||
impl<D: PickerDelegate> Render for Picker<D> {
|
||||
type Element = Div;
|
||||
|
@ -221,6 +230,9 @@ impl<D: PickerDelegate> Render for Picker<D> {
|
|||
div()
|
||||
.key_context("picker")
|
||||
.size_full()
|
||||
.when_some(self.width, |el, width| {
|
||||
el.w(width)
|
||||
})
|
||||
.overflow_hidden()
|
||||
.elevation_3(cx)
|
||||
.on_action(cx.listener(Self::select_next))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue