Skip to content

Commit

Permalink
#6051: Pre-select the global settings entry in the stage list when a …
Browse files Browse the repository at this point in the history
…new material is selected
  • Loading branch information
codereader committed Aug 6, 2022
1 parent 0e4fc6d commit e285ae3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
16 changes: 16 additions & 0 deletions libs/wxutil/dataview/TreeModel.cpp
Expand Up @@ -492,6 +492,22 @@ wxDataViewItem TreeModel::FindInteger(long needle, const Column& column, const w
});
}

wxDataViewItem TreeModel::FindItem(const std::function<bool(const TreeModel::Row&)>& predicate)
{
return FindItem(predicate, wxDataViewItem());
}

wxDataViewItem TreeModel::FindItem(const std::function<bool(const TreeModel::Row&)>& predicate, const wxDataViewItem& startItem)
{
auto* startNode = !startItem.IsOk() ? _rootNode.get() : static_cast<Node*>(startItem.GetID());

return FindRecursive(*startNode, [&](const Node& node)->bool
{
Row row(node.item, *this);
return predicate(row);
});
}

wxDataViewItem TreeModel::FindRecursive(const TreeModel::Node& node, const std::function<bool (const TreeModel::Node&)>& predicate)
{
// Test the node itself
Expand Down
6 changes: 6 additions & 0 deletions libs/wxutil/dataview/TreeModel.h
Expand Up @@ -475,6 +475,12 @@ class TreeModel :
// Find the given number needle in the given column (searches only the subtree given by the startNode item)
virtual wxDataViewItem FindInteger(long needle, const Column& column, const wxDataViewItem& startNode);

// Find the item matching the predicate (searches the entire tree)
virtual wxDataViewItem FindItem(const std::function<bool(const TreeModel::Row&)>& predicate);

// Find the item matching the predicate (searches from the given item)
virtual wxDataViewItem FindItem(const std::function<bool(const TreeModel::Row&)>& predicate, const wxDataViewItem& startNode);

// Returns true if any of the given columns in the given row contains the string value
// Set lowerStrings to true to convert the column values to lowercase first (the value is not touched
// and needs to be made lowercase by the calling code).
Expand Down
9 changes: 7 additions & 2 deletions radiant/ui/materials/editor/MaterialEditor.cpp
Expand Up @@ -2036,14 +2036,19 @@ void MaterialEditor::updateStageListFromMaterial()
row[STAGE_COLS().index] = index;
row[STAGE_COLS().name] = getNameForLayer(*layer);
row[STAGE_COLS().visible] = true;
row[STAGE_COLS().global] = false;

row.SendItemAdded();

++index;
}

// Pre-select the first stage (it's ok if there are no stages)
selectStageByIndex(0);
// Pre-select the global settings page
auto globalSettings = _stageList->FindItem([&](const wxutil::TreeModel::Row& row)
{
return row[STAGE_COLS().global].getBool();
});
_stageView->Select(globalSettings);
}

void MaterialEditor::updateMaterialPropertiesFromMaterial()
Expand Down

0 comments on commit e285ae3

Please sign in to comment.