diff --git a/src/app/browser/window/tab/item/page/content/status/download.rs b/src/app/browser/window/tab/item/page/content/status/download.rs index 8837f013..3015c6d1 100644 --- a/src/app/browser/window/tab/item/page/content/status/download.rs +++ b/src/app/browser/window/tab/item/page/content/status/download.rs @@ -50,8 +50,7 @@ pub fn new( progress.disable(); // update `status` - status.label.set_css_classes(&["warning"]); - status.label.set_label("Operation cancelled"); + status.set_warning("Operation cancelled"); // hide self button.set_visible(false); @@ -86,8 +85,7 @@ pub fn new( file_launcher.set_file(Some(&file)); // update `status` - status.label.set_css_classes(&[]); - status.label.set_label("Loading..."); + status.set_default("Loading..."); // show `cancel` button cancel.button.set_visible(true); @@ -109,8 +107,7 @@ pub fn new( progress.disable(); // update `status` - status.label.set_css_classes(&["warning"]); - status.label.set_label(e.message()) + status.set_warning(e.message()); } } } @@ -129,8 +126,7 @@ pub fn new( let button = button.clone(); move |result| { if let Err(ref e) = result { - status.label.set_css_classes(&["error"]); - status.label.set_label(e.message()) + status.set_error(e.message()) } button.set_sensitive(true); // unlock } diff --git a/src/app/browser/window/tab/item/page/content/status/download/status.rs b/src/app/browser/window/tab/item/page/content/status/download/status.rs index 01638ec6..46a602c9 100644 --- a/src/app/browser/window/tab/item/page/content/status/download/status.rs +++ b/src/app/browser/window/tab/item/page/content/status/download/status.rs @@ -1,7 +1,11 @@ -use gtk::Label; +use gtk::{prelude::WidgetExt, Label}; // Defaults +const CSS_CLASSES_DEFAULT: &[&str; 0] = &[]; +const CSS_CLASSES_ERROR: &[&str; 1] = &["error"]; +const CSS_CLASSES_SUCCESS: &[&str; 1] = &["success"]; +const CSS_CLASSES_WARNING: &[&str; 1] = &["warning"]; const LABEL: &str = "Choose location to download"; const MARGIN: i32 = 16; @@ -20,4 +24,26 @@ impl Status { label: Label::builder().label(LABEL).margin_top(MARGIN).build(), } } + + // Actions + + pub fn set_default(&self, label: &str) { + self.label.set_css_classes(CSS_CLASSES_DEFAULT); + self.label.set_label(label) + } + + pub fn set_error(&self, label: &str) { + self.label.set_css_classes(CSS_CLASSES_ERROR); + self.label.set_label(label) + } + + pub fn set_success(&self, label: &str) { + self.label.set_css_classes(CSS_CLASSES_SUCCESS); + self.label.set_label(label) + } + + pub fn set_warning(&self, label: &str) { + self.label.set_css_classes(CSS_CLASSES_WARNING); + self.label.set_label(label) + } }