Render match count next to branch label

This commit is contained in:
Piotr Osiewicz 2023-07-01 01:38:36 +02:00
parent 7c2c1a279b
commit 525521eeb3
2 changed files with 58 additions and 45 deletions

View file

@ -1,6 +1,8 @@
use anyhow::{anyhow, bail}; use anyhow::{anyhow, bail};
use fuzzy::{StringMatch, StringMatchCandidate}; use fuzzy::{StringMatch, StringMatchCandidate};
use gpui::{elements::*, AppContext, MouseState, Task, ViewContext, ViewHandle}; use gpui::{
elements::*, platform::MouseButton, AppContext, MouseState, Task, ViewContext, ViewHandle,
};
use picker::{Picker, PickerDelegate, PickerEvent}; use picker::{Picker, PickerDelegate, PickerEvent};
use std::{ops::Not, sync::Arc}; use std::{ops::Not, sync::Arc};
use util::ResultExt; use util::ResultExt;
@ -210,11 +212,13 @@ 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>>> { fn render_header(
&self,
cx: &mut ViewContext<Picker<Self>>,
) -> Option<AnyElement<Picker<Self>>> {
let theme = &theme::current(cx); let theme = &theme::current(cx);
let style = theme.picker.header.clone(); let style = theme.picker.header.clone();
if self.last_query.is_empty() { let label = if self.last_query.is_empty() {
Some(
Stack::new() Stack::new()
.with_child( .with_child(
Flex::row() Flex::row()
@ -225,16 +229,12 @@ impl PickerDelegate for BranchListDelegate {
) )
.contained() .contained()
.with_style(style.container) .with_style(style.container)
.into_any(), .into_any()
)
} else { } else {
Some(
Stack::new() Stack::new()
.with_child( .with_child(
Flex::row() Flex::row()
.with_child( .with_child(Label::new("Branches", style.label.clone()).aligned().left())
Label::new("Branches", style.label.clone()).aligned().left(),
)
.contained() .contained()
.with_style(style.container), .with_style(style.container),
) )
@ -252,8 +252,15 @@ impl PickerDelegate for BranchListDelegate {
.contained() .contained()
.with_style(style.container) .with_style(style.container)
.constrained() .constrained()
.into_any()
};
Some(
MouseEventHandler::<BranchList, _>::new(0, cx, move |_, _| label)
.on_click(MouseButton::Left, move |_, _, _| {})
.on_down_out(MouseButton::Left, move |_, _, cx| {
cx.emit(PickerEvent::Dismiss)
})
.into_any(), .into_any(),
) )
} }
} }
}

View file

@ -45,10 +45,16 @@ pub trait PickerDelegate: Sized + 'static {
fn center_selection_after_match_updates(&self) -> bool { fn center_selection_after_match_updates(&self) -> bool {
false false
} }
fn render_header(&self, _cx: &AppContext) -> Option<AnyElement<Picker<Self>>> { fn render_header(
&self,
_cx: &mut ViewContext<Picker<Self>>,
) -> Option<AnyElement<Picker<Self>>> {
None None
} }
fn render_footer(&self, _cx: &AppContext) -> Option<AnyElement<Picker<Self>>> { fn render_footer(
&self,
_cx: &mut ViewContext<Picker<Self>>,
) -> Option<AnyElement<Picker<Self>>> {
None None
} }
} }