From a34b242f4eda2e5ababea59c8192bf3daa5a4179 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 16 Feb 2024 16:32:26 +0000 Subject: [PATCH] Delete empty Netclass fields only if there are others. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16997 --- eeschema/dialogs/dialog_label_properties.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/eeschema/dialogs/dialog_label_properties.cpp b/eeschema/dialogs/dialog_label_properties.cpp index 15594c80b7..e4c6880c2b 100644 --- a/eeschema/dialogs/dialog_label_properties.cpp +++ b/eeschema/dialogs/dialog_label_properties.cpp @@ -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 );