Delete empty Netclass fields only if there are others.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16997

(cherry picked from commit a34b242f4e)
This commit is contained in:
Jeff Young 2024-02-16 16:32:26 +00:00 committed by Roberto Fernandez Bautista
parent a156b49e2c
commit 800bbd8841
1 changed files with 19 additions and 1 deletions

View File

@ -502,11 +502,29 @@ bool DIALOG_LABEL_PROPERTIES::TransferDataFromWindow()
const wxString& fieldText = field.GetText();
if( fieldName.IsEmpty() && fieldText.IsEmpty() )
{
// delete empty, unnamed fields
m_fields->erase( m_fields->begin() + ii );
}
else if( fieldName == wxT( "Netclass" ) && fieldText.IsEmpty() )
m_fields->erase( m_fields->begin() + ii );
{
// delete empty Netclass fields if there are other Netclass fields present
int netclassFieldCount = 0;
for( int jj = 0; jj < m_fields->GetNumberRows(); ++jj )
{
if( m_fields->at( jj ).GetCanonicalName() == wxT( "Netclass" ) )
netclassFieldCount++;
}
if( netclassFieldCount > 1 )
m_fields->erase( m_fields->begin() + ii );
}
else if( fieldName.IsEmpty() )
{
// give non-empty, unnamed fields a name
field.SetName( _( "untitled" ) );
}
}
m_currentLabel->SetFields( *m_fields );