Ensure stackup material returned is correct after list item deletion

This commit is contained in:
Ian McInerney 2024-02-03 17:42:41 +00:00
parent 5c86247e21
commit 2fc96c1d11
2 changed files with 34 additions and 2 deletions

View File

@ -134,6 +134,26 @@ void DIALOG_DIELECTRIC_MATERIAL::onListKeyDown( wxListEvent& event )
{
int idx = event.GetIndex();
if( ( idx > 0 ) && ( event.GetKeyCode() == WXK_DELETE ) )
m_lcMaterials->DeleteItem( idx );
switch( event.GetKeyCode() )
{
case WXK_DELETE:
if( idx >= 0 )
{
m_lcMaterials->DeleteItem( idx );
m_materialList.DeleteSubstrate( idx );
// Get the new material information for the next item in the list
// (or last if the deleted item was the last item)
int next = ( idx < m_materialList.GetCount() ) ? idx : idx - 1;
m_lcMaterials->SetItemState( next, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
m_lcMaterials->SetItemState( next, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED );
m_lcMaterials->EnsureVisible( next );
}
break;
default:
event.Skip();
}
}

View File

@ -115,6 +115,18 @@ public:
m_substrateList.emplace_back( aItem );
return GetCount()-1;
}
/**
* Delete the specified item in the substrate list.
*
* @param aInd is the index in the substrate list to delete
*/
void DeleteSubstrate( int aIdx )
{
wxCHECK( aIdx > 0 && aIdx < (int) m_substrateList.size(), /* void */ );
m_substrateList.erase( m_substrateList.begin() + aIdx );
}
};
#endif // #ifndef DIELECTRIC_MATERIAL_H