Преглед на файлове

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

Marco Cutecchia преди 3 години
родител
ревизия
cb041d7496
променени са 1 файла, в които са добавени 20 реда и са изтрити 3 реда
  1. 20 3
      Userland/DevTools/HackStudio/main.cpp

+ 20 - 3
Userland/DevTools/HackStudio/main.cpp

@@ -32,6 +32,7 @@ static WeakPtr<HackStudioWidget> s_hack_studio_widget;
 static bool make_is_available();
 static bool make_is_available();
 static void notify_make_not_available();
 static void notify_make_not_available();
 static void update_path_environment_variable();
 static void update_path_environment_variable();
+static Optional<String> last_opened_project_path();
 
 
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 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 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));
     auto hack_studio_widget = TRY(window->try_set_main_widget<HackStudioWidget>(project_path));
     s_hack_studio_widget = hack_studio_widget;
     s_hack_studio_widget = hack_studio_widget;
@@ -123,6 +128,18 @@ static void update_path_environment_variable()
     setenv("PATH", path.to_string().characters(), true);
     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 {
 namespace HackStudio {
 
 
 GUI::TextEditor& current_editor()
 GUI::TextEditor& current_editor()