diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp index afe60febdc..4b49b973ab 100644 --- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp +++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp @@ -3,6 +3,7 @@ * Copyright (c) 2020-2022, Itamar S. * Copyright (c) 2023-2024, Abhishek R. * Copyright (c) 2020-2022, the SerenityOS developers. + * Copyright (c) 2024, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -274,14 +275,7 @@ void HackStudioWidget::open_project(ByteString const& root_path) LexicalPath::relative_path(absolute_new_path, m_project->root_path())); }; - auto recent_projects = read_recent_projects(); - recent_projects.remove_all_matching([&](auto& p) { return p == absolute_root_path; }); - recent_projects.insert(0, absolute_root_path); - if (recent_projects.size() > recent_projects_history_size) - recent_projects.shrink(recent_projects_history_size); - - Config::write_string("HackStudio"sv, "Global"sv, "RecentProjects"sv, JsonArray(recent_projects).to_byte_string()); - update_recent_projects_submenu(); + GUI::Application::the()->set_most_recently_open_file(absolute_root_path); } Vector HackStudioWidget::selected_file_paths() const @@ -1403,29 +1397,6 @@ void HackStudioWidget::create_project_tab(GUI::Widget& parent) }; } -void HackStudioWidget::update_recent_projects_submenu() -{ - if (!m_recent_projects_submenu) - return; - - m_recent_projects_submenu->remove_all_actions(); - auto recent_projects = read_recent_projects(); - - if (recent_projects.size() <= 1) { - auto empty_action = GUI::Action::create("(No recently open files)", [](auto&) {}); - empty_action->set_enabled(false); - m_recent_projects_submenu->add_action(empty_action); - return; - } - - for (size_t i = 1; i < recent_projects.size(); i++) { - auto project_path = recent_projects[i]; - m_recent_projects_submenu->add_action(GUI::Action::create(recent_projects[i], [this, project_path](auto&) { - open_project(project_path); - })); - } -} - ErrorOr HackStudioWidget::create_file_menu(GUI::Window& window) { auto file_menu = window.add_menu("&File"_string); @@ -1450,8 +1421,10 @@ ErrorOr HackStudioWidget::create_file_menu(GUI::Window& window) { auto icon = TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/open-recent.png"sv)); m_recent_projects_submenu->set_icon(icon); + m_recent_projects_submenu->add_recent_files_list( + [this](GUI::Action& action) { open_project(action.text()); }, + GUI::Menu::AddTrailingSeparator::No); } - update_recent_projects_submenu(); file_menu->add_action(*m_save_action); file_menu->add_action(*m_save_as_action); file_menu->add_separator(); diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.h b/Userland/DevTools/HackStudio/HackStudioWidget.h index 0a92dbb6fe..17583616bc 100644 --- a/Userland/DevTools/HackStudio/HackStudioWidget.h +++ b/Userland/DevTools/HackStudio/HackStudioWidget.h @@ -2,6 +2,7 @@ * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2020-2022, Itamar S. * Copyright (c) 2020-2021, the SerenityOS developers. + * Copyright (c) 2024, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -86,8 +87,6 @@ public: void update_window_title(); private: - static constexpr size_t recent_projects_history_size = 15; - static ByteString get_full_path_of_serenity_source(ByteString const& file); ByteString get_absolute_path(ByteString const&) const; Vector selected_file_paths() const; @@ -149,7 +148,6 @@ private: void create_toolbar(GUI::Widget& parent); ErrorOr create_action_tab(GUI::Widget& parent); ErrorOr create_file_menu(GUI::Window&); - void update_recent_projects_submenu(); ErrorOr create_edit_menu(GUI::Window&); void create_build_menu(GUI::Window&); ErrorOr create_view_menu(GUI::Window&); diff --git a/Userland/DevTools/HackStudio/main.cpp b/Userland/DevTools/HackStudio/main.cpp index d9de69efbb..953d0b4944 100644 --- a/Userland/DevTools/HackStudio/main.cpp +++ b/Userland/DevTools/HackStudio/main.cpp @@ -42,6 +42,7 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::pledge("stdio recvfd sendfd tty rpath cpath wpath proc exec unix fattr thread ptrace")); auto app = TRY(GUI::Application::create(arguments)); + app->set_config_domain("HackStudio"_string); Config::pledge_domains({ "HackStudio", "Terminal", "FileManager" }); auto window = GUI::Window::construct();