Improve safety around un-committed grid changes.

This commit is contained in:
Jeff Young 2018-08-15 14:29:19 +01:00
parent a6d10d6e28
commit afacb6e7cb
4 changed files with 35 additions and 18 deletions

View File

@ -775,12 +775,19 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnUpdateUI( wxUpdateUIEvent& event )
m_delayedFocusGrid->SetGridCursor( m_delayedFocusRow, m_delayedFocusColumn ); m_delayedFocusGrid->SetGridCursor( m_delayedFocusRow, m_delayedFocusColumn );
if( !m_delayedErrorMessage.IsEmpty() ) if( !m_delayedErrorMessage.IsEmpty() )
DisplayErrorMessage( this, m_delayedErrorMessage ); {
// We will re-enter this routine when the error dialog is displayed, so make
// sure we don't keep putting up more dialogs.
wxString msg = m_delayedErrorMessage;
m_delayedErrorMessage = wxEmptyString;
// Do not use DisplayErrorMessage(); it screws up window order on Mac
DisplayError( nullptr, msg );
}
m_delayedFocusGrid->EnableCellEditControl( true ); m_delayedFocusGrid->EnableCellEditControl( true );
m_delayedFocusGrid->ShowCellEditControl(); m_delayedFocusGrid->ShowCellEditControl();
m_delayedErrorMessage = wxEmptyString;
m_delayedFocusGrid = nullptr; m_delayedFocusGrid = nullptr;
} }
} }

View File

@ -546,8 +546,8 @@ void DIALOG_EDIT_COMPONENTS_LIBID::AddRowToGrid( bool aMarkRow, const wxString&
bool DIALOG_EDIT_COMPONENTS_LIBID::validateLibIds() bool DIALOG_EDIT_COMPONENTS_LIBID::validateLibIds()
{ {
// Commit any pending edits if( !m_grid->CommitPendingChanges() )
m_grid->DisableCellEditControl(); return false;
int row_max = m_grid->GetNumberRows() - 1; int row_max = m_grid->GetNumberRows() - 1;

View File

@ -128,8 +128,6 @@ DIALOG_FOOTPRINT_BOARD_EDITOR::DIALOG_FOOTPRINT_BOARD_EDITOR( PCB_EDIT_FRAME* aP
m_allow180Label->SetFont( infoFont ); m_allow180Label->SetFont( infoFont );
m_libraryIDLabel->SetFont( infoFont ); m_libraryIDLabel->SetFont( infoFont );
m_staticLibraryID->SetFont( infoFont ); m_staticLibraryID->SetFont( infoFont );
m_sheetPathLabel->SetFont( infoFont );
m_staticSheetPath->SetFont( infoFont );
m_staticTextInfoValNeg->SetFont( infoFont ); m_staticTextInfoValNeg->SetFont( infoFont );
m_staticTextInfoValPos->SetFont( infoFont ); m_staticTextInfoValPos->SetFont( infoFont );
m_staticTextInfoCopper->SetFont( infoFont ); m_staticTextInfoCopper->SetFont( infoFont );
@ -373,9 +371,8 @@ bool DIALOG_FOOTPRINT_BOARD_EDITOR::TransferDataToWindow()
select3DModel( 0 ); // will clamp idx within bounds select3DModel( 0 ); // will clamp idx within bounds
// Show the footprint's ID and schematic reference. // Show the footprint's ID.
m_staticLibraryID->SetLabel( m_footprint->GetFPID().Format() ); m_staticLibraryID->SetLabel( m_footprint->GetFPID().Format() );
m_staticSheetPath->SetLabel( m_footprint->GetPath() );
Layout(); Layout();
adjustGridColumns( m_itemsGrid->GetRect().GetWidth()); adjustGridColumns( m_itemsGrid->GetRect().GetWidth());
@ -424,6 +421,7 @@ void DIALOG_FOOTPRINT_BOARD_EDITOR::On3DModelCellChanged( wxGridEvent& aEvent )
m_delayedFocusGrid = m_modelsGrid; m_delayedFocusGrid = m_modelsGrid;
m_delayedFocusRow = aEvent.GetRow(); m_delayedFocusRow = aEvent.GetRow();
m_delayedFocusColumn = aEvent.GetCol(); m_delayedFocusColumn = aEvent.GetCol();
aEvent.Veto();
} }
// if the user has specified an alias in the name then prepend ':' // if the user has specified an alias in the name then prepend ':'
@ -450,6 +448,8 @@ void DIALOG_FOOTPRINT_BOARD_EDITOR::On3DModelCellChanged( wxGridEvent& aEvent )
void DIALOG_FOOTPRINT_BOARD_EDITOR::OnRemove3DModel( wxCommandEvent& ) void DIALOG_FOOTPRINT_BOARD_EDITOR::OnRemove3DModel( wxCommandEvent& )
{ {
m_modelsGrid->CommitPendingChanges( true /* quiet mode */ );
int idx = m_modelsGrid->GetGridCursorRow(); int idx = m_modelsGrid->GetGridCursorRow();
if( idx >= 0 ) if( idx >= 0 )
@ -465,6 +465,9 @@ void DIALOG_FOOTPRINT_BOARD_EDITOR::OnRemove3DModel( wxCommandEvent& )
void DIALOG_FOOTPRINT_BOARD_EDITOR::OnAdd3DModel( wxCommandEvent& ) void DIALOG_FOOTPRINT_BOARD_EDITOR::OnAdd3DModel( wxCommandEvent& )
{ {
if( !m_modelsGrid->CommitPendingChanges() )
return;
PROJECT& prj = Prj(); PROJECT& prj = Prj();
MODULE_3D_SETTINGS model; MODULE_3D_SETTINGS model;
@ -525,6 +528,9 @@ void DIALOG_FOOTPRINT_BOARD_EDITOR::OnAdd3DModel( wxCommandEvent& )
void DIALOG_FOOTPRINT_BOARD_EDITOR::OnAdd3DRow( wxCommandEvent& ) void DIALOG_FOOTPRINT_BOARD_EDITOR::OnAdd3DRow( wxCommandEvent& )
{ {
if( !m_modelsGrid->CommitPendingChanges() )
return;
MODULE_3D_SETTINGS model; MODULE_3D_SETTINGS model;
model.m_Preview = true; model.m_Preview = true;
@ -545,8 +551,8 @@ void DIALOG_FOOTPRINT_BOARD_EDITOR::OnAdd3DRow( wxCommandEvent& )
bool DIALOG_FOOTPRINT_BOARD_EDITOR::Validate() bool DIALOG_FOOTPRINT_BOARD_EDITOR::Validate()
{ {
// Commit any pending in-place edits and close the editor if( !m_itemsGrid->CommitPendingChanges() )
m_itemsGrid->DisableCellEditControl(); return false;
if( !DIALOG_SHIM::Validate() ) if( !DIALOG_SHIM::Validate() )
return false; return false;
@ -718,6 +724,9 @@ bool DIALOG_FOOTPRINT_BOARD_EDITOR::TransferDataFromWindow()
void DIALOG_FOOTPRINT_BOARD_EDITOR::OnAddField( wxCommandEvent& ) void DIALOG_FOOTPRINT_BOARD_EDITOR::OnAddField( wxCommandEvent& )
{ {
if( !m_itemsGrid->CommitPendingChanges() )
return;
const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings(); const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings();
TEXTE_MODULE textMod( m_footprint ); TEXTE_MODULE textMod( m_footprint );
@ -749,29 +758,29 @@ void DIALOG_FOOTPRINT_BOARD_EDITOR::OnAddField( wxCommandEvent& )
void DIALOG_FOOTPRINT_BOARD_EDITOR::OnDeleteField( wxCommandEvent& ) void DIALOG_FOOTPRINT_BOARD_EDITOR::OnDeleteField( wxCommandEvent& )
{ {
m_itemsGrid->CommitPendingChanges( true /* quiet mode */ );
int rowCount = m_itemsGrid->GetNumberRows(); int rowCount = m_itemsGrid->GetNumberRows();
int curRow = m_itemsGrid->GetGridCursorRow(); int curRow = m_itemsGrid->GetGridCursorRow();
if( curRow < 0 || curRow >= (int) m_texts->size() ) if( curRow < 0 )
return; return;
else if( curRow < 2 )
if( curRow < 2 )
{ {
DisplayError( nullptr, _( "Reference and value are mandatory." ) ); DisplayError( nullptr, _( "Reference and value are mandatory." ) );
return; return;
} }
auto start = m_texts->begin() + curRow; m_texts->erase( m_texts->begin() + curRow );
m_texts->erase( start, start + 1 );
// notify the grid // notify the grid
wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 ); wxGridTableMessage msg( m_texts, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
m_itemsGrid->ProcessTableMessage( msg ); m_itemsGrid->ProcessTableMessage( msg );
if( curRow == rowCount - 1 ) if( m_itemsGrid->GetNumberRows() > 0 )
{ {
m_itemsGrid->MakeCellVisible( curRow-1, m_itemsGrid->GetGridCursorCol() ); m_itemsGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
m_itemsGrid->SetGridCursor( curRow-1, m_itemsGrid->GetGridCursorCol() ); m_itemsGrid->SetGridCursor( std::max( 0, curRow-1 ), m_itemsGrid->GetGridCursorCol() );
} }
} }

View File

@ -336,6 +336,7 @@ void DIALOG_FOOTPRINT_FP_EDITOR::On3DModelCellChanged( wxGridEvent& aEvent )
m_delayedFocusGrid = m_modelsGrid; m_delayedFocusGrid = m_modelsGrid;
m_delayedFocusRow = aEvent.GetRow(); m_delayedFocusRow = aEvent.GetRow();
m_delayedFocusColumn = aEvent.GetCol(); m_delayedFocusColumn = aEvent.GetCol();
aEvent.Veto();
} }
// if the user has specified an alias in the name then prepend ':' // if the user has specified an alias in the name then prepend ':'