Skip to content

Commit

Permalink
#5613: Disengage the existing key value handling code in EntityInspec…
Browse files Browse the repository at this point in the history
…tor. Key value addition/removal/update is now exclusively handled by listening to the signals emitted by the CollectiveSpawnargs helper. A couple of things stopped working at this point.
  • Loading branch information
codereader committed Oct 16, 2021
1 parent 54be9e9 commit b4b6c10
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 16 deletions.
73 changes: 59 additions & 14 deletions radiant/ui/einspector/EntityInspector.cpp
Expand Up @@ -142,6 +142,17 @@ void EntityInspector::construct()
// changes.
GlobalSelectionSystem().addObserver(this);
_entitySelection.reset(new selection::EntitySelection);

// Connect the signals
_keyValueAddedHandler = _entitySelection->getSpawnargs().signal_KeyAdded().connect(
sigc::mem_fun(this, &EntityInspector::onKeyAdded)
);
_keyValueRemovedHandler = _entitySelection->getSpawnargs().signal_KeyRemoved().connect(
sigc::mem_fun(this, &EntityInspector::onKeyRemoved)
);
_keyValueSetChangedHandler = _entitySelection->getSpawnargs().signal_KeyValueSetChanged().connect(
sigc::mem_fun(this, &EntityInspector::onKeyValueSetChanged)
);

_defsReloadedHandler = GlobalEntityClassManager().defsReloadedSignal().connect(
sigc::mem_fun(this, &EntityInspector::onDefsReloaded)
Expand Down Expand Up @@ -188,17 +199,10 @@ void EntityInspector::onMapEditModeChanged(IMap::EditMode mode)
void EntityInspector::onKeyInsert(const std::string& key,
EntityKeyValue& value)
{
onKeyChange(key, value.get());
//onKeyChange(key, value.get());
}

void EntityInspector::onKeyChange(const std::string& key,
const std::string& value)
{
onKeyChange(nullptr, key, value);
}

void EntityInspector::onKeyChange(Entity* entity, const std::string& key,
const std::string& value)
void EntityInspector::onKeyChange(const std::string& key, const std::string& value)
{
wxDataViewItem keyValueIter;
bool added = false;
Expand All @@ -215,7 +219,7 @@ void EntityInspector::onKeyChange(Entity* entity, const std::string& key,
{
// Append a new row to the list store and add it to the iter map
keyValueIter = _kvStore->AddItem().getItem();
_keyValueIterMap.insert(TreeIterMap::value_type(key, keyValueIter));
_keyValueIterMap.emplace(key, keyValueIter);

added = true;
}
Expand All @@ -227,10 +231,11 @@ void EntityInspector::onKeyChange(Entity* entity, const std::string& key,

//assert(!_selectedEntity.expired());
//Entity* selectedEntity = Node_getEntity(_selectedEntity.lock());
auto selectedEntity = entity;
//auto selectedEntity = entity;

bool hasDescription = false;

#if 0
if (selectedEntity != nullptr)
{
// Check the entityclass (which will return blank if not found)
Expand All @@ -244,6 +249,7 @@ void EntityInspector::onKeyChange(Entity* entity, const std::string& key,

hasDescription = !attr.getDescription().empty();
}
#endif

// Set the values for the row
wxutil::TreeModel::Row row(keyValueIter, *_kvStore);
Expand Down Expand Up @@ -365,6 +371,8 @@ void EntityInspector::onKeyChange(Entity* entity, const std::string& key,
void EntityInspector::onKeyErase(const std::string& key,
EntityKeyValue& value)
{
return;

// Look up iter in the TreeIter map, and delete it from the list store
TreeIterMap::iterator i = _keyValueIterMap.find(key);
if (i != _keyValueIterMap.end())
Expand Down Expand Up @@ -455,6 +463,9 @@ void EntityInspector::onMainFrameShuttingDown()
_selectedEntity.reset();

GlobalSelectionSystem().removeObserver(this);
_keyValueAddedHandler.disconnect();
_keyValueRemovedHandler.disconnect();
_keyValueSetChangedHandler.disconnect();
_entitySelection.reset();

_mergeActions.clear();
Expand All @@ -473,6 +484,36 @@ void EntityInspector::onMainFrameShuttingDown()
_currentPropertyEditor.reset();
}

void EntityInspector::onKeyAdded(const std::string& key, const std::string& value)
{
onKeyChange(key, value);
}

void EntityInspector::onKeyRemoved(const std::string& key)
{
// Look up iter in the TreeIter map, and delete it from the list store
auto i = _keyValueIterMap.find(key);

if (i != _keyValueIterMap.end())
{
// Erase row from tree store
_kvStore->RemoveItem(i->second);

// Erase iter from iter map
_keyValueIterMap.erase(i);
}
else
{
rConsoleError() << "EntityInspector: warning: removed key '" << key
<< "' not found in map." << std::endl;
}
}

void EntityInspector::onKeyValueSetChanged(const std::string& key, const std::string& uniqueValue)
{
onKeyChange(key, uniqueValue.empty() ? _("[differing values]") : uniqueValue);
}

void EntityInspector::onUndoRedoOperation()
{
refresh();
Expand Down Expand Up @@ -1463,14 +1504,14 @@ void EntityInspector::getEntityFromSelectionSystem()

if (numSelectedEntities == 0)
{
changeSelectedEntity(scene::INodePtr(), scene::INodePtr());
//changeSelectedEntity(scene::INodePtr(), scene::INodePtr());
_primitiveNumLabel->SetLabelText("");
return;
}

if (numSelectedEntities > 1)
{
changeSelectedEntity(scene::INodePtr(), scene::INodePtr());
//changeSelectedEntity(scene::INodePtr(), scene::INodePtr());
_primitiveNumLabel->SetLabelText(fmt::format("[{0} Entities]", numSelectedEntities));
}

Expand Down Expand Up @@ -1559,6 +1600,7 @@ void EntityInspector::getEntityFromSelectionSystem()

void EntityInspector::updateTreeView()
{
#if 0
// Clear the view. If the old entity has been destroyed before we had
// a chance to disconnect the list store might contain remnants
_keyValueIterMap.clear();
Expand All @@ -1568,7 +1610,8 @@ void EntityInspector::updateTreeView()

// Reset the sorting when changing entities
_keyValueTreeView->ResetSortingOnAllColumns();

#endif
#if 0
_entitySelection->foreachKey([&](const std::string& key, const selection::CollectiveSpawnargs::KeyValueSet& set)
{
if (set.valueIsEqualOnAllEntities)
Expand All @@ -1581,10 +1624,12 @@ void EntityInspector::updateTreeView()
onKeyChange(key, _("[multiple values]"));
}
});
#endif
}

void EntityInspector::changeSelectedEntity(const scene::INodePtr& newEntity, const scene::INodePtr& selectedNode)
{
return;
#if 0
// Check what we need to do with the existing entity
scene::INodePtr oldEntity = _selectedEntity.lock();
Expand Down
10 changes: 8 additions & 2 deletions radiant/ui/einspector/EntityInspector.h
Expand Up @@ -153,6 +153,10 @@ class EntityInspector :
sigc::connection _defsReloadedHandler;
sigc::connection _mapEditModeChangedHandler;

sigc::connection _keyValueAddedHandler;
sigc::connection _keyValueRemovedHandler;
sigc::connection _keyValueSetChangedHandler;

// Maps the key names to a possible merge action that should be displayed
std::map<std::string, scene::merge::IEntityKeyValueMergeAction::Ptr> _mergeActions;
std::map<std::string, scene::merge::IConflictResolutionAction::Ptr> _conflictActions;
Expand Down Expand Up @@ -204,6 +208,10 @@ class EntityInspector :
void _onContextMenu(wxDataViewEvent& ev);
void _onDataViewItemChanged(wxDataViewEvent& ev);

void onKeyAdded(const std::string& key, const std::string& value);
void onKeyRemoved(const std::string& key);
void onKeyValueSetChanged(const std::string& key, const std::string& uniqueValue);

void handleShowInheritedChanged();
void handleShowHelpTextChanged();
void updateHelpText(const wxutil::TreeModel::Row& row);
Expand Down Expand Up @@ -271,10 +279,8 @@ class EntityInspector :
void onMainFrameConstructed();
void onMainFrameShuttingDown();

/* Entity::Observer implementation */
void onKeyInsert(const std::string& key, EntityKeyValue& value);
void onKeyChange(const std::string& key, const std::string& value);
void onKeyChange(Entity* entity, const std::string& key, const std::string& value);
void onKeyErase(const std::string& key, EntityKeyValue& value);

// greebo: Tells the inspector to reload the window settings from the registry.
Expand Down

0 comments on commit b4b6c10

Please sign in to comment.