Skip to content

Commit

Permalink
#5613: Inherited properties can be displayed if there's a single clas…
Browse files Browse the repository at this point in the history
…sname shared by all selected entities.
  • Loading branch information
codereader committed Oct 17, 2021
1 parent efcf6c7 commit 464ec1f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 18 deletions.
71 changes: 53 additions & 18 deletions radiant/ui/einspector/EntityInspector.cpp
Expand Up @@ -71,7 +71,8 @@ EntityInspector::EntityInspector() :
_keyEntry(nullptr),
_valEntry(nullptr),
_setButton(nullptr),
_selectionNeedsUpdate(true)
_selectionNeedsUpdate(true),
_inheritedPropertiesNeedUpdate(true)
{}

void EntityInspector::construct()
Expand Down Expand Up @@ -123,22 +124,6 @@ void EntityInspector::construct()

_helpText->Hide();

// Connect to registry key and handle the loaded value
registry::bindWidget(_showHelpColumnCheckbox, RKEY_SHOW_HELP_AREA);
registry::bindWidget(_showInheritedCheckbox, RKEY_SHOW_INHERITED_PROPERTIES);

handleShowInheritedChanged();
handleShowHelpTextChanged();

// Reload the information from the registry
restoreSettings();

// Create the context menu
createContextMenu();

// Stimulate initial redraw to get the correct status
requestIdleCallback();

// Register self to the SelectionSystem to get notified upon selection
// changes.
GlobalSelectionSystem().addObserver(this);
Expand All @@ -156,6 +141,22 @@ void EntityInspector::construct()
);

_entitySelection = std::make_unique<selection::EntitySelection>(*_spawnargs);

// Connect to registry key and handle the loaded value
registry::bindWidget(_showHelpColumnCheckbox, RKEY_SHOW_HELP_AREA);
registry::bindWidget(_showInheritedCheckbox, RKEY_SHOW_INHERITED_PROPERTIES);

handleShowInheritedChanged();
handleShowHelpTextChanged();

// Reload the information from the registry
restoreSettings();

// Create the context menu
createContextMenu();

// Stimulate initial redraw to get the correct status
requestIdleCallback();

_defsReloadedHandler = GlobalEntityClassManager().defsReloadedSignal().connect(
sigc::mem_fun(this, &EntityInspector::onDefsReloaded)
Expand Down Expand Up @@ -463,13 +464,24 @@ void EntityInspector::onMainFrameShuttingDown()
_currentPropertyEditor.reset();
}

void EntityInspector::onKeyUpdatedCommon(const std::string& key)
{
if (key == "classname")
{
_inheritedPropertiesNeedUpdate = true;
}
}

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

void EntityInspector::onKeyRemoved(const std::string& key)
{
onKeyUpdatedCommon(key);

// Look up iter in the TreeIter map, and delete it from the list store
auto i = _keyValueIterMap.find(key);

Expand All @@ -490,6 +502,7 @@ void EntityInspector::onKeyRemoved(const std::string& key)

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

Expand Down Expand Up @@ -726,7 +739,7 @@ void EntityInspector::updateGUIElements()
{
_editorFrame->Enable(entityCanBeUpdated);
_keyValueTreeView->Enable(true);
_showInheritedCheckbox->Enable(true);
//_showInheritedCheckbox->Enable(true);
_showHelpColumnCheckbox->Enable(true);
_keyEntry->Enable(entityCanBeUpdated);
_valEntry->Enable(entityCanBeUpdated);
Expand All @@ -750,6 +763,9 @@ void EntityInspector::updateGUIElements()
}
else // no selected entity
{
// Reset the sorting when changing entities
_keyValueTreeView->ResetSortingOnAllColumns();

// Remove the displayed PropertyEditor
_currentPropertyEditor.reset();

Expand All @@ -771,6 +787,25 @@ void EntityInspector::onIdle()
_entitySelection->update();
}

if (_inheritedPropertiesNeedUpdate)
{
_inheritedPropertiesNeedUpdate = false;

// We can display inherited key values if the classname is unique
bool canShowInheritedKeys = !_spawnargs->getSharedKeyValue("classname").empty();

_showInheritedCheckbox->Enable(canShowInheritedKeys);

if (canShowInheritedKeys && _showInheritedCheckbox->IsChecked())
{
addClassProperties();
}
else
{
removeClassProperties();
}
}

updateGUIElements();
}

Expand Down
4 changes: 4 additions & 0 deletions radiant/ui/einspector/EntityInspector.h
Expand Up @@ -163,6 +163,7 @@ class EntityInspector final :
std::map<std::string, scene::merge::IConflictResolutionAction::Ptr> _conflictActions;

bool _selectionNeedsUpdate;
bool _inheritedPropertiesNeedUpdate;

private:
bool canUpdateEntity();
Expand Down Expand Up @@ -214,6 +215,9 @@ class EntityInspector final :
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);

// Routines shared by onKeyAdded, onKeyRemoved and onKeyValueSetChanged
void onKeyUpdatedCommon(const std::string& key);

void handleShowInheritedChanged();
void handleShowHelpTextChanged();
Expand Down

0 comments on commit 464ec1f

Please sign in to comment.