From 0dc1f810d27deb96f4b74947e56d05363b055156 Mon Sep 17 00:00:00 2001 From: FeuRenard Date: Sun, 12 May 2019 17:59:56 +0200 Subject: [PATCH] headerbar: Add ERROR style to Add entry When you enter an invalid or duplicate URL an error message is shown. But GTK's error style is not applied to the entry. This commit applies GTK's error style to the URL entry when appropriate. part of #45 --- podcasts-gtk/src/headerbar.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/podcasts-gtk/src/headerbar.rs b/podcasts-gtk/src/headerbar.rs index 8f8dc4c..880e822 100644 --- a/podcasts-gtk/src/headerbar.rs +++ b/podcasts-gtk/src/headerbar.rs @@ -107,10 +107,16 @@ impl AddPopover { match Url::parse(&url) { Ok(u) => { if !dbqueries::source_exists(u.as_str())? { + self.entry + .get_style_context() + .remove_class(>k::STYLE_CLASS_ERROR); self.entry .set_icon_from_icon_name(gtk::EntryIconPosition::Secondary, None); self.add.set_sensitive(true); } else { + self.entry + .get_style_context() + .add_class(>k::STYLE_CLASS_ERROR); self.entry.set_icon_from_icon_name( gtk::EntryIconPosition::Secondary, "dialog-error-symbolic", @@ -126,6 +132,9 @@ impl AddPopover { Err(err) => { self.add.set_sensitive(false); if !url.is_empty() { + self.entry + .get_style_context() + .add_class(>k::STYLE_CLASS_ERROR); self.entry.set_icon_from_icon_name( gtk::EntryIconPosition::Secondary, "dialog-error-symbolic", @@ -136,6 +145,9 @@ impl AddPopover { ); error!("Error: {}", err); } else { + self.entry + .get_style_context() + .remove_class(>k::STYLE_CLASS_ERROR); self.entry .set_icon_from_icon_name(gtk::EntryIconPosition::Secondary, None); }