Skip to content

Commit

Permalink
#5613: Fix display of removed and changed entity key values. On leavi…
Browse files Browse the repository at this point in the history
…ng merge mode the tree view needs to be cleared.
  • Loading branch information
codereader committed Oct 22, 2021
1 parent 98c1af8 commit 4fa64d9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
5 changes: 5 additions & 0 deletions include/imapmerge.h
Expand Up @@ -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 :
Expand Down
11 changes: 8 additions & 3 deletions libs/scene/merge/MergeAction.h
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -265,6 +265,11 @@ class SetEntityKeyValueAction :
return _value;
}

const std::string& getUnchangedValue() const override
{
return _unchangedValue;
}

INodePtr getAffectedNode() override
{
return getEntityNode();
Expand All @@ -283,7 +288,7 @@ class SetEntityKeyValueAction :
{
MergeAction::deactivate();

applyValue(_existingValue);
applyValue(_unchangedValue);
}

private:
Expand Down
24 changes: 19 additions & 5 deletions radiant/ui/einspector/EntityInspector.cpp
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -843,6 +850,9 @@ void EntityInspector::onIdle()
_keyValueTreeView->ResetSortingOnAllColumns();
}

_mergeActions.clear();
_conflictActions.clear();

if (GlobalMapModule().getEditMode() == IMap::EditMode::Merge)
{
auto selectionCount = GlobalSelectionSystem().countSelected();
Expand All @@ -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();
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4fa64d9

Please sign in to comment.