summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--iced_builder/src/dialogs.rs19
-rw-r--r--iced_builder/src/error.rs19
-rw-r--r--iced_builder/src/lib.rs1
-rw-r--r--iced_builder/src/main.rs32
4 files changed, 45 insertions, 26 deletions
diff --git a/iced_builder/src/dialogs.rs b/iced_builder/src/dialogs.rs
new file mode 100644
index 0000000..18e3c0d
--- /dev/null
+++ b/iced_builder/src/dialogs.rs
@@ -0,0 +1,19 @@
+use rfd::{MessageButtons, MessageDialog, MessageDialogResult, MessageLevel};
+
+pub fn error_dialog(description: impl Into<String>) {
+ MessageDialog::new()
+ .set_level(MessageLevel::Error)
+ .set_buttons(MessageButtons::Ok)
+ .set_title("Oops! Something went wrong.")
+ .set_description(description)
+ .show();
+}
+
+pub fn unsaved_changes_dialog(description: impl Into<String>) -> MessageDialogResult {
+ MessageDialog::new()
+ .set_level(MessageLevel::Warning)
+ .set_buttons(MessageButtons::OkCancel)
+ .set_title("Unsaved changes")
+ .set_description(description)
+ .show()
+}
diff --git a/iced_builder/src/error.rs b/iced_builder/src/error.rs
index 8987851..edb57b9 100644
--- a/iced_builder/src/error.rs
+++ b/iced_builder/src/error.rs
@@ -1,4 +1,3 @@
-use rfd::{MessageButtons, MessageDialog, MessageLevel};
use std::io;
use std::sync::Arc;
use thiserror::Error;
@@ -42,21 +41,3 @@ impl From<&'static str> for Error {
Self::Other(value.to_owned())
}
}
-
-pub fn error_dialog(description: impl Into<String>) {
- MessageDialog::new()
- .set_level(MessageLevel::Error)
- .set_buttons(MessageButtons::Ok)
- .set_title("Oops! Something went wrong.")
- .set_description(description)
- .show();
-}
-
-pub fn warning_dialog(title: impl Into<String>, description: impl Into<String>) {
- MessageDialog::new()
- .set_level(MessageLevel::Warning)
- .set_buttons(MessageButtons::Ok)
- .set_title(title)
- .set_description(description)
- .show();
-}
diff --git a/iced_builder/src/lib.rs b/iced_builder/src/lib.rs
index ddb080c..6af030f 100644
--- a/iced_builder/src/lib.rs
+++ b/iced_builder/src/lib.rs
@@ -1,3 +1,4 @@
+pub mod dialogs;
pub mod error;
pub mod types;
pub mod views;
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) => {