search_status_button.rs

 1use editor::EditorSettings;
 2use settings::Settings as _;
 3use ui::{ButtonCommon, Clickable, Context, Render, Tooltip, Window, prelude::*};
 4use workspace::{ItemHandle, StatusItemView};
 5
 6pub const SEARCH_ICON: IconName = IconName::MagnifyingGlass;
 7
 8pub struct SearchButton;
 9
10impl SearchButton {
11    pub fn new() -> Self {
12        Self {}
13    }
14}
15
16impl Render for SearchButton {
17    fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl ui::IntoElement {
18        let button = div();
19
20        if !EditorSettings::get_global(cx).search.button {
21            return button.w_0().invisible();
22        }
23
24        button.child(
25            IconButton::new("project-search-indicator", SEARCH_ICON)
26                .icon_size(IconSize::Small)
27                .tooltip(|window, cx| {
28                    Tooltip::for_action(
29                        "Project Search",
30                        &workspace::DeploySearch::default(),
31                        window,
32                        cx,
33                    )
34                })
35                .on_click(cx.listener(|_this, _, window, cx| {
36                    window.dispatch_action(Box::new(workspace::DeploySearch::default()), cx);
37                })),
38        )
39    }
40}
41
42impl StatusItemView for SearchButton {
43    fn set_active_pane_item(
44        &mut self,
45        _active_pane_item: Option<&dyn ItemHandle>,
46        _window: &mut Window,
47        _cx: &mut Context<Self>,
48    ) {
49    }
50}