implement status actions

This commit is contained in:
yggverse 2024-12-10 21:04:00 +02:00
parent 7bdf38d327
commit 556a85b7e5
2 changed files with 31 additions and 9 deletions

View File

@ -50,8 +50,7 @@ pub fn new(
progress.disable(); progress.disable();
// update `status` // update `status`
status.label.set_css_classes(&["warning"]); status.set_warning("Operation cancelled");
status.label.set_label("Operation cancelled");
// hide self // hide self
button.set_visible(false); button.set_visible(false);
@ -86,8 +85,7 @@ pub fn new(
file_launcher.set_file(Some(&file)); file_launcher.set_file(Some(&file));
// update `status` // update `status`
status.label.set_css_classes(&[]); status.set_default("Loading...");
status.label.set_label("Loading...");
// show `cancel` button // show `cancel` button
cancel.button.set_visible(true); cancel.button.set_visible(true);
@ -109,8 +107,7 @@ pub fn new(
progress.disable(); progress.disable();
// update `status` // update `status`
status.label.set_css_classes(&["warning"]); status.set_warning(e.message());
status.label.set_label(e.message())
} }
} }
} }
@ -129,8 +126,7 @@ pub fn new(
let button = button.clone(); let button = button.clone();
move |result| { move |result| {
if let Err(ref e) = result { if let Err(ref e) = result {
status.label.set_css_classes(&["error"]); status.set_error(e.message())
status.label.set_label(e.message())
} }
button.set_sensitive(true); // unlock button.set_sensitive(true); // unlock
} }

View File

@ -1,7 +1,11 @@
use gtk::Label; use gtk::{prelude::WidgetExt, Label};
// Defaults // 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 LABEL: &str = "Choose location to download";
const MARGIN: i32 = 16; const MARGIN: i32 = 16;
@ -20,4 +24,26 @@ impl Status {
label: Label::builder().label(LABEL).margin_top(MARGIN).build(), 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)
}
} }