Delete empty Netclass fields only if there are others.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16997
This commit is contained in:
Jeff Young 2024-02-16 16:32:26 +00:00
parent 8a3cbce8f8
commit a34b242f4e
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(); const wxString& fieldText = field.GetText();
if( fieldName.IsEmpty() && fieldText.IsEmpty() ) if( fieldName.IsEmpty() && fieldText.IsEmpty() )
{
// delete empty, unnamed fields
m_fields->erase( m_fields->begin() + ii ); m_fields->erase( m_fields->begin() + ii );
}
else if( fieldName == wxT( "Netclass" ) && fieldText.IsEmpty() ) 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() ) else if( fieldName.IsEmpty() )
{
// give non-empty, unnamed fields a name
field.SetName( _( "untitled" ) ); field.SetName( _( "untitled" ) );
}
} }
m_currentLabel->SetFields( *m_fields ); m_currentLabel->SetFields( *m_fields );