diff options
author | Skye Sprung <skye.sprung@gmail.com> | 2022-08-29 18:25:35 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-08-31 15:21:03 +0100 |
commit | a7b7003376556d99db389dbd94bb1dea411b0354 (patch) | |
tree | 4ad169d5a8af1864d5e3c598e10ef4c26ac5716f /Userland | |
parent | fa2ece11834177102647b9b46e30bc623871616d (diff) | |
download | serenity-a7b7003376556d99db389dbd94bb1dea411b0354.zip |
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.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/DevTools/HackStudio/EditorWrapper.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
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 <LibGUI/Application.h> #include <LibGUI/BoxLayout.h> +#include <LibGUI/FilePicker.h> #include <LibGUI/Label.h> #include <LibGfx/Font/Font.h> #include <LibGfx/Font/FontDatabase.h> @@ -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<String> 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(); |