Skip to content

Commit

Permalink
#6034: Resort the subtree when inserting a single texture element int…
Browse files Browse the repository at this point in the history
…o the material tree view.

Send ItemDeleted/ItemAdded events for all children to force the client data views to rebuild their nodes.
  • Loading branch information
codereader committed Aug 5, 2022
1 parent f971cf8 commit 5d1ae53
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
12 changes: 12 additions & 0 deletions libs/wxutil/dataview/TreeModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1020,4 +1020,16 @@ void TreeModel::SetEnabled(const wxDataViewItem& item, unsigned int col, bool en
owningNode->enabledFlags[col] = enabled;
}

void TreeModel::SendSubtreeRefreshEvents(wxDataViewItem& parentItem)
{
wxDataViewItemArray children;
GetChildren(parentItem, children);

for (auto child : children)
{
ItemDeleted(parentItem, child);
ItemAdded(parentItem, child);
}
}

} // namespace
4 changes: 4 additions & 0 deletions libs/wxutil/dataview/TreeModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,10 @@ class TreeModel :
virtual int Compare(const wxDataViewItem& item1, const wxDataViewItem& item2,
unsigned int column, bool ascending) const override;

// Forces client data views to refresh this subtree by sending add/remove events
// for each of the children of the given item
virtual void SendSubtreeRefreshEvents(wxDataViewItem& parentItem);

protected:
// Returns a reference to the actual rootnode, only allowed for use in subclasses
virtual const NodePtr& getRootNode() const;
Expand Down
13 changes: 12 additions & 1 deletion radiant/ui/materials/MaterialPopulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ void MaterialPopulator::AddSingleMaterial(const wxutil::TreeModel::Ptr& model, c
if (!existingItem.IsOk())
{
InsertTexture(model, itemPath, materialName, parts.back(), parentItem);

// Sort the subtree starting from this parent item
SortModel(model, parentItem);

// Force a reload of this subtree by sending events for each child
model->SendSubtreeRefreshEvents(parentItem);
}
}

Expand Down Expand Up @@ -173,7 +179,12 @@ void MaterialPopulator::InsertTexture(const wxutil::TreeModel::Ptr& model,
void MaterialPopulator::SortModel(const wxutil::TreeModel::Ptr& model)
{
// Sort the model while we're still in the worker thread
model->SortModelFoldersFirst(_columns.iconAndName, _columns.isFolder,
SortModel(model, wxDataViewItem());
}

void MaterialPopulator::SortModel(const wxutil::TreeModel::Ptr& model, const wxDataViewItem& startItem)
{
model->SortModelFoldersFirst(startItem, _columns.iconAndName, _columns.isFolder,
[&](const wxDataViewItem& a, const wxDataViewItem& b)
{
// Special folder comparison function
Expand Down
2 changes: 2 additions & 0 deletions radiant/ui/materials/MaterialPopulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class MaterialPopulator :
const std::string& leafName, const wxDataViewItem& parentItem, bool isOtherMaterial);
void InsertTexture(const wxutil::TreeModel::Ptr& model, const std::string& path,
const std::string& declName, const std::string& leafName, const wxDataViewItem& parentItem);

void SortModel(const wxutil::TreeModel::Ptr& model, const wxDataViewItem& startItem);
};

}

0 comments on commit 5d1ae53

Please sign in to comment.