From 904719d52cba3b54d9c19d55c0e15bbcbff0d871 Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Fri, 3 Nov 2023 19:09:26 +0100 Subject: [PATCH] search entry: Show clear icon --- src/search_entry.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/search_entry.rs b/src/search_entry.rs index 45e78c1..18d492d 100644 --- a/src/search_entry.rs +++ b/src/search_entry.rs @@ -146,7 +146,11 @@ impl MusicusSearchEntry { } pub fn add_tag(&self, tag: Tag) { - self.imp().text.set_text(""); + let imp = self.imp(); + + imp.clear_icon.set_visible(true); + imp.text.set_text(""); + let tag = MusicusSearchTag::new(tag); tag.connect_remove(clone!(@weak self as self_ => move |tag| { @@ -161,8 +165,8 @@ impl MusicusSearchEntry { self_.emit_by_name::<()>("query-changed", &[]); })); - self.imp().tags_box.append(&tag); - self.imp().tags.borrow_mut().push(tag); + imp.tags_box.append(&tag); + imp.tags.borrow_mut().push(tag); self.emit_by_name::<()>("query-changed", &[]); } @@ -207,14 +211,18 @@ impl MusicusSearchEntry { #[template_callback] async fn text_changed(&self, text: >k::Text) { - self.imp().clear_icon.set_visible(!text.text().is_empty()); + let imp = self.imp(); - if let Some(cancellable) = self.imp().query_changed.borrow_mut().take() { + if imp.tags.borrow().is_empty() { + imp.clear_icon.set_visible(!text.text().is_empty()); + } + + if let Some(cancellable) = imp.query_changed.borrow_mut().take() { cancellable.cancel(); } let cancellable = gio::Cancellable::new(); - self.imp().query_changed.replace(Some(cancellable.clone())); + imp.query_changed.replace(Some(cancellable.clone())); let _ = gio::CancellableFuture::new( async {