HackStudio: Open by default the last opened project if not specified

This commit is contained in:
Marco Cutecchia 2022-02-13 22:34:28 +01:00 committed by Andreas Kling
parent 7e7bfdac50
commit cb041d7496

View file

@ -32,6 +32,7 @@ static WeakPtr<HackStudioWidget> s_hack_studio_widget;
static bool make_is_available();
static void notify_make_not_available();
static void update_path_environment_variable();
static Optional<String> last_opened_project_path();
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
@ -59,9 +60,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto argument_absolute_path = Core::File::real_path_for(path_argument);
auto project_path = argument_absolute_path;
if (argument_absolute_path.is_null() || mode_coredump)
project_path = Core::File::real_path_for(".");
auto project_path = Core::File::real_path_for(".");
if (!mode_coredump) {
if (!argument_absolute_path.is_null())
project_path = argument_absolute_path;
else if (auto path = last_opened_project_path(); path.has_value())
project_path = path.release_value();
}
auto hack_studio_widget = TRY(window->try_set_main_widget<HackStudioWidget>(project_path));
s_hack_studio_widget = hack_studio_widget;
@ -123,6 +128,18 @@ static void update_path_environment_variable()
setenv("PATH", path.to_string().characters(), true);
}
static Optional<String> last_opened_project_path()
{
auto projects = HackStudioWidget::read_recent_projects();
if (projects.size() == 0)
return {};
if (!Core::File::exists(projects[0]))
return {};
return { projects[0] };
}
namespace HackStudio {
GUI::TextEditor& current_editor()