Przeglądaj źródła

HackStudio: Fixed opening the project by always opening the main.cpp file

Now when opening the project a search will be made for
a file with the extension cpp or js and opening it.
If not found, the first file will be opened.
Kesse Jones 4 lat temu
rodzic
commit
8c4a2c34d3
1 zmienionych plików z 24 dodań i 3 usunięć
  1. 24 3
      DevTools/HackStudio/Project.cpp

+ 24 - 3
DevTools/HackStudio/Project.cpp

@@ -302,11 +302,32 @@ RefPtr<ProjectFile> Project::get_file(const String& filename)
 
 String Project::default_file() const
 {
-    if (m_type == ProjectType::Cpp)
-        return "main.cpp";
+    if (m_files.size() > 0) {
+        if (m_type != ProjectType::Unknown) {
+            StringView extension;
+            switch (m_type) {
+            case ProjectType::Cpp:
+                extension = ".cpp";
+                break;
+            case ProjectType::JavaScript:
+                extension = ".js";
+                break;
+            default:
+                ASSERT_NOT_REACHED();
+            }
+
+            auto project_file = m_files.find([&](auto project_file) {
+                return project_file->name().ends_with(extension);
+            });
+
+            if (!project_file.is_end()) {
+                auto& file = *project_file;
+                return file->name();
+            }
+        }
 
-    if (m_files.size() > 0)
         return m_files.first().name();
+    }
 
     ASSERT_NOT_REACHED();
 }