mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 08:56:40 +00:00
HackStudio: Replace custom recent-project management with the LibGUI one
The only downside is we are limited to 4 recent projects now. LibGUI currently relies on the number of recent files being constexpr, so that will take some more work to make it variable.
This commit is contained in:
parent
343de324db
commit
315c95a1ce
|
@ -3,6 +3,7 @@
|
|||
* Copyright (c) 2020-2022, Itamar S. <itamar8910@gmail.com>
|
||||
* Copyright (c) 2023-2024, Abhishek R. <raturiabhi1000@gmail.com>
|
||||
* Copyright (c) 2020-2022, the SerenityOS developers.
|
||||
* Copyright (c) 2024, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* 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<ByteString> 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<void> HackStudioWidget::create_file_menu(GUI::Window& window)
|
||||
{
|
||||
auto file_menu = window.add_menu("&File"_string);
|
||||
|
@ -1450,8 +1421,10 @@ ErrorOr<void> 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();
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2020-2022, Itamar S. <itamar8910@gmail.com>
|
||||
* Copyright (c) 2020-2021, the SerenityOS developers.
|
||||
* Copyright (c) 2024, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* 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<ByteString> selected_file_paths() const;
|
||||
|
@ -149,7 +148,6 @@ private:
|
|||
void create_toolbar(GUI::Widget& parent);
|
||||
ErrorOr<void> create_action_tab(GUI::Widget& parent);
|
||||
ErrorOr<void> create_file_menu(GUI::Window&);
|
||||
void update_recent_projects_submenu();
|
||||
ErrorOr<void> create_edit_menu(GUI::Window&);
|
||||
void create_build_menu(GUI::Window&);
|
||||
ErrorOr<void> create_view_menu(GUI::Window&);
|
||||
|
|
|
@ -42,6 +42,7 @@ ErrorOr<int> 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();
|
||||
|
|
Loading…
Reference in a new issue