Skip to content

Commit

Permalink
Add convenience method to TreeView class
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Dec 25, 2016
1 parent 6732b8b commit 4056bac
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
16 changes: 16 additions & 0 deletions libs/wxutil/TreeView.cpp
Expand Up @@ -76,6 +76,22 @@ void TreeView::TriggerColumnSizeEvent(const wxDataViewItem& item)
});
}

void TreeView::ExpandTopLevelItems()
{
TreeModel* model = dynamic_cast<TreeModel*>(GetModel());

if (model == nullptr) return;

// Expand the first layer
wxDataViewItemArray children;
model->GetChildren(model->GetRoot(), children);

std::for_each(children.begin(), children.end(), [&](const wxDataViewItem& item)
{
Expand(item);
});
}

void TreeView::AddSearchColumn(const TreeModel::Column& column)
{
// Only text columns are supported right now
Expand Down
3 changes: 3 additions & 0 deletions libs/wxutil/TreeView.h
Expand Up @@ -50,6 +50,9 @@ class TreeView :
// Call this if your text columns get squashed and are not sized correctly
void TriggerColumnSizeEvent(const wxDataViewItem& item = wxDataViewItem());

// Expands the first level of all the top-level items
void ExpandTopLevelItems();

// Adds a column to search when the user starts typing
void AddSearchColumn(const TreeModel::Column& column);

Expand Down
8 changes: 1 addition & 7 deletions radiant/ui/entitychooser/EntityClassChooser.cpp
Expand Up @@ -265,13 +265,7 @@ void EntityClassChooser::setTreeViewModel()
_treeView->AssociateModel(_treeStore.get());

// Expand the first layer
wxDataViewItemArray children;
_treeStore->GetChildren(_treeStore->GetRoot(), children);

std::for_each(children.begin(), children.end(), [&] (const wxDataViewItem& item)
{
_treeView->Expand(item);
});
_treeView->ExpandTopLevelItems();

// Pre-select the given class if requested by setSelectedEntityClass()
if (!_classToHighlight.empty())
Expand Down

0 comments on commit 4056bac

Please sign in to comment.