1use crate::prelude::*;
2use crate::{h_stack, Icon, IconButton, Input, TextColor};
3use gpui::{Div, Render, RenderOnce, View, VisualContext};
4
5#[derive(Clone)]
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 cx.build_view(|cx| Self::new())
25 }
26}
27
28impl Render<Self> for BufferSearch {
29 type Element = Div<Self>;
30
31 fn render(&mut self, cx: &mut ViewContext<Self>) -> Div<Self> {
32 h_stack()
33 .bg(cx.theme().colors().toolbar_background)
34 .p_2()
35 .child(
36 h_stack().child(Input::new("Search")).child(
37 IconButton::<Self>::new("replace", Icon::Replace)
38 .when(self.is_replace_open, |this| this.color(TextColor::Accent))
39 .on_click(|buffer_search, cx| {
40 buffer_search.toggle_replace(cx);
41 }),
42 ),
43 )
44 }
45}