subspace_dashboard/handle/
find.rs1use crate::{Dashboard, find_in_page::FindInPage};
3use gpui_kit::{AnyView, App, AppContext as _, Entity, Window};
4pub(super) fn create<D: Dashboard>(
5 owner: &Entity<D>,
6 window: &mut Window,
7 cx: &mut App,
8) -> Entity<FindInPage> {
9 let read = owner.downgrade();
10 let reveal = read.clone();
11 let mode = read.clone();
12 let provider = crate::find_in_page::Provider {
13 virtual_content: std::rc::Rc::new(move |cx| {
14 mode.read_with(cx, |board, cx| board.find_virtual_content(cx))
15 .unwrap_or(false)
16 }),
17 snapshot: std::rc::Rc::new(move |cx| {
18 read.read_with(cx, |board, cx| board.find_documents(cx))
19 .unwrap_or_default()
20 }),
21 reveal: std::rc::Rc::new(move |id, window, cx| {
22 _ = reveal.update(cx, |board, cx| board.reveal_find_document(id, window, cx));
23 }),
24 };
25 cx.new(|cx| {
26 let mut pane =
27 crate::find_in_page::FindInPage::new(owner.clone().into(), provider, window, cx);
28 pane.observe_owner_in(owner, window, cx);
29 pane
30 })
31}
32
33impl super::DashboardHandle {
34 pub fn find_commands(&self, cx: &App) -> Vec<crate::PaletteCommand> {
35 crate::find_in_page::commands(
36 self.find
37 .get()
38 .is_some_and(|find| find.read(cx).is_open(cx)),
39 )
40 }
41 pub fn find_view(&self, window: &mut Window, cx: &mut App) -> AnyView {
42 self.find
43 .get_or_init(|| self.inner.find_view(window, cx))
44 .clone()
45 .into()
46 }
47}