69 lines
2.2 KiB
C++
69 lines
2.2 KiB
C++
|
|
#include "ProjectBrowserModelSupport.h"
|
||
|
|
|
||
|
|
namespace XCEngine::UI::Editor::App {
|
||
|
|
|
||
|
|
using namespace ProjectBrowserModelSupport;
|
||
|
|
|
||
|
|
void ProjectBrowserModel::RefreshFolderTree() {
|
||
|
|
m_folderEntries.clear();
|
||
|
|
m_treeItems.clear();
|
||
|
|
|
||
|
|
if (m_assetsRootPath.empty() || !std::filesystem::exists(m_assetsRootPath)) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
const auto appendFolderRecursive =
|
||
|
|
[&](auto&& self, const std::filesystem::path& folderPath, std::uint32_t depth) -> void {
|
||
|
|
const std::string itemId = BuildRelativeItemId(folderPath, m_assetsRootPath);
|
||
|
|
|
||
|
|
FolderEntry folderEntry = {};
|
||
|
|
folderEntry.itemId = itemId;
|
||
|
|
folderEntry.absolutePath = folderPath;
|
||
|
|
folderEntry.label = PathToUtf8String(folderPath.filename());
|
||
|
|
m_folderEntries.push_back(folderEntry);
|
||
|
|
|
||
|
|
Widgets::UIEditorTreeViewItem item = {};
|
||
|
|
item.itemId = itemId;
|
||
|
|
item.label = folderEntry.label;
|
||
|
|
item.depth = depth;
|
||
|
|
item.forceLeaf = !HasChildDirectories(folderPath);
|
||
|
|
item.leadingIcon = m_folderIcon;
|
||
|
|
m_treeItems.push_back(std::move(item));
|
||
|
|
|
||
|
|
const std::vector<std::filesystem::path> childFolders =
|
||
|
|
CollectSortedChildDirectories(folderPath);
|
||
|
|
for (const std::filesystem::path& childPath : childFolders) {
|
||
|
|
self(self, childPath, depth + 1u);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
appendFolderRecursive(appendFolderRecursive, m_assetsRootPath, 0u);
|
||
|
|
}
|
||
|
|
|
||
|
|
std::vector<std::string> ProjectBrowserModel::CollectCurrentFolderAncestorIds() const {
|
||
|
|
return BuildAncestorFolderIds(m_currentFolderId);
|
||
|
|
}
|
||
|
|
|
||
|
|
std::vector<std::string> ProjectBrowserModel::BuildAncestorFolderIds(
|
||
|
|
std::string_view itemId) const {
|
||
|
|
std::vector<std::string> ancestors = {};
|
||
|
|
const FolderEntry* folderEntry = FindFolderEntry(itemId);
|
||
|
|
if (folderEntry == nullptr) {
|
||
|
|
return ancestors;
|
||
|
|
}
|
||
|
|
|
||
|
|
std::filesystem::path path = folderEntry->absolutePath;
|
||
|
|
while (true) {
|
||
|
|
ancestors.push_back(BuildRelativeItemId(path, m_assetsRootPath));
|
||
|
|
if (path == m_assetsRootPath) {
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
path = path.parent_path();
|
||
|
|
}
|
||
|
|
|
||
|
|
std::reverse(ancestors.begin(), ancestors.end());
|
||
|
|
return ancestors;
|
||
|
|
}
|
||
|
|
|
||
|
|
} // namespace XCEngine::UI::Editor::App
|