1use gpui3::{view, Context, View};
2
3use crate::prelude::*;
4use crate::{h_stack, Icon, IconButton, IconColor, Input};
5
6pub struct BufferSearch {
7 is_replace_open: bool,
8}
9
10impl BufferSearch {
11 pub fn new() -> Self {
12 Self {
13 is_replace_open: false,
14 }
15 }
16
17 fn toggle_replace(&mut self, cx: &mut ViewContext<Self>) {
18 self.is_replace_open = !self.is_replace_open;
19
20 cx.notify();
21 }
22
23 pub fn view(cx: &mut WindowContext) -> View<Self> {
24 let theme = theme(cx);
25
26 view(cx.entity(|cx| Self::new()), Self::render)
27 }
28
29 fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<ViewState = Self> {
30 let theme = theme(cx);
31
32 h_stack()
33 .bg(theme.highest.base.default.background)
34 .p_2()
35 .child(
36 h_stack()
37 .child(Input::new("Search (↑/↓ for previous/next query)"))
38 .child(
39 IconButton::<Self>::new(Icon::Replace)
40 .when(self.is_replace_open, |this| this.color(IconColor::Accent))
41 .on_click(|buffer_search, cx| {
42 buffer_search.toggle_replace(cx);
43 }),
44 ),
45 )
46 }
47}