Skip to content

Commit

Permalink
#5613: In merge mode not real entities are selected. When hitting a s…
Browse files Browse the repository at this point in the history
…ingle merge node, the Entity Inspector is fully refreshing its view on every selection change.
  • Loading branch information
codereader committed Oct 22, 2021
1 parent 3267a40 commit 4369ea2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
15 changes: 0 additions & 15 deletions libs/selection/EntitySelection.h
Expand Up @@ -6,7 +6,6 @@
#include "ientity.h"
#include "iselection.h"
#include "iselectable.h"
#include "imapmerge.h"
#include "CollectiveSpawnargs.h"

namespace selection
Expand Down Expand Up @@ -259,20 +258,6 @@ class EntitySelection final :
return selectedNodeParent;
}

// Finally, we may encounter merge node types
if (selected->getNodeType() == scene::INode::Type::MergeAction &&
GlobalMapModule().getEditMode() == IMap::EditMode::Merge)
{
auto mergeAction = std::dynamic_pointer_cast<scene::IMergeActionNode>(selected);
assert(mergeAction);

if (mergeAction && Node_isEntity(mergeAction->getAffectedNode()))
{
// Use the entity of the merge node
return mergeAction->getAffectedNode();
}
}

return {}; // nothing of interest
}
};
Expand Down
44 changes: 35 additions & 9 deletions radiant/ui/einspector/EntityInspector.cpp
Expand Up @@ -843,18 +843,31 @@ void EntityInspector::onIdle()
_keyValueTreeView->ResetSortingOnAllColumns();
}

// Clear the merge info
_mergeActions.clear();
_conflictActions.clear();
if (GlobalMapModule().getEditMode() == IMap::EditMode::Merge)
{
auto selectionCount = GlobalSelectionSystem().countSelected();

// Disable the tree view if we're in merge mode and multiple entities are selected
_keyValueTreeView->Enable(selectionCount == 1);

bool mergeMode = GlobalMapModule().getEditMode() == IMap::EditMode::Merge;
// In merge mode, we handle all updates ourselves,
// no entities are directly selected, only merge nodes are candidates

// Disable the tree view if we're in merge mode and multiple entities are selected
_keyValueTreeView->Enable(!mergeMode || _entitySelection->size() == 1);
// We do a full refresh on every selection change in merge mode
_mergeActions.clear();
_conflictActions.clear();
_kvStore->Clear();
_keyValueIterMap.clear();
_keyValueTreeView->ResetSortingOnAllColumns();

if (mergeMode && _entitySelection->size() == 1)
if (GlobalSelectionSystem().countSelected() == 1)
{
handleMergeActions(GlobalSelectionSystem().ultimateSelected());
}
}
else
{
handleMergeActions(_entitySelection->getSingleSelectedEntity());
_keyValueTreeView->Enable(!_entitySelection->empty());
}

updatePrimitiveNumber();
Expand Down Expand Up @@ -1169,6 +1182,7 @@ void EntityInspector::_onAcceptMergeAction()
// We perform a full refresh of the view
changeSelectedEntity(scene::INodePtr(), scene::INodePtr());
_selectionNeedsUpdate = true;
requestIdleCallback();
}

void EntityInspector::_onRejectMergeAction()
Expand Down Expand Up @@ -1221,6 +1235,7 @@ void EntityInspector::_onRejectMergeAction()
// We perform a full refresh of the view
changeSelectedEntity(scene::INodePtr(), scene::INodePtr());
_selectionNeedsUpdate = true;
requestIdleCallback();
}

bool EntityInspector::_testAcceptMergeAction()
Expand Down Expand Up @@ -1719,7 +1734,8 @@ void EntityInspector::handleMergeActions(const scene::INodePtr& selectedNode)
auto mergeNode = std::dynamic_pointer_cast<scene::IMergeActionNode>(selectedNode);

if (!mergeNode) return;


// Collect all the merge actions and conflict info first
mergeNode->foreachMergeAction([&](const scene::merge::IMergeAction::Ptr& action)
{
if (!action->isActive()) return; // don't apply inactive actions to our view
Expand Down Expand Up @@ -1754,6 +1770,16 @@ void EntityInspector::handleMergeActions(const scene::INodePtr& selectedNode)
}
}
});

// Now load the regular key values from the entity into the view
auto affectedEntity = Node_getEntity(mergeNode->getAffectedNode());

if (!affectedEntity) return; // not an entity we're looking at

affectedEntity->forEachKeyValue([&](const std::string& key, const std::string& value)
{
onKeyChange(key, value, false);
});
}

void EntityInspector::registerPropertyEditorDialog(const std::string& key, const IPropertyEditorDialog::CreationFunc& create)
Expand Down

0 comments on commit 4369ea2

Please sign in to comment.