diff options
author | Kesse Jones <kjonesfc@outlook.com> | 2020-11-01 12:57:55 -0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-11-01 18:47:43 +0100 |
commit | 8c4a2c34d307d38b1590634d0294f8f1b8d106b9 (patch) | |
tree | 8c7255da1d80b25c8d7a627529eb2af777ebaef7 | |
parent | 656ffe36f20d33286c9f640259be234a78667015 (diff) | |
download | serenity-8c4a2c34d307d38b1590634d0294f8f1b8d106b9.zip |
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.
-rw-r--r-- | DevTools/HackStudio/Project.cpp | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/DevTools/HackStudio/Project.cpp b/DevTools/HackStudio/Project.cpp index 8ff6a13a06..d994cc80ee 100644 --- a/DevTools/HackStudio/Project.cpp +++ b/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(); } |