Skip to content

Commit

Permalink
#5623: Use background colours to show changed/added/removed key values
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed May 31, 2021
1 parent 16654fc commit cde31d5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 10 deletions.
15 changes: 15 additions & 0 deletions libs/wxutil/dataview/TreeViewItemStyle.h
Expand Up @@ -35,6 +35,21 @@ class TreeViewItemStyle

return wxDataViewItemAttr();
}

static wxColour KeyValueAddedBackground()
{
return wxColour(100, 254, 100);
}

static wxColour KeyValueChangedBackground()
{
return wxColour(90, 140, 254);
}

static wxColour KeyValueRemovedBackground()
{
return wxColour(254, 100, 100);
}
};

}
54 changes: 44 additions & 10 deletions radiant/ui/einspector/EntityInspector.cpp
Expand Up @@ -22,6 +22,7 @@
#include "wxutil/dialog/MessageBox.h"
#include "wxutil/menu/IconTextMenuItem.h"
#include "wxutil/dataview/TreeModel.h"
#include "wxutil/dataview/TreeViewItemStyle.h"
#include "xmlutil/Document.h"

#include <map>
Expand Down Expand Up @@ -182,7 +183,7 @@ void EntityInspector::onKeyChange(const std::string& key,

// Check if we already have an iter for this key (i.e. this is a
// modification).
TreeIterMap::const_iterator i = _keyValueIterMap.find(key);
auto i = _keyValueIterMap.find(key);

if (i != _keyValueIterMap.end())
{
Expand Down Expand Up @@ -219,8 +220,26 @@ void EntityInspector::onKeyChange(const std::string& key,
// Set the values for the row
wxutil::TreeModel::Row row(keyValueIter, *_kvStore);

wxDataViewItemAttr black;
black.SetColour(wxColor(0,0,0));
wxDataViewItemAttr style;

// Check if this key is affected by a merge operation
auto action = _mergeActions.find(key);

if (action != _mergeActions.end())
{
switch (action->second->getType())
{
case scene::merge::ActionType::AddKeyValue:
style.SetBackgroundColour(wxutil::TreeViewItemStyle::KeyValueAddedBackground());
break;
case scene::merge::ActionType::ChangeKeyValue:
style.SetBackgroundColour(wxutil::TreeViewItemStyle::KeyValueChangedBackground());
break;
case scene::merge::ActionType::RemoveKeyValue:
style.SetBackgroundColour(wxutil::TreeViewItemStyle::KeyValueRemovedBackground());
break;
}
}

wxIcon icon;
icon.CopyFromBitmap(parms.type.empty() ? _emptyIcon : PropertyEditorFactory::getBitmapFor(parms.type));
Expand All @@ -242,23 +261,38 @@ void EntityInspector::onKeyChange(const std::string& key,
row[_columns.booleanValue].setEnabled(false);
}

// Check if this key is affected by a merge operation
auto action = _mergeActions.find(key);

if (action != _mergeActions.end())
{
row[_columns.oldValue] = value;
if (action->second->getType() == scene::merge::ActionType::AddKeyValue)
{
row[_columns.oldValue] = std::string(); // no old value to show
row[_columns.oldValue] = style;
}
else
{
wxDataViewItemAttr oldAttr = style;
oldAttr.SetStrikethrough(true);
row[_columns.oldValue] = value;
row[_columns.oldValue] = oldAttr;
}

row[_columns.newValue] = action->second->getValue();

wxDataViewItemAttr newAttr = style;
newAttr.SetBold(true);

row[_columns.newValue] = newAttr;
}
else
{
row[_columns.oldValue] = std::string();
row[_columns.newValue] = std::string();
}

// Text colour
row[_columns.name] = black;
row[_columns.value] = black;
// Apply background style to all other columns
row[_columns.name] = style;
row[_columns.value] = style;
row[_columns.booleanValue] = style;

row[_columns.isInherited] = false;
row[_columns.hasHelpText] = hasDescription;
Expand Down

0 comments on commit cde31d5

Please sign in to comment.