From 4370e8f80af19c9b0db6fc37cad6d1cd272d7b50 Mon Sep 17 00:00:00 2001 From: Skye Sprung Date: Mon, 29 Aug 2022 19:03:42 +0200 Subject: [PATCH] HackStudio: Warn of unsaved changes before making a new project Before, the warning dialog would be opened after the NewProjectDialog, leading to focus-fighting by the two windows. This fixes that and makes the action more consistent with the standard serenity way of handling unsaved changes by asking before the NewProjectDialog is brought up. The way this is achieved avoids having to rewrite open_project as well. --- Userland/DevTools/HackStudio/HackStudioWidget.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp index cbac2156cc..f1c6e04533 100644 --- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp +++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp @@ -703,6 +703,12 @@ NonnullRefPtr HackStudioWidget::create_delete_action() NonnullRefPtr HackStudioWidget::create_new_project_action() { return GUI::Action::create("&Project...", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/hackstudio-project.png"sv).release_value_but_fixme_should_propagate_errors(), [this](const GUI::Action&) { + if (warn_unsaved_changes("There are unsaved changes. Would you like to save before creating a new project?") == ContinueDecision::No) + return; + // If the user wishes to save the changes, this occurs in warn_unsaved_changes. If they do not, + // we need to mark the documents as clean so open_project works properly without asking again. + for (auto& editor_wrapper : m_all_editor_wrappers) + editor_wrapper.editor().document().set_unmodified(); auto dialog = NewProjectDialog::construct(window()); dialog->set_icon(window()->icon()); auto result = dialog->exec();