Skip to content

Commit

Permalink
2094: preserve grid curosr when renaming a key (even if it reorders t…
Browse files Browse the repository at this point in the history
…he grid) (#2101)
  • Loading branch information
ericwa authored and kduske committed Mar 6, 2018
1 parent 386511a commit 08087c5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
24 changes: 23 additions & 1 deletion common/src/View/EntityAttributeGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ namespace TrenchBroom {
moveCursorTo(row + 1, 0);
}
}

void EntityAttributeGrid::setLastSelectedNameAndColumn(const Model::AttributeName& name, const int col) {
if (IsBeingDeleted()) return;

m_lastSelectedName = name;
m_lastSelectedCol = col;
}

void EntityAttributeGrid::OnAttributeGridTab(wxGridEvent& event) {
tabNavigate(event.GetRow(), event.GetCol(), !event.ShiftDown());
Expand Down Expand Up @@ -295,7 +302,13 @@ namespace TrenchBroom {
if (event.GetKeyCode() == WXK_TAB) {
// HACK: Consume tab key and use it for cell navigation.
// Otherwise, wxTextCtrl::AutoComplete uses it for cycling between completions (on Windows)
m_grid->tabNavigate(m_row, m_col, !event.ShiftDown());

// First, close the cell editor
m_grid->gridWindow()->DisableCellEditControl();

// Closing the editor might reorder the cells (#2094), so m_row/m_col are no longer valid.
// Ask the wxGrid for the cursor row/column.
m_grid->tabNavigate(m_grid->gridWindow()->GetGridCursorRow(), m_grid->gridWindow()->GetGridCursorCol(), !event.ShiftDown());
} else if (event.GetKeyCode() == WXK_RETURN && m_col == 1) {
// HACK: (#1976) Make the next call to EndEdit return true unconditionally
// so it's possible to press enter to apply a value to all entites in a selection
Expand Down Expand Up @@ -348,6 +361,15 @@ namespace TrenchBroom {
return superclassDidChange;
}
}

void ApplyEdit(int row, int col, wxGrid* grid) override {
if (col == 0) {
// Hack to preserve selection when renaming a key (#2094)
const auto newName = GetValue().ToStdString();
m_grid->setLastSelectedNameAndColumn(newName, col);
}
wxGridCellTextEditor::ApplyEdit(row, col, grid);
}
};

void EntityAttributeGrid::createGui(MapDocumentWPtr document) {
Expand Down
1 change: 1 addition & 0 deletions common/src/View/EntityAttributeGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ namespace TrenchBroom {
void OnAttributeGridTab(wxGridEvent& event);
public:
void tabNavigate(int row, int col, bool forward);
void setLastSelectedNameAndColumn(const Model::AttributeName& name, const int col);
private:
void moveCursorTo(int row, int col);
void fireSelectionEvent(int row, int col);
Expand Down

0 comments on commit 08087c5

Please sign in to comment.