From a7b7003376556d99db389dbd94bb1dea411b0354 Mon Sep 17 00:00:00 2001 From: Skye Sprung Date: Mon, 29 Aug 2022 18:25:35 +0200 Subject: [PATCH] HackStudio: Fix crash when opening or creating with open empty file This commit fixes a crash that would occur due to an unnamed file being automatically saved via EditorWrapper::save(). Now, we throw up a FilePicker::get_save_filepath. --- Userland/DevTools/HackStudio/EditorWrapper.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Userland/DevTools/HackStudio/EditorWrapper.cpp b/Userland/DevTools/HackStudio/EditorWrapper.cpp index 4a911add5e..d344788e64 100644 --- a/Userland/DevTools/HackStudio/EditorWrapper.cpp +++ b/Userland/DevTools/HackStudio/EditorWrapper.cpp @@ -10,6 +10,7 @@ #include "HackStudio.h" #include #include +#include #include #include #include @@ -72,6 +73,13 @@ void EditorWrapper::set_filename(String const& filename) void EditorWrapper::save() { + if (filename().is_empty()) { + auto file_picker_action = GUI::CommonActions::make_save_as_action([&](auto&) { + Optional save_path = GUI::FilePicker::get_save_filepath(window(), "file"sv, "txt"sv, project_root().value()); + set_filename(save_path.value()); + }); + file_picker_action->activate(); + } editor().write_to_file(filename()); update_diff(); editor().update();