1use editor::EditorSettings;
2use gpui::FocusHandle;
3use settings::Settings as _;
4use ui::{ButtonCommon, Clickable, Context, Render, Tooltip, Window, prelude::*};
5use workspace::{ItemHandle, StatusItemView};
6
7pub const SEARCH_ICON: IconName = IconName::MagnifyingGlass;
8
9pub struct SearchButton {
10 pane_item_focus_handle: Option<FocusHandle>,
11}
12
13impl SearchButton {
14 pub fn new() -> Self {
15 Self {
16 pane_item_focus_handle: None,
17 }
18 }
19}
20
21impl Render for SearchButton {
22 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl ui::IntoElement {
23 let button = div();
24
25 if !EditorSettings::get_global(cx).search.button {
26 return button.hidden();
27 }
28
29 let focus_handle = self.pane_item_focus_handle.clone();
30 button.child(
31 IconButton::new("project-search-indicator", SEARCH_ICON)
32 .icon_size(IconSize::Small)
33 .tooltip(move |_window, cx| {
34 if let Some(focus_handle) = &focus_handle {
35 Tooltip::for_action_in(
36 "Project Search",
37 &workspace::DeploySearch::default(),
38 focus_handle,
39 cx,
40 )
41 } else {
42 Tooltip::for_action(
43 "Project Search",
44 &workspace::DeploySearch::default(),
45 cx,
46 )
47 }
48 })
49 .on_click(cx.listener(|_this, _, window, cx| {
50 window.dispatch_action(Box::new(workspace::DeploySearch::default()), cx);
51 })),
52 )
53 }
54}
55
56impl StatusItemView for SearchButton {
57 fn set_active_pane_item(
58 &mut self,
59 active_pane_item: Option<&dyn ItemHandle>,
60 _window: &mut Window,
61 cx: &mut Context<Self>,
62 ) {
63 self.pane_item_focus_handle = active_pane_item.map(|item| item.item_focus_handle(cx));
64 }
65}