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();
// 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
}

View File

@ -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)
}
}