1use gpui2::{view, Context, View};
2
3use crate::prelude::*;
4use crate::{h_stack, Icon, IconButton, IconColor, Input};
5
6#[derive(Clone)]
7pub struct BufferSearch {
8 is_replace_open: bool,
9}
10
11impl BufferSearch {
12 pub fn new() -> Self {
13 Self {
14 is_replace_open: false,
15 }
16 }
17
18 fn toggle_replace(&mut self, cx: &mut ViewContext<Self>) {
19 self.is_replace_open = !self.is_replace_open;
20
21 cx.notify();
22 }
23
24 pub fn view(cx: &mut WindowContext) -> View<Self> {
25 view(cx.entity(|cx| Self::new()), Self::render)
26 }
27
28 fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<Self> {
29 let theme = theme(cx);
30
31 h_stack().bg(theme.toolbar).p_2().child(
32 h_stack().child(Input::new("Search")).child(
33 IconButton::<Self>::new("replace", Icon::Replace)
34 .when(self.is_replace_open, |this| this.color(IconColor::Accent))
35 .on_click(|buffer_search, cx| {
36 buffer_search.toggle_replace(cx);
37 }),
38 ),
39 )
40 }
41}