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.
This commit is contained in:
Seth Hillbrand 2023-09-12 15:20:25 -07:00
parent 36a4d5a511
commit 584eb9f531
2 changed files with 14 additions and 3 deletions

View File

@ -208,9 +208,8 @@ bool DIALOG_SHEET_PROPERTIES::Validate()
for( size_t i = SHEET_MANDATORY_FIELDS; i < m_fields->size(); ++i ) for( size_t i = SHEET_MANDATORY_FIELDS; i < m_fields->size(); ++i )
{ {
SCH_FIELD& field = m_fields->at( 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." ) ); DisplayErrorMessage( this, _( "Fields must have a name." ) );
@ -367,7 +366,7 @@ bool DIALOG_SHEET_PROPERTIES::TransferDataFromWindow()
SCH_FIELD& field = m_fields->at( ii ); SCH_FIELD& field = m_fields->at( ii );
const wxString& fieldName = field.GetCanonicalName(); const wxString& fieldName = field.GetCanonicalName();
if( fieldName.IsEmpty() && field.GetText().IsEmpty() ) if( field.IsEmpty() )
m_fields->erase( m_fields->begin() + ii ); m_fields->erase( m_fields->begin() + ii );
else if( fieldName.IsEmpty() ) else if( fieldName.IsEmpty() )
field.SetName( _( "untitled" ) ); field.SetName( _( "untitled" ) );

View File

@ -134,6 +134,18 @@ public:
return GetShownText( nullptr, aAllowExtraText, aDepth ); 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; COLOR4D GetFieldColor() const;
void SetLastResolvedState( const SCH_ITEM* aItem ) override void SetLastResolvedState( const SCH_ITEM* aItem ) override