Skip to content

Commit

Permalink
#5623: Add unimplemented context menu option to reject key value changes
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed May 31, 2021
1 parent ad41111 commit d64ecbc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
43 changes: 43 additions & 0 deletions radiant/ui/einspector/EntityInspector.cpp
Expand Up @@ -379,6 +379,15 @@ void EntityInspector::createContextMenu()
std::bind(&EntityInspector::_onPasteKey, this),
std::bind(&EntityInspector::_testPasteKey, this)
);

_contextMenu->addSeparator();

_contextMenu->addItem(
new wxutil::StockIconTextMenuItem(_("Reject selected Changes"), wxART_UNDO),
std::bind(&EntityInspector::_onRejectMergeAction, this),
std::bind(&EntityInspector::_testRejectMergeAction, this),
[] { return GlobalMapModule().getEditMode() == IMap::EditMode::Merge; }
);
}

void EntityInspector::onMainFrameConstructed()
Expand Down Expand Up @@ -935,6 +944,40 @@ bool EntityInspector::_testPasteKey()
return !_clipboard.empty() && canUpdateEntity();
}

void EntityInspector::_onRejectMergeAction()
{

}

bool EntityInspector::_testRejectMergeAction()
{
if (GlobalMapModule().getEditMode() != IMap::EditMode::Merge)
{
return false;
}

wxDataViewItemArray selectedItems;
_keyValueTreeView->GetSelections(selectedItems);

for (const wxDataViewItem& item : selectedItems)
{
wxutil::TreeModel::Row row(item, *_kvStore);

if (isItemAffecedByMergeOperation(row))
{
return true; // we have at least one non-inherited value that is not "classname"
}
}

return false;
}

bool EntityInspector::isItemAffecedByMergeOperation(const wxutil::TreeModel::Row& row)
{
auto key = row[_columns.name].getString().ToStdString();
return _mergeActions.count(key) > 0;
}

// wxWidget callbacks

void EntityInspector::_onContextMenu(wxDataViewEvent& ev)
Expand Down
3 changes: 3 additions & 0 deletions radiant/ui/einspector/EntityInspector.h
Expand Up @@ -173,16 +173,19 @@ class EntityInspector :
void _onCopyKey();
void _onCutKey();
void _onPasteKey();
void _onRejectMergeAction();

bool _testAddKey();
bool _testDeleteKey();
bool _testCopyKey();
bool _testCutKey();
bool _testPasteKey();
bool _testRejectMergeAction();

// Shared by cut and delete keys
bool _testNonEmptyAndDeletableSelection();
bool isItemDeletable(const wxutil::TreeModel::Row& row);
bool isItemAffecedByMergeOperation(const wxutil::TreeModel::Row& row);

// callbacks
void _onEntryActivate(wxCommandEvent& ev);
Expand Down

0 comments on commit d64ecbc

Please sign in to comment.