1use std::path::PathBuf;
2
3use gpui3::{view, Context, View};
4
5use crate::prelude::*;
6use crate::{
7 hello_world_rust_editor_with_status_example, v_stack, Breadcrumb, Buffer, BufferSearch, Icon,
8 IconButton, IconColor, Symbol, Tab, TabBar, Toolbar,
9};
10
11#[derive(Clone)]
12pub struct EditorPane {
13 tabs: Vec<Tab<Self>>,
14 path: PathBuf,
15 symbols: Vec<Symbol>,
16 buffer: Buffer<Self>,
17 is_buffer_search_open: bool,
18}
19
20impl EditorPane {
21 pub fn new(
22 tabs: Vec<Tab<Self>>,
23 path: PathBuf,
24 symbols: Vec<Symbol>,
25 buffer: Buffer<Self>,
26 ) -> Self {
27 Self {
28 tabs,
29 path,
30 symbols,
31 buffer,
32 is_buffer_search_open: false,
33 }
34 }
35
36 pub fn toggle_buffer_search(&mut self, cx: &mut ViewContext<Self>) {
37 self.is_buffer_search_open = !self.is_buffer_search_open;
38
39 cx.notify();
40 }
41
42 pub fn view(cx: &mut WindowContext) -> View<Self> {
43 let theme = theme(cx);
44
45 view(
46 cx.entity(|cx| hello_world_rust_editor_with_status_example(&theme)),
47 Self::render,
48 )
49 }
50
51 fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<ViewState = Self> {
52 v_stack()
53 .w_full()
54 .h_full()
55 .flex_1()
56 .child(TabBar::new(self.tabs.clone()))
57 .child(
58 Toolbar::new()
59 .left_item(Breadcrumb::new(self.path.clone(), self.symbols.clone()))
60 .right_items(vec![
61 IconButton::new(Icon::InlayHint),
62 IconButton::<Self>::new(Icon::MagnifyingGlass)
63 .when(self.is_buffer_search_open, |this| {
64 this.color(IconColor::Accent)
65 })
66 .on_click(|editor, cx| {
67 editor.toggle_buffer_search(cx);
68 }),
69 IconButton::new(Icon::MagicWand),
70 ]),
71 )
72 .children(Some(BufferSearch::new()).filter(|_| self.is_buffer_search_open))
73 .child(self.buffer.clone())
74 }
75}