/
EClassTreeBuilder.cpp
75 lines (55 loc) · 1.87 KB
/
EClassTreeBuilder.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "EClassTreeBuilder.h"
#include "EClassTree.h"
#include "wxutil/dataview/VFSTreePopulator.h"
#include "wxutil/dataview/TreeModel.h"
namespace ui
{
namespace
{
constexpr const char* ENTITY_ICON = "cmenu_add_entity.png";
}
EClassTreeBuilder::EClassTreeBuilder(const wxutil::DeclarationTreeView::Columns& columns) :
ThreadedDeclarationTreePopulator(decl::Type::EntityDef, columns, ENTITY_ICON),
_columns(columns)
{}
EClassTreeBuilder::~EClassTreeBuilder()
{
EnsureStopped();
}
void EClassTreeBuilder::PopulateModel(const wxutil::TreeModel::Ptr& model)
{
_treePopulator = std::make_unique<wxutil::VFSTreePopulator>(model);
ThrowIfCancellationRequested();
GlobalEntityClassManager().forEachEntityClass([&](const IEntityClassPtr& eclass)
{
ThrowIfCancellationRequested();
// Prefix mod name
auto fullPath = eclass->getModName() + "/";
// Prefix inheritance path (recursively)
fullPath += GetInheritancePathRecursively(*eclass);
// The entityDef name itself
fullPath += eclass->getDeclName();
// Let the VFSTreePopulator sort this into the tree
_treePopulator->addPath(fullPath, [&](wxutil::TreeModel::Row& row,
const std::string& path, const std::string& leafName, bool isFolder)
{
AssignValuesToRow(row, path, leafName, leafName, false);
});
});
ThrowIfCancellationRequested();
}
void EClassTreeBuilder::SortModel(const wxutil::TreeModel::Ptr& model)
{
model->SortModelByColumn(_columns.leafName);
}
std::string EClassTreeBuilder::GetInheritancePathRecursively(IEntityClass& eclass)
{
std::string returnValue;
if (auto parent = eclass.getParent(); parent)
{
returnValue += GetInheritancePathRecursively(*parent);
returnValue += parent->getDeclName() + "/";
}
return returnValue;
}
} // namespace ui