Skip to content

Commit

Permalink
#6021: Migrate EClassTreeBuilder population code to use the base meth…
Browse files Browse the repository at this point in the history
…ods in ThreadedDeclarationTreePopulator
  • Loading branch information
codereader committed Jul 29, 2022
1 parent c0e8c69 commit 2d344cd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 45 deletions.
2 changes: 1 addition & 1 deletion radiant/ui/eclasstree/EClassTree.cpp
Expand Up @@ -52,7 +52,7 @@ void EClassTree::onTreeViewPopulationFinished(wxutil::ResourceTreeView::Populati

if (!className.empty())
{
_eclassView->SetSelectedFullname(className);
_eclassView->SetSelectedDeclName(className);
}
else
{
Expand Down
62 changes: 22 additions & 40 deletions radiant/ui/eclasstree/EClassTreeBuilder.cpp
@@ -1,13 +1,9 @@
#include "EClassTreeBuilder.h"

#include "EClassTree.h"
#include "ifavourites.h"

#include "wxutil/Bitmap.h"

#include "wxutil/dataview/VFSTreePopulator.h"
#include "wxutil/dataview/TreeModel.h"
#include "wxutil/dataview/TreeViewItemStyle.h"

namespace ui
{
Expand All @@ -18,11 +14,9 @@ namespace
}

EClassTreeBuilder::EClassTreeBuilder(const wxutil::DeclarationTreeView::Columns& columns) :
ThreadedDeclarationTreePopulator(decl::Type::EntityDef, columns),
ThreadedDeclarationTreePopulator(decl::Type::EntityDef, columns, ENTITY_ICON),
_columns(columns)
{
_entityIcon.CopyFromBitmap(wxutil::GetLocalBitmap(ENTITY_ICON));
}
{}

EClassTreeBuilder::~EClassTreeBuilder()
{
Expand All @@ -35,45 +29,33 @@ void EClassTreeBuilder::PopulateModel(const wxutil::TreeModel::Ptr& model)

ThrowIfCancellationRequested();

GlobalEntityClassManager().forEachEntityClass(*this);

ThrowIfCancellationRequested();
}

void EClassTreeBuilder::SortModel(const wxutil::TreeModel::Ptr& model)
{
model->SortModelByColumn(_columns.leafName);
}

void EClassTreeBuilder::visit(const IEntityClassPtr& eclass)
{
ThrowIfCancellationRequested();
GlobalEntityClassManager().forEachEntityClass([&](const IEntityClassPtr& eclass)
{
ThrowIfCancellationRequested();

// Prefix mod name
std::string fullPath = eclass->getModName() + "/";
// Prefix mod name
auto fullPath = eclass->getModName() + "/";

// Prefix inheritance path (recursively)
fullPath += GetInheritancePathRecursively(*eclass);
// Prefix inheritance path (recursively)
fullPath += GetInheritancePathRecursively(*eclass);

// The entityDef name itself
fullPath += eclass->getDeclName();
// 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)
// 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)
{
bool isFavourite = IsFavourite(leafName);
AssignValuesToRow(row, path, leafName, leafName, false);
});
});

row[_columns.iconAndName] = wxVariant(wxDataViewIconText(leafName, _entityIcon));
row[_columns.iconAndName] = wxutil::TreeViewItemStyle::Declaration(isFavourite);
row[_columns.fullName] = leafName;
row[_columns.leafName] = leafName;
row[_columns.declName] = leafName;
row[_columns.isFolder] = false;
row[_columns.isFavourite] = isFavourite;
ThrowIfCancellationRequested();
}

row.SendItemAdded();
});
void EClassTreeBuilder::SortModel(const wxutil::TreeModel::Ptr& model)
{
model->SortModelByColumn(_columns.leafName);
}

std::string EClassTreeBuilder::GetInheritancePathRecursively(IEntityClass& eclass)
Expand Down
5 changes: 1 addition & 4 deletions radiant/ui/eclasstree/EClassTreeBuilder.h
Expand Up @@ -16,8 +16,7 @@ namespace ui
* Visitor class to retrieve entityDef names and sort them into the hierarchy tree.
*/
class EClassTreeBuilder final :
public wxutil::ThreadedDeclarationTreePopulator,
public EntityClassVisitor
public wxutil::ThreadedDeclarationTreePopulator
{
private:
const wxutil::DeclarationTreeView::Columns& _columns;
Expand All @@ -31,8 +30,6 @@ class EClassTreeBuilder final :

~EClassTreeBuilder();

void visit(const IEntityClassPtr& eclass) override;

protected:
void PopulateModel(const wxutil::TreeModel::Ptr& model) override;
void SortModel(const wxutil::TreeModel::Ptr& model) override;
Expand Down

0 comments on commit 2d344cd

Please sign in to comment.