From 92fdc5bd69afc346ef181104617ddc29974c6576 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 22 Jun 2021 19:24:49 +0200 Subject: [PATCH] Playground: Prompt to save changes after the user picked a file to open There's no point in saving the file - and potentially having to ask the user for a file name - if the user abandons the 'Open' action by clicking 'Cancel' in the file picker. This now also matches TextEditor's behavior. --- Userland/DevTools/Playground/main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Userland/DevTools/Playground/main.cpp b/Userland/DevTools/Playground/main.cpp index a24c6b42261..a84ab531350 100644 --- a/Userland/DevTools/Playground/main.cpp +++ b/Userland/DevTools/Playground/main.cpp @@ -186,6 +186,11 @@ int main(int argc, char** argv) }); file_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) { + Optional open_path = GUI::FilePicker::get_open_filepath(window); + + if (!open_path.has_value()) + return; + if (window->is_modified()) { auto save_document_first_result = GUI::MessageBox::show(window, "Save changes to current document first?", "Warning", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNoCancel); if (save_document_first_result == GUI::Dialog::ExecResult::ExecYes) @@ -194,11 +199,6 @@ int main(int argc, char** argv) return; } - Optional open_path = GUI::FilePicker::get_open_filepath(window); - - if (!open_path.has_value()) - return; - auto file = Core::File::construct(open_path.value()); if (!file->open(Core::OpenMode::ReadOnly) && file->error() != ENOENT) { GUI::MessageBox::show(window, String::formatted("Opening \"{}\" failed: {}", open_path.value(), strerror(errno)), "Error", GUI::MessageBox::Type::Error);