diff options
| author | pml68 <contact@pml68.me> | 2024-11-04 20:31:09 +0100 |
|---|---|---|
| committer | pml68 <contact@pml68.me> | 2024-11-04 20:31:09 +0100 |
| commit | 6953207b30c7630d8ebb9508603ee1d92d6062a9 (patch) | |
| tree | 57952c0e1c862e530316db258c9f6ad3f7132698 /iced_builder/src/main.rs | |
| parent | feat(error): use `Arc` instead of .to_string for From impls (diff) | |
| download | iced-builder-6953207b30c7630d8ebb9508603ee1d92d6062a9.tar.gz | |
feat: add `unsaved_changes` dialog
Diffstat (limited to '')
| -rw-r--r-- | iced_builder/src/main.rs | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/iced_builder/src/main.rs b/iced_builder/src/main.rs index bbf01c5..0afcb90 100644 --- a/iced_builder/src/main.rs +++ b/iced_builder/src/main.rs @@ -11,10 +11,11 @@ use iced::{ Alignment, Element, Length, Settings, Task, Theme, }; use iced_builder::{ - error::error_dialog, + dialogs::{error_dialog, unsaved_changes_dialog}, types::{Action, DesignerPage, ElementName, Message, Project}, views::{code_view, designer_view, element_list}, }; +use rfd::MessageDialogResult; fn main() -> iced::Result { iced::application(App::title, App::update, App::view) @@ -179,16 +180,33 @@ impl App { Message::PaneDragged(_) => {} Message::NewFile => { if !self.is_loading { - self.project = Project::new(); - self.project_path = None; - self.editor_content = text_editor::Content::new(); + if !self.is_dirty { + self.project = Project::new(); + self.project_path = None; + self.editor_content = text_editor::Content::new(); + } else { + if let MessageDialogResult::Ok = unsaved_changes_dialog("You have unsaved changes. Do you wish to discard these and create a new project?") { + self.is_dirty = false; + self.project = Project::new(); + self.project_path = None; + self.editor_content = text_editor::Content::new(); + } + } } } Message::OpenFile => { - if !self.is_loading && !self.is_dirty { - self.is_loading = true; + if !self.is_loading { + if !self.is_dirty { + self.is_loading = true; - return Task::perform(Project::from_path(), Message::FileOpened); + return Task::perform(Project::from_path(), Message::FileOpened); + } else { + if let MessageDialogResult::Ok = unsaved_changes_dialog("You have unsaved changes. Do you wish to discard these and open another project?") { + self.is_dirty = false; + self.is_loading = true; + return Task::perform(Project::from_path(), Message::FileOpened); + } + } } } Message::FileOpened(result) => { |
