auto_save_dialog.rs - icy_draw - icy_draw is the successor to mystic draw. fork / mirror
(HTM) git clone https://git.drkhsh.at/icy_draw.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
auto_save_dialog.rs (1888B)
---
1 use eframe::egui;
2 use egui_modal::Modal;
3 use i18n_embed_fl::fl;
4
5 use crate::{util::autosave::remove_autosave, MainWindow, Message, TerminalResult};
6
7 #[derive(Default)]
8 pub struct AutoSaveDialog {
9 finish: bool,
10 load_autosave: bool,
11 path: std::path::PathBuf,
12 }
13 impl AutoSaveDialog {
14 pub(crate) fn new(path: std::path::PathBuf) -> Self {
15 Self {
16 load_autosave: false,
17 finish: false,
18 path,
19 }
20 }
21 }
22
23 impl crate::ModalDialog for AutoSaveDialog {
24 fn show(&mut self, ctx: &egui::Context) -> bool {
25 let mut result = false;
26 let modal = Modal::new(ctx, "autosave_dialog");
27
28 modal.show(|ui| {
29 modal.title(ui, fl!(crate::LANGUAGE_LOADER, "autosave-dialog-title"));
30
31 modal.frame(ui, |ui| {
32 ui.strong(fl!(crate::LANGUAGE_LOADER, "autosave-dialog-description"));
33 ui.label(fl!(crate::LANGUAGE_LOADER, "autosave-dialog-question"));
34 });
35
36 modal.buttons(ui, |ui| {
37 if ui.button(fl!(crate::LANGUAGE_LOADER, "autosave-dialog-load_autosave_button")).clicked() {
38 self.load_autosave = true;
39 self.finish = true;
40 result = true;
41 }
42
43 if ui.button(fl!(crate::LANGUAGE_LOADER, "autosave-dialog-discard_autosave_button")).clicked() {
44 remove_autosave(&self.path);
45 self.load_autosave = false;
46 self.finish = true;
47 result = true;
48 }
49 });
50 });
51 modal.open();
52 result
53 }
54
55 fn should_commit(&self) -> bool {
56 self.finish
57 }
58
59 fn commit_self(&self, _window: &mut MainWindow<'_>) -> TerminalResult<Option<Message>> {
60 Ok(Some(Message::LoadFile(self.path.clone(), self.load_autosave)))
61 }
62 }