diff --git a/eeschema/dialogs/dialog_sheet_properties.cpp b/eeschema/dialogs/dialog_sheet_properties.cpp index 4b6cf65477..56e3a54a58 100644 --- a/eeschema/dialogs/dialog_sheet_properties.cpp +++ b/eeschema/dialogs/dialog_sheet_properties.cpp @@ -209,9 +209,8 @@ bool DIALOG_SHEET_PROPERTIES::Validate() for( size_t i = SHEET_MANDATORY_FIELDS; i < m_fields->size(); ++i ) { SCH_FIELD& field = m_fields->at( i ); - wxString fieldName = field.GetName( false ); - if( fieldName.IsEmpty() ) + if( field.GetName( false ).empty() && !field.GetText().empty() ) { DisplayErrorMessage( this, _( "Fields must have a name." ) ); @@ -363,7 +362,7 @@ bool DIALOG_SHEET_PROPERTIES::TransferDataFromWindow() SCH_FIELD& field = m_fields->at( ii ); const wxString& fieldName = field.GetCanonicalName(); - if( fieldName.IsEmpty() && field.GetText().IsEmpty() ) + if( field.IsEmpty() ) m_fields->erase( m_fields->begin() + ii ); else if( fieldName.IsEmpty() ) field.SetName( _( "untitled" ) ); diff --git a/eeschema/sch_field.h b/eeschema/sch_field.h index 4511c98153..57d75e99d1 100644 --- a/eeschema/sch_field.h +++ b/eeschema/sch_field.h @@ -140,6 +140,18 @@ public: wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override; + /** + * Return true if both the name and value of the field are empty. Whitespace + * does not count as non-empty + */ + bool IsEmpty() + { + wxString name( m_name ); + wxString value( GetText() ); + + return name.Trim().empty() && value.Trim().empty(); + } + COLOR4D GetFieldColor() const; void SetLastResolvedState( const SCH_ITEM* aItem ) override