From 4b1f057d74fc02d8040830fb5f06a23a1b8471f0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 27 Jun 2020 17:13:04 +0200 Subject: [PATCH] Factor out DoAcceptCellEditControl() into a separate function This allows to fold the last DoSaveEditControlValue() call into this function, so that it's only called from DoAcceptCellEditControl() or from SaveEditControlValue() (which is public, and hence can't be changed, even if its behaviour doesn't make much sense). This commit means that m_cellEditCtrlEnabled is now reset to false when AcceptCellEditControlIfShown() is called, which was not the case before, but this seems to make sense, as we shouldn't be just hiding the editor while leaving it enabled, and, also, doesn't really seem to change anything as hiding the editor indirectly results in a call to DisableCellEditControl(), via wxGrid::OnHideEditor(), and so it was actually already reset before -- but now this happens slightly earlier and more explicitly. --- include/wx/generic/grid.h | 7 +++++-- src/generic/grid.cpp | 27 ++++++++++++++++----------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index 1d47ea384f..38a51453e8 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -2908,8 +2908,11 @@ private: ); } - // Accept the changes in the edit control, if it's currently shown, and - // dismiss it. + // Accept the changes in the edit control, i.e. save them to the table and + // dismiss the editor. + void DoAcceptCellEditControl(); + + // As above, but do nothing if the control is not currently shown. void AcceptCellEditControlIfShown(); // Unlike the public SaveEditControlValue(), this method doesn't check if diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 206ffcab4a..675f6d2b75 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -7170,15 +7170,7 @@ void wxGrid::EnableCellEditControl( bool enable ) { SendEvent(wxEVT_GRID_EDITOR_HIDDEN); - HideCellEditControl(); - - // do it after HideCellEditControl() but before invoking - // user-defined handlers invoked by DoSaveEditControlValue() to - // ensure that we don't enter infinite loop if any of them try to - // disable the edit control again. - m_cellEditCtrlEnabled = false; - - DoSaveEditControlValue(); + DoAcceptCellEditControl(); } } } @@ -7415,11 +7407,24 @@ void wxGrid::AcceptCellEditControlIfShown() { if ( IsCellEditControlShown() ) { - HideCellEditControl(); - DoSaveEditControlValue(); + DoAcceptCellEditControl(); } } +void wxGrid::DoAcceptCellEditControl() +{ + HideCellEditControl(); + + // do it after HideCellEditControl() but before invoking + // user-defined handlers invoked by DoSaveEditControlValue() to + // ensure that we don't enter infinite loop if any of them try to + // disable the edit control again by calling DisableCellEditControl() + // from which we can be called + m_cellEditCtrlEnabled = false; + + DoSaveEditControlValue(); +} + void wxGrid::SaveEditControlValue() { if ( IsCellEditControlEnabled() )