recent_projects.rs

 1use std::marker::PhantomData;
 2
 3use crate::prelude::*;
 4use crate::{OrderMethod, Palette, PaletteItem};
 5
 6#[derive(Element)]
 7pub struct RecentProjects<S: 'static + Send + Sync + Clone> {
 8    state_type: PhantomData<S>,
 9    scroll_state: ScrollState,
10}
11
12impl<S: 'static + Send + Sync + Clone> RecentProjects<S> {
13    pub fn new() -> Self {
14        Self {
15            state_type: PhantomData,
16            scroll_state: ScrollState::default(),
17        }
18    }
19
20    fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
21        div().child(
22            Palette::new(self.scroll_state.clone())
23                .items(vec![
24                    PaletteItem::new("zed").sublabel("~/projects/zed"),
25                    PaletteItem::new("saga").sublabel("~/projects/saga"),
26                    PaletteItem::new("journal").sublabel("~/journal"),
27                    PaletteItem::new("dotfiles").sublabel("~/dotfiles"),
28                    PaletteItem::new("zed.dev").sublabel("~/projects/zed.dev"),
29                    PaletteItem::new("laminar").sublabel("~/projects/laminar"),
30                ])
31                .placeholder("Recent Projects...")
32                .empty_string("No matches")
33                .default_order(OrderMethod::Ascending),
34        )
35    }
36}
37
38#[cfg(feature = "stories")]
39pub use stories::*;
40
41#[cfg(feature = "stories")]
42mod stories {
43    use crate::Story;
44
45    use super::*;
46
47    #[derive(Element)]
48    pub struct RecentProjectsStory<S: 'static + Send + Sync + Clone> {
49        state_type: PhantomData<S>,
50    }
51
52    impl<S: 'static + Send + Sync + Clone> RecentProjectsStory<S> {
53        pub fn new() -> Self {
54            Self {
55                state_type: PhantomData,
56            }
57        }
58
59        fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
60            Story::container(cx)
61                .child(Story::title_for::<_, RecentProjects<S>>(cx))
62                .child(Story::label(cx, "Default"))
63                .child(RecentProjects::new())
64        }
65    }
66}