Skip to content

Commit

Permalink
#6107: Preserve the expanded/selected state of the tree when rebuildi…
Browse files Browse the repository at this point in the history
…ng it
  • Loading branch information
codereader committed Oct 1, 2022
1 parent 32202b2 commit 1fd7312
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions radiant/ui/layers/LayerControlDialog.cpp
Expand Up @@ -222,6 +222,18 @@ void LayerControlDialog::refresh()
{
_refreshTreeOnIdle = false;

// Find out which layers are currently expanded and/or selected
auto selectedLayerId = getSelectedLayerId();
std::set<int> expandedLayers;

for (const auto& [id, item] : _layerItemMap)
{
if (_layersView->IsExpanded(item))
{
expandedLayers.insert(id);
}
}

clearControls();

if (!GlobalMapModule().getRoot()) return; // no map present
Expand All @@ -234,6 +246,22 @@ void LayerControlDialog::refresh()
std::bind(&TreePopulator::processLayer, &populator, std::placeholders::_1, std::placeholders::_2));

_layerItemMap = std::move(populator.getLayerItemMap());

// Restore the expanded state of tree elements
for (const auto& [id, item] : _layerItemMap)
{
if (expandedLayers.count(id) > 0)
{
_layersView->Expand(item);
}

if (selectedLayerId == id)
{
_layersView->Select(item);
_layersView->EnsureVisible(item);
}
}

updateButtonSensitivity(populator.getNumVisibleLayers(), populator.getNumHiddenLayers());
}

Expand Down

0 comments on commit 1fd7312

Please sign in to comment.