From dff9bf7d7eb4ccea9504b73f7bf14235b0391a16 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Thu, 27 Jul 2023 16:03:26 +0200 Subject: [PATCH] Make row_count of toolbaritem dynamic (WIP). Move result count to the left hand side. --- crates/search/src/project_search.rs | 23 ++++++++++++++++++----- crates/workspace/src/toolbar.rs | 4 ++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index 435b5542a97de620d318a9b175dfcc576b331947..9b6b8da3208b77d47be7f633571720eb34c54cda 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -374,7 +374,9 @@ impl Item for ProjectSearchView { query_text.into() }); Label::new( - tab_name.unwrap_or("Project search".into()), + tab_name + .filter(|name| !name.is_empty()) + .unwrap_or("Project search".into()), tab_theme.label.clone(), ) .aligned() @@ -425,6 +427,7 @@ impl Item for ProjectSearchView { project: ModelHandle, cx: &mut ViewContext, ) -> Task> { + self.results_editor .update(cx, |editor, cx| editor.reload(project, cx)) } @@ -825,6 +828,7 @@ impl ProjectSearchView { } fn model_changed(&mut self, cx: &mut ViewContext) { + let match_ranges = self.model.read(cx).match_ranges.clone(); if match_ranges.is_empty() { self.active_match_index = None; @@ -1026,8 +1030,11 @@ impl ProjectSearchBar { if let Some(search_view) = self.active_project_search.as_ref() { search_view.update(cx, |search_view, cx| { search_view.filters_enabled = !search_view.filters_enabled; + search_view.included_files_editor.update(cx, |_, cx| {cx.notify()}); + search_view.excluded_files_editor.update(cx, |_, cx| {cx.notify()}); search_view.semantic = None; search_view.search(cx); + cx.notify(); }); cx.notify(); true @@ -1325,12 +1332,12 @@ impl View for ProjectSearchBar { let semantic_index = SemanticIndex::enabled(cx).then(|| self.render_semantic_search_button(cx)); Flex::row() - .with_child(Flex::row().flex(1., true)) + .with_child(Flex::column().with_child(Flex::row().with_children(matches).aligned() + .left()).flex(1., true)) .with_child( Flex::column() .with_child( Flex::row() - .with_children(matches) .with_child( Flex::row() .with_child(query) @@ -1413,8 +1420,14 @@ impl ToolbarItemView for ProjectSearchBar { } } - fn row_count(&self) -> usize { - 2 + fn row_count(&self, cx: &ViewContext) -> usize { + self.active_project_search + .as_ref() + .map(|search| { + let offset = search.read(cx).filters_enabled as usize; + 1 + offset + }) + .unwrap_or_else(|| 1) } } diff --git a/crates/workspace/src/toolbar.rs b/crates/workspace/src/toolbar.rs index 69394b842132b61b6403537d76eacf3f6b0b484f..3fa37f36664449a3342ecef4d1e8755b0ba8cd2a 100644 --- a/crates/workspace/src/toolbar.rs +++ b/crates/workspace/src/toolbar.rs @@ -25,7 +25,7 @@ pub trait ToolbarItemView: View { /// Number of times toolbar's height will be repeated to get the effective height. /// Useful when multiple rows one under each other are needed. /// The rows have the same width and act as a whole when reacting to resizes and similar events. - fn row_count(&self) -> usize { + fn row_count(&self, _cx: &ViewContext) -> usize { 1 } } @@ -362,7 +362,7 @@ impl ToolbarItemViewHandle for ViewHandle { } fn row_count(&self, cx: &WindowContext) -> usize { - self.read(cx).row_count() + self.read_with(cx, |this, cx| this.row_count(cx)) } }