From e39c7d037d3fa4b57a2ca80c3fc26ff900309e91 Mon Sep 17 00:00:00 2001 From: pml68 Date: Tue, 31 Dec 2024 00:00:09 +0100 Subject: refactor: unsaved_changes_dialog emits bool instead of MessageDialogResult --- iced_builder/src/dialogs.rs | 14 +++++++++----- iced_builder/src/main.rs | 5 ++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/iced_builder/src/dialogs.rs b/iced_builder/src/dialogs.rs index c9a5ba2..56d22b2 100644 --- a/iced_builder/src/dialogs.rs +++ b/iced_builder/src/dialogs.rs @@ -18,13 +18,17 @@ pub fn warning_dialog(description: impl Into) { .show(); } -pub fn unsaved_changes_dialog( - description: impl Into, -) -> MessageDialogResult { - MessageDialog::new() +pub fn unsaved_changes_dialog(description: impl Into) -> bool { + let result = MessageDialog::new() .set_level(MessageLevel::Warning) .set_buttons(MessageButtons::OkCancel) .set_title("Unsaved changes") .set_description(description) - .show() + .show(); + + if let MessageDialogResult::Ok = result { + true + } else { + false + } } diff --git a/iced_builder/src/main.rs b/iced_builder/src/main.rs index 02e1ae0..86e478d 100644 --- a/iced_builder/src/main.rs +++ b/iced_builder/src/main.rs @@ -14,7 +14,6 @@ use iced_builder::types::{ Action, DesignerPage, ElementName, Message, Project, }; use iced_builder::{icon, Error}; -use rfd::MessageDialogResult; use tokio::runtime; fn main() -> Result<(), Box> { @@ -235,7 +234,7 @@ impl App { 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?") { + if 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; @@ -254,7 +253,7 @@ impl App { Message::FileOpened, ); } else { - if let MessageDialogResult::Ok = unsaved_changes_dialog("You have unsaved changes. Do you wish to discard these and open another project?") { + if 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_file(), Message::FileOpened); -- cgit v1.2.3