From 5247cfee441637d7e07ba35796a1c49f5a7607a6 Mon Sep 17 00:00:00 2001 From: yggverse Date: Fri, 31 Jan 2025 01:02:47 +0200 Subject: [PATCH] hide secondary icon on request entry is empty, implement shared method for trait --- .../tab/item/page/navigation/request.rs | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/app/browser/window/tab/item/page/navigation/request.rs b/src/app/browser/window/tab/item/page/navigation/request.rs index 8fadbccc..90540dcb 100644 --- a/src/app/browser/window/tab/item/page/navigation/request.rs +++ b/src/app/browser/window/tab/item/page/navigation/request.rs @@ -44,6 +44,8 @@ pub trait Request { ) -> Result<(), String>; fn update_primary_icon(&self, profile: &Profile); + fn update_secondary_icon(&self); + fn show_identity_dialog(&self, profile: &Rc); fn show_search_dialog(&self, profile: &Rc); @@ -92,14 +94,7 @@ impl Request for Entry { } }); - entry.connect_has_focus_notify(|this| { - if this.focus_child().is_some_and(|text| text.has_focus()) { - this.set_secondary_icon_name(Some("pan-end-symbolic")); - } else { - this.set_secondary_icon_name(None); - this.select_region(0, 0); - } - }); + entry.connect_has_focus_notify(|this| this.update_secondary_icon()); entry.connect_changed({ let profile = profile.clone(); @@ -109,8 +104,9 @@ impl Request for Entry { item_action.reload.set_enabled(!this.text().is_empty()); item_action.home.set_enabled(this.home().is_some()); - // Update primary icon - this.update_primary_icon(&profile) + // Update icons + this.update_primary_icon(&profile); + this.update_secondary_icon(); } }); @@ -220,7 +216,6 @@ impl Request for Entry { } fn update_primary_icon(&self, profile: &Profile) { - // Update primary icon self.first_child().unwrap().remove_css_class("success"); // @TODO handle match primary_icon::from(&self.text()) { @@ -256,6 +251,15 @@ impl Request for Entry { } } + fn update_secondary_icon(&self) { + if !self.text().is_empty() && self.focus_child().is_some_and(|text| text.has_focus()) { + self.set_secondary_icon_name(Some("pan-end-symbolic")); + } else { + self.set_secondary_icon_name(None); + self.select_region(0, 0); + } + } + /// Present Identity [AlertDialog](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.AlertDialog.html) for `Self` fn show_identity_dialog(&self, profile: &Rc) { // connect identity traits