Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Project Search button to the Status Bar #19238

2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions assets/settings/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@
"show": null
}
},
"project_search": {
// Whether to show the project search button in the status bar
"button": false
},
"outline_panel": {
// Whether to show the outline panel button in the status bar
"button": true,
Expand Down
2 changes: 2 additions & 0 deletions crates/search/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ gpui.workspace = true
language.workspace = true
menu.workspace = true
project.workspace = true
schemars.workspace = true
serde.workspace = true
serde_derive.workspace = true
serde_json.workspace = true
settings.workspace = true
smol.workspace = true
Expand Down
74 changes: 74 additions & 0 deletions crates/search/src/items.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use editor::Editor;
use gpui::{Empty, IntoElement, Render, ViewContext, WeakView};
use ui::{prelude::*, Color, IconName, Tooltip};
use workspace::{item::ItemHandle, DeploySearch, StatusItemView, Workspace};

use crate::{ProjectSearchSettings, ProjectSearchView};
use settings::Settings;

pub struct ProjectSearchIndicator {
active_editor: Option<WeakView<Editor>>,
workspace: WeakView<Workspace>,
}

impl Render for ProjectSearchIndicator {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let project_search_indicator = if ProjectSearchSettings::get_global(cx).button {
Some(
IconButton::new("project-search-indicator", IconName::MagnifyingGlass)
.icon_size(IconSize::Small)
.icon_color(Color::Default)
.tooltip(|cx| {
Tooltip::for_action("Project Search", &DeploySearch::default(), cx)
})
.on_click(cx.listener(|this, _, cx| {
if let Some(workspace) = this.workspace.upgrade() {
workspace.update(cx, |workspace, cx| {
ProjectSearchView::deploy_search(
workspace,
&DeploySearch::default(),
cx,
)
})
}
})),
)
} else {
None
};

if let Some(search_indicator) = project_search_indicator {
h_flex()
.h(rems(1.375))
.gap_2()
.child(search_indicator)
.into_any()
} else {
Empty.into_any()
}
}
}

impl ProjectSearchIndicator {
pub fn new(workspace: &Workspace) -> Self {
Self {
active_editor: None,
workspace: workspace.weak_handle(),
}
}
}

impl StatusItemView for ProjectSearchIndicator {
fn set_active_pane_item(
&mut self,
active_pane_item: Option<&dyn ItemHandle>,
cx: &mut ViewContext<Self>,
) {
if let Some(editor) = active_pane_item.and_then(|item| item.downcast::<Editor>()) {
self.active_editor = Some(editor.downgrade());
} else {
self.active_editor = None;
}
cx.notify();
}
}
11 changes: 8 additions & 3 deletions crates/search/src/project_search.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{
FocusSearch, NextHistoryQuery, PreviousHistoryQuery, ReplaceAll, ReplaceNext, SearchOptions,
FocusSearch, NextHistoryQuery, PreviousHistoryQuery,
ProjectSearchSettings as GlobalProjectSearchSettings, ReplaceAll, ReplaceNext, SearchOptions,
SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, ToggleIncludeIgnored, ToggleRegex,
ToggleReplace, ToggleWholeWord,
};
Expand Down Expand Up @@ -58,7 +59,12 @@ struct ActiveSettings(HashMap<WeakModel<Project>, ProjectSearchSettings>);

impl Global for ActiveSettings {}

pub fn init_settings(cx: &mut AppContext) {
GlobalProjectSearchSettings::register(cx);
}

pub fn init(cx: &mut AppContext) {
init_settings(cx);
cx.set_global(ActiveSettings::default());
cx.observe_new_views(|workspace: &mut Workspace, _cx| {
register_workspace_action(workspace, move |search_bar, _: &FocusSearch, cx| {
Expand Down Expand Up @@ -3577,9 +3583,8 @@ pub mod tests {
cx.update(|cx| {
let settings = SettingsStore::test(cx);
cx.set_global(settings);

init_settings(cx);
theme::init(theme::LoadThemes::JustBase, cx);

language::init(cx);
client::init_settings(cx);
editor::init(cx);
Expand Down
29 changes: 29 additions & 0 deletions crates/search/src/project_search_settings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use schemars::JsonSchema;
use serde_derive::{Deserialize, Serialize};
use settings::{Settings, SettingsSources};

#[derive(Deserialize, Debug, Clone, Copy, PartialEq)]
pub struct ProjectSearchSettings {
pub button: bool,
}

#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
pub struct ProjectSearchSettingsContent {
/// Whether to show the project search button in the status bar.
///
/// Default: false
pub button: Option<bool>,
}

impl Settings for ProjectSearchSettings {
const KEY: Option<&'static str> = Some("project_search");

type FileContent = ProjectSearchSettingsContent;

fn load(
sources: SettingsSources<Self::FileContent>,
_: &mut gpui::AppContext,
) -> anyhow::Result<Self> {
sources.json_merge()
}
}
3 changes: 3 additions & 0 deletions crates/search/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ use editor::SearchSettings;
use gpui::{actions, Action, AppContext, FocusHandle, IntoElement};
use project::search::SearchQuery;
pub use project_search::ProjectSearchView;
pub use project_search_settings::ProjectSearchSettings;
use ui::{prelude::*, Tooltip};
use ui::{ButtonStyle, IconButton, IconButtonShape};
use workspace::notifications::NotificationId;
use workspace::{Toast, Workspace};

pub mod buffer_search;
pub mod items;
pub mod project_search;
pub mod project_search_settings;
pub(crate) mod search_bar;

pub fn init(cx: &mut AppContext) {
Expand Down
3 changes: 3 additions & 0 deletions crates/zed/src/zed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ pub fn initialize_workspace(
inline_completion_button::InlineCompletionButton::new(app_state.fs.clone(), cx)
});

let project_search =
cx.new_view(|_| search::items::ProjectSearchIndicator::new(workspace));
let diagnostic_summary =
cx.new_view(|cx| diagnostics::items::DiagnosticIndicator::new(workspace, cx));
let activity_indicator =
Expand All @@ -209,6 +211,7 @@ pub fn initialize_workspace(
let cursor_position =
cx.new_view(|_| go_to_line::cursor_position::CursorPosition::new(workspace));
workspace.status_bar().update(cx, |status_bar, cx| {
status_bar.add_left_item(project_search, cx);
status_bar.add_left_item(diagnostic_summary, cx);
status_bar.add_left_item(activity_indicator, cx);
status_bar.add_right_item(inline_completion_button, cx);
Expand Down
14 changes: 14 additions & 0 deletions docs/src/configuring-zed.md
Original file line number Diff line number Diff line change
Expand Up @@ -2163,6 +2163,20 @@ Run the `theme selector: toggle` action in the command palette to see a current
}
```

## Project Search

- Description: Configuration for the Project Search Button
- Setting: 'project_search'
- Default:

```json
{
"project_search": {
"button": false
}
},
```

## Assistant Panel

- Description: Customize assistant panel
Expand Down
Loading