From 4fa64d942ddd88313995c368a68bddf0fb098886 Mon Sep 17 00:00:00 2001 From: codereader Date: Fri, 22 Oct 2021 14:52:27 +0200 Subject: [PATCH] #5613: Fix display of removed and changed entity key values. On leaving merge mode the tree view needs to be cleared. --- include/imapmerge.h | 5 +++++ libs/scene/merge/MergeAction.h | 11 ++++++++--- radiant/ui/einspector/EntityInspector.cpp | 24 ++++++++++++++++++----- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/include/imapmerge.h b/include/imapmerge.h index 3915634c01..b64ad731ac 100644 --- a/include/imapmerge.h +++ b/include/imapmerge.h @@ -99,6 +99,11 @@ class IEntityKeyValueMergeAction : // Gets the value that is going to be set by this action virtual const std::string& getValue() const = 0; + + // The action is usually applying its value as soon as it is inserted into + // the scene for preview. It remembers the original entity key value, + // use tis method to retrieve it. + virtual const std::string& getUnchangedValue() const = 0; }; class IConflictResolutionAction : diff --git a/libs/scene/merge/MergeAction.h b/libs/scene/merge/MergeAction.h index 6086b1ebc0..f8aa278575 100644 --- a/libs/scene/merge/MergeAction.h +++ b/libs/scene/merge/MergeAction.h @@ -225,7 +225,7 @@ class SetEntityKeyValueAction : INodePtr _node; std::string _key; std::string _value; - std::string _existingValue; + std::string _unchangedValue; public: // Will call setKeyValue(key, value) on the targetnode when applyChanges() is called @@ -240,7 +240,7 @@ class SetEntityKeyValueAction : assert(!_key.empty()); // Store the existing value, it's reverted when deactivating this action - _existingValue = Node_getEntity(node)->getKeyValue(key); + _unchangedValue = Node_getEntity(node)->getKeyValue(key); } void applyChanges() override @@ -265,6 +265,11 @@ class SetEntityKeyValueAction : return _value; } + const std::string& getUnchangedValue() const override + { + return _unchangedValue; + } + INodePtr getAffectedNode() override { return getEntityNode(); @@ -283,7 +288,7 @@ class SetEntityKeyValueAction : { MergeAction::deactivate(); - applyValue(_existingValue); + applyValue(_unchangedValue); } private: diff --git a/radiant/ui/einspector/EntityInspector.cpp b/radiant/ui/einspector/EntityInspector.cpp index 8a153320ad..689b6f86b0 100644 --- a/radiant/ui/einspector/EntityInspector.cpp +++ b/radiant/ui/einspector/EntityInspector.cpp @@ -194,8 +194,15 @@ void EntityInspector::restoreSettings() void EntityInspector::onMapEditModeChanged(IMap::EditMode mode) { - // Clear the selection to not hold any references to merge nodes - changeSelectedEntity(scene::INodePtr(), scene::INodePtr()); + if (mode == IMap::EditMode::Normal) + { + _mergeActions.clear(); + _conflictActions.clear(); + _keyValueIterMap.clear(); + _kvStore->Clear(); + } + + _selectionNeedsUpdate = true; requestIdleCallback(); } @@ -306,7 +313,7 @@ void EntityInspector::onKeyChange(const std::string& key, const std::string& val { wxDataViewItemAttr oldAttr = style; wxutil::TreeViewItemStyle::SetStrikethrough(oldAttr, true); - row[_columns.oldValue] = value; + row[_columns.oldValue] = action->second->getUnchangedValue(); row[_columns.oldValue] = oldAttr; } @@ -843,6 +850,9 @@ void EntityInspector::onIdle() _keyValueTreeView->ResetSortingOnAllColumns(); } + _mergeActions.clear(); + _conflictActions.clear(); + if (GlobalMapModule().getEditMode() == IMap::EditMode::Merge) { auto selectionCount = GlobalSelectionSystem().countSelected(); @@ -854,8 +864,6 @@ void EntityInspector::onIdle() // no entities are directly selected, only merge nodes are candidates // We do a full refresh on every selection change in merge mode - _mergeActions.clear(); - _conflictActions.clear(); _kvStore->Clear(); _keyValueIterMap.clear(); _keyValueTreeView->ResetSortingOnAllColumns(); @@ -1722,6 +1730,12 @@ void EntityInspector::handleKeyValueMergeAction(const scene::merge::IEntityKeyVa { onKeyChange(key, mergeAction->getValue()); } + + // Remove keys are special too + if (mergeAction->getType() == scene::merge::ActionType::RemoveKeyValue && !_spawnargs->containsKey(key)) + { + onKeyChange(key, mergeAction->getUnchangedValue()); + } } void EntityInspector::handleMergeActions(const scene::INodePtr& selectedNode)