1use std::path::PathBuf;
2
3use gpui2::{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 buffer_search: View<BufferSearch>,
18 is_buffer_search_open: bool,
19}
20
21impl EditorPane {
22 pub fn new(
23 cx: &mut WindowContext,
24 tabs: Vec<Tab<Self>>,
25 path: PathBuf,
26 symbols: Vec<Symbol>,
27 buffer: Buffer<Self>,
28 ) -> Self {
29 Self {
30 tabs,
31 path,
32 symbols,
33 buffer,
34 buffer_search: BufferSearch::view(cx),
35 is_buffer_search_open: false,
36 }
37 }
38
39 pub fn toggle_buffer_search(&mut self, cx: &mut ViewContext<Self>) {
40 self.is_buffer_search_open = !self.is_buffer_search_open;
41
42 cx.notify();
43 }
44
45 pub fn view(cx: &mut WindowContext) -> View<Self> {
46 view(
47 cx.entity(|cx| hello_world_rust_editor_with_status_example(cx)),
48 Self::render,
49 )
50 }
51
52 fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<ViewState = Self> {
53 v_stack()
54 .w_full()
55 .h_full()
56 .flex_1()
57 .child(TabBar::new("editor-pane-tabs", self.tabs.clone()).can_navigate((false, true)))
58 .child(
59 Toolbar::new()
60 .left_item(Breadcrumb::new(self.path.clone(), self.symbols.clone()))
61 .right_items(vec![
62 IconButton::new("toggle_inlay_hints", Icon::InlayHint),
63 IconButton::<Self>::new("buffer_search", Icon::MagnifyingGlass)
64 .when(self.is_buffer_search_open, |this| {
65 this.color(IconColor::Accent)
66 })
67 .on_click(|editor, cx| {
68 editor.toggle_buffer_search(cx);
69 }),
70 IconButton::new("inline_assist", Icon::MagicWand),
71 ]),
72 )
73 .children(Some(self.buffer_search.clone()).filter(|_| self.is_buffer_search_open))
74 .child(self.buffer.clone())
75 }
76}