1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 14:25:06 +00:00

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.
This commit is contained in:
Kesse Jones 2020-11-01 12:57:55 -03:00 committed by Andreas Kling
parent 656ffe36f2
commit 8c4a2c34d3

View file

@ -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();
}