errors during the upload are now shown in a separate user-friendly alert dialog, and you can also choose to upload the file to no folder
82 lines
2 KiB
Rust
82 lines
2 KiB
Rust
use relm4::{
|
|
SimpleComponent,
|
|
adw::{self, prelude::*},
|
|
gtk::glib::clone,
|
|
};
|
|
|
|
pub struct Dialog {
|
|
window: adw::ApplicationWindow,
|
|
visible: bool,
|
|
heading: String,
|
|
body: String,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum DialogInput {
|
|
Show { heading: String, body: String },
|
|
Dismiss,
|
|
}
|
|
|
|
pub struct DialogWidgets {
|
|
dialog: adw::AlertDialog,
|
|
}
|
|
|
|
impl SimpleComponent for Dialog {
|
|
type Init = adw::ApplicationWindow;
|
|
type Root = adw::AlertDialog;
|
|
type Widgets = DialogWidgets;
|
|
type Input = DialogInput;
|
|
type Output = ();
|
|
|
|
fn init_root() -> Self::Root {
|
|
let dialog = adw::AlertDialog::builder().close_response("ok").build();
|
|
dialog.add_response("ok", "OK");
|
|
dialog
|
|
}
|
|
|
|
fn init(
|
|
window: Self::Init,
|
|
root: Self::Root,
|
|
sender: relm4::ComponentSender<Self>,
|
|
) -> relm4::ComponentParts<Self> {
|
|
let model = Self {
|
|
window,
|
|
visible: false,
|
|
heading: String::new(),
|
|
body: String::new(),
|
|
};
|
|
|
|
root.connect_response(
|
|
None,
|
|
clone!(
|
|
#[strong]
|
|
sender,
|
|
move |_, _| sender.input(DialogInput::Dismiss)
|
|
),
|
|
);
|
|
|
|
let widgets = DialogWidgets { dialog: root };
|
|
|
|
relm4::ComponentParts { model, widgets }
|
|
}
|
|
|
|
fn update(&mut self, message: Self::Input, _sender: relm4::ComponentSender<Self>) {
|
|
match message {
|
|
DialogInput::Show { heading, body } => {
|
|
self.heading = heading;
|
|
self.body = body;
|
|
self.visible = true;
|
|
}
|
|
DialogInput::Dismiss => self.visible = false,
|
|
}
|
|
}
|
|
|
|
fn update_view(&self, widgets: &mut Self::Widgets, _sender: relm4::ComponentSender<Self>) {
|
|
widgets.dialog.set_heading(Some(&self.heading));
|
|
widgets.dialog.set_body(&self.body);
|
|
|
|
if self.visible {
|
|
widgets.dialog.present(Some(&self.window));
|
|
}
|
|
}
|
|
}
|