From 584eb9f53187bcc9feb6d356060befff8e25e98b Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Tue, 12 Sep 2023 15:20:25 -0700 Subject: [PATCH] Remove extra nag/grid assertion When editing the properties, if you accidentally make an extra line, you should be able to remove the data and have it ignored. --- eeschema/dialogs/dialog_sheet_properties.cpp | 5 ++--- eeschema/sch_field.h | 12 ++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/eeschema/dialogs/dialog_sheet_properties.cpp b/eeschema/dialogs/dialog_sheet_properties.cpp index be9865a3ce..f637cd2703 100644 --- a/eeschema/dialogs/dialog_sheet_properties.cpp +++ b/eeschema/dialogs/dialog_sheet_properties.cpp @@ -208,9 +208,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." ) ); @@ -367,7 +366,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 e808147e3b..9aababb6a8 100644 --- a/eeschema/sch_field.h +++ b/eeschema/sch_field.h @@ -134,6 +134,18 @@ public: return GetShownText( nullptr, aAllowExtraText, aDepth ); } + /** + * 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