Render header and footer of git menu

This commit is contained in:
Piotr Osiewicz 2023-06-27 12:22:44 +02:00
parent d8d0bdc479
commit ac6e9c88e9

View file

@ -22,6 +22,7 @@ pub fn build_branch_list(
matches: vec![], matches: vec![],
project, project,
selected_index: 0, selected_index: 0,
last_query: String::default(),
}, },
cx, cx,
) )
@ -33,6 +34,7 @@ pub struct BranchListDelegate {
matches: Vec<StringMatch>, matches: Vec<StringMatch>,
project: ModelHandle<Project>, project: ModelHandle<Project>,
selected_index: usize, selected_index: usize,
last_query: String,
} }
impl PickerDelegate for BranchListDelegate { impl PickerDelegate for BranchListDelegate {
@ -109,6 +111,7 @@ impl PickerDelegate for BranchListDelegate {
let delegate = picker.delegate_mut(); let delegate = picker.delegate_mut();
//delegate.branches = actions; //delegate.branches = actions;
delegate.matches = matches; delegate.matches = matches;
delegate.last_query = query;
if delegate.matches.is_empty() { if delegate.matches.is_empty() {
delegate.selected_index = 0; delegate.selected_index = 0;
} else { } else {
@ -175,4 +178,34 @@ impl PickerDelegate for BranchListDelegate {
.with_height(theme.contact_finder.row_height) .with_height(theme.contact_finder.row_height)
.into_any() .into_any()
} }
fn render_header(&self, cx: &AppContext) -> Option<AnyElement<Picker<Self>>> {
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<AnyElement<Picker<Self>>> {
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
}
}
} }