From ac6e9c88e9400da223e2d0996c11c40d58ee24cd Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Tue, 27 Jun 2023 12:22:44 +0200 Subject: [PATCH] Render header and footer of git menu --- crates/collab_ui/src/branch_list.rs | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/crates/collab_ui/src/branch_list.rs b/crates/collab_ui/src/branch_list.rs index 8d755e8aa4..d946b9da3d 100644 --- a/crates/collab_ui/src/branch_list.rs +++ b/crates/collab_ui/src/branch_list.rs @@ -22,6 +22,7 @@ pub fn build_branch_list( matches: vec![], project, selected_index: 0, + last_query: String::default(), }, cx, ) @@ -33,6 +34,7 @@ pub struct BranchListDelegate { matches: Vec, project: ModelHandle, selected_index: usize, + last_query: String, } impl PickerDelegate for BranchListDelegate { @@ -109,6 +111,7 @@ impl PickerDelegate for BranchListDelegate { let delegate = picker.delegate_mut(); //delegate.branches = actions; delegate.matches = matches; + delegate.last_query = query; if delegate.matches.is_empty() { delegate.selected_index = 0; } else { @@ -175,4 +178,34 @@ impl PickerDelegate for BranchListDelegate { .with_height(theme.contact_finder.row_height) .into_any() } + fn render_header(&self, cx: &AppContext) -> Option>> { + let theme = &theme::current(cx); + let style = theme.picker.no_matches.label.clone(); + if self.last_query.is_empty() { + Some( + Flex::row() + .with_child(Label::new("Recent branches", style)) + .into_any(), + ) + } else { + Some( + Flex::row() + .with_child(Label::new("Branches", style)) + .into_any(), + ) + } + } + fn render_footer(&self, cx: &AppContext) -> Option>> { + if !self.last_query.is_empty() && !self.matches.is_empty() { + let theme = &theme::current(cx); + let style = theme.picker.no_matches.label.clone(); + Some( + Flex::row() + .with_child(Label::new(format!("{} matches", self.matches.len()), style)) + .into_any(), + ) + } else { + None + } + } }