refactor(new_editor/app): reorganize host structure and add smoke test
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
#include "ProjectBrowserModelSupport.h"
|
||||
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
|
||||
using namespace ProjectBrowserModelSupport;
|
||||
|
||||
void ProjectBrowserModel::RefreshAssetList() {
|
||||
EnsureValidCurrentFolder();
|
||||
|
||||
m_assetEntries.clear();
|
||||
const FolderEntry* currentFolder = FindFolderEntry(m_currentFolderId);
|
||||
if (currentFolder == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::filesystem::directory_entry> entries = {};
|
||||
std::error_code errorCode = {};
|
||||
const std::filesystem::directory_iterator end = {};
|
||||
for (std::filesystem::directory_iterator iterator(currentFolder->absolutePath, errorCode);
|
||||
!errorCode && iterator != end;
|
||||
iterator.increment(errorCode)) {
|
||||
if (!iterator->exists(errorCode) || IsMetaFile(iterator->path())) {
|
||||
continue;
|
||||
}
|
||||
if (!iterator->is_directory(errorCode) && !iterator->is_regular_file(errorCode)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
entries.push_back(*iterator);
|
||||
}
|
||||
|
||||
std::sort(
|
||||
entries.begin(),
|
||||
entries.end(),
|
||||
[](const std::filesystem::directory_entry& lhs, const std::filesystem::directory_entry& rhs) {
|
||||
const bool lhsDirectory = lhs.is_directory();
|
||||
const bool rhsDirectory = rhs.is_directory();
|
||||
if (lhsDirectory != rhsDirectory) {
|
||||
return lhsDirectory && !rhsDirectory;
|
||||
}
|
||||
|
||||
return ToLowerCopy(PathToUtf8String(lhs.path().filename())) <
|
||||
ToLowerCopy(PathToUtf8String(rhs.path().filename()));
|
||||
});
|
||||
|
||||
for (const std::filesystem::directory_entry& entry : entries) {
|
||||
AssetEntry assetEntry = {};
|
||||
assetEntry.itemId = BuildRelativeItemId(entry.path(), m_assetsRootPath);
|
||||
assetEntry.absolutePath = entry.path();
|
||||
assetEntry.displayName = BuildAssetDisplayName(entry.path(), entry.is_directory());
|
||||
assetEntry.directory = entry.is_directory();
|
||||
m_assetEntries.push_back(std::move(assetEntry));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor::App
|
||||
Reference in New Issue
Block a user