diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2023-03-16 20:46:17 +0000 |
---|---|---|
committer | Sam Atkins <atkinssj@gmail.com> | 2023-03-20 09:06:12 +0000 |
commit | 1fba3640cbc855ac73ccdcb9938d32eebab9eb12 (patch) | |
tree | 0fed2cddc8d74507b0a71ddfb23f4b3b1936d3ab /Userland/DevTools | |
parent | d0730c1c750b51fcfa40415f8d81078d10f84027 (diff) | |
download | serenity-1fba3640cbc855ac73ccdcb9938d32eebab9eb12.zip |
GMLPlayground: Add list of recent files to the File menu
Diffstat (limited to 'Userland/DevTools')
-rw-r--r-- | Userland/DevTools/GMLPlayground/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Userland/DevTools/GMLPlayground/main.cpp | 44 |
2 files changed, 36 insertions, 10 deletions
diff --git a/Userland/DevTools/GMLPlayground/CMakeLists.txt b/Userland/DevTools/GMLPlayground/CMakeLists.txt index 8b91442fc7..05b55f8dc8 100644 --- a/Userland/DevTools/GMLPlayground/CMakeLists.txt +++ b/Userland/DevTools/GMLPlayground/CMakeLists.txt @@ -15,4 +15,4 @@ set(GENERATED_SOURCES ) serenity_app(GMLPlayground ICON app-gml-playground) -target_link_libraries(GMLPlayground PRIVATE LibCore LibDesktop LibFileSystemAccessClient LibGfx LibGUI LibMain LibSyntax) +target_link_libraries(GMLPlayground PRIVATE LibConfig LibCore LibDesktop LibFileSystemAccessClient LibGfx LibGUI LibMain LibSyntax) diff --git a/Userland/DevTools/GMLPlayground/main.cpp b/Userland/DevTools/GMLPlayground/main.cpp index 21e3168bdf..a6fcdb754c 100644 --- a/Userland/DevTools/GMLPlayground/main.cpp +++ b/Userland/DevTools/GMLPlayground/main.cpp @@ -8,6 +8,7 @@ */ #include <AK/URL.h> +#include <LibConfig/Client.h> #include <LibCore/ArgsParser.h> #include <LibCore/System.h> #include <LibDesktop/Launcher.h> @@ -67,6 +68,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) TRY(Core::System::pledge("stdio thread recvfd sendfd cpath rpath wpath unix")); auto app = TRY(GUI::Application::try_create(arguments)); + Config::pledge_domain("GMLPlayground"); + app->set_config_domain(TRY("GMLPlayground"_string)); + TRY(Core::System::unveil("/res", "r")); TRY(Core::System::unveil("/tmp/session/%sid/portal/launch", "rw")); TRY(Core::System::unveil("/tmp/session/%sid/portal/filesystemaccess", "rw")); @@ -136,6 +140,18 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) update_title(); }; + auto load_file = [&](auto file) { + auto buffer_or_error = file.stream().read_until_eof(); + if (buffer_or_error.is_error()) + return; + + editor->set_text(buffer_or_error.release_value()); + editor->set_focus(true); + update_title(); + + GUI::Application::the()->set_most_recently_open_file(file.filename()); + }; + auto file_menu = TRY(window->try_add_menu("&File")); auto save_as_action = GUI::CommonActions::make_save_as_action([&](auto&) { @@ -150,6 +166,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) } file_path = response.value().filename().to_deprecated_string(); update_title(); + + GUI::Application::the()->set_most_recently_open_file(response.value().filename()); }); auto save_action = GUI::CommonActions::make_save_action([&](auto&) { @@ -182,15 +200,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) if (response.is_error()) return; - auto file = response.release_value(); - file_path = file.filename().to_deprecated_string(); - auto buffer_or_error = file.stream().read_until_eof(); - if (buffer_or_error.is_error()) - return; - - editor->set_text(buffer_or_error.release_value()); - editor->set_focus(true); - update_title(); + load_file(response.release_value()); }); TRY(file_menu->try_add_action(open_action)); @@ -198,6 +208,22 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) TRY(file_menu->try_add_action(save_as_action)); TRY(file_menu->try_add_separator()); + TRY(file_menu->add_recent_files_list([&](auto& action) { + if (window->is_modified()) { + auto result = GUI::MessageBox::ask_about_unsaved_changes(window, file_path, editor->document().undo_stack().last_unmodified_timestamp()); + if (result == GUI::MessageBox::ExecResult::Yes) + save_action->activate(); + if (result != GUI::MessageBox::ExecResult::No && window->is_modified()) + return; + } + + auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, action.text()); + if (response.is_error()) + return; + file_path = response.value().filename().to_deprecated_string(); + load_file(response.release_value()); + })); + TRY(file_menu->try_add_action(GUI::CommonActions::make_quit_action([&](auto&) { if (window->on_close_request() == GUI::Window::CloseRequestDecision::Close) app->quit(); |