diff --git a/libs/wxutil/dataview/TreeModel.cpp b/libs/wxutil/dataview/TreeModel.cpp index 67899bd54f..6e01b50c73 100644 --- a/libs/wxutil/dataview/TreeModel.cpp +++ b/libs/wxutil/dataview/TreeModel.cpp @@ -492,6 +492,22 @@ wxDataViewItem TreeModel::FindInteger(long needle, const Column& column, const w }); } +wxDataViewItem TreeModel::FindItem(const std::function& predicate) +{ + return FindItem(predicate, wxDataViewItem()); +} + +wxDataViewItem TreeModel::FindItem(const std::function& predicate, const wxDataViewItem& startItem) +{ + auto* startNode = !startItem.IsOk() ? _rootNode.get() : static_cast(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& predicate) { // Test the node itself diff --git a/libs/wxutil/dataview/TreeModel.h b/libs/wxutil/dataview/TreeModel.h index 5b2b1100f2..663cd78583 100644 --- a/libs/wxutil/dataview/TreeModel.h +++ b/libs/wxutil/dataview/TreeModel.h @@ -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& predicate); + + // Find the item matching the predicate (searches from the given item) + virtual wxDataViewItem FindItem(const std::function& 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). diff --git a/radiant/ui/materials/editor/MaterialEditor.cpp b/radiant/ui/materials/editor/MaterialEditor.cpp index 56f2d411ba..0038fbfb1c 100644 --- a/radiant/ui/materials/editor/MaterialEditor.cpp +++ b/radiant/ui/materials/editor/MaterialEditor.cpp @@ -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()