save_file_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
---
save_file_dialog.rs (1350B)
---
1 use eframe::egui;
2 use egui_file::FileDialog;
3 use std::path::PathBuf;
4
5 use crate::{MainWindow, Message};
6
7 pub struct SaveFileDialog {
8 open_file: bool,
9 dialog: FileDialog,
10 opened_file: Option<PathBuf>,
11 }
12
13 impl SaveFileDialog {
14 pub fn new(initial_path: Option<PathBuf>) -> Self {
15 let mut dialog = FileDialog::save_file(initial_path);
16 dialog.open();
17
18 Self {
19 open_file: false,
20 dialog,
21 opened_file: None,
22 }
23 }
24 }
25
26 impl crate::ModalDialog for SaveFileDialog {
27 fn show(&mut self, ctx: &egui::Context) -> bool {
28 let mut result = false;
29
30 if self.dialog.show(ctx).selected() {
31 if let Some(file) = self.dialog.path() {
32 self.opened_file = Some(file.to_path_buf());
33 self.open_file = true;
34 }
35 result = true;
36 }
37
38 result
39 }
40
41 fn should_commit(&self) -> bool {
42 self.open_file
43 }
44
45 fn commit_self(&self, window: &mut MainWindow<'_>) -> crate::TerminalResult<Option<Message>> {
46 if let Some(file) = &self.opened_file.clone() {
47 if let Some(pane) = window.get_active_pane_mut() {
48 pane.set_path(file.clone());
49 pane.save();
50 window.current_id = None;
51 }
52 }
53 Ok(None)
54 }
55 }