Less nagging. (If we need a field name, then create one.)

Also cleans up empty fields when exiting the dialog.
This commit is contained in:
Jeff Young 2023-03-19 19:15:02 +00:00
parent f97beb15b8
commit ef0d561a5c
5 changed files with 84 additions and 52 deletions

View File

@ -502,6 +502,20 @@ bool DIALOG_LABEL_PROPERTIES::TransferDataFromWindow()
else
doAutoplace = true;
for( int ii = m_fields->GetNumberRows() - 1; ii >= 0; ii-- )
{
SCH_FIELD& field = m_fields->at( ii );
const wxString& fieldName = field.GetCanonicalName();
const wxString& fieldText = field.GetText();
if( fieldName.IsEmpty() && fieldText.IsEmpty() )
m_fields->erase( m_fields->begin() + ii );
else if( fieldName == wxT( "Netclass" ) && fieldText.IsEmpty() )
m_fields->erase( m_fields->begin() + ii );
else if( fieldName.IsEmpty() )
field.SetName( _( "untitled" ) );
}
m_currentLabel->SetFields( *m_fields );
if( m_shapeSizer->AreAnyItemsShown() )

View File

@ -302,7 +302,7 @@ bool DIALOG_LIB_SYMBOL_PROPERTIES::Validate()
LIB_FIELD& field = m_fields->at( ii );
wxString fieldName = field.GetName( false );
if( fieldName.IsEmpty() )
if( fieldName.IsEmpty() && !field.GetText().IsEmpty() )
{
if( m_NoteBook->GetSelection() != 0 )
m_NoteBook->SetSelection( 0 );
@ -393,6 +393,17 @@ bool DIALOG_LIB_SYMBOL_PROPERTIES::TransferDataFromWindow()
m_fields->at( ii ).SetId( ii );
}
for( int ii = m_fields->GetNumberRows() - 1; ii >= MANDATORY_FIELDS; ii-- )
{
LIB_FIELD& field = m_fields->at( ii );
const wxString& fieldName = field.GetCanonicalName();
if( fieldName.IsEmpty() && field.GetText().IsEmpty() )
m_fields->erase( m_fields->begin() + ii );
else if( fieldName.IsEmpty() )
field.SetName( _( "untitled" ) );
}
m_libEntry->SetFields( *m_fields );
// Update the parent for inherited symbols

View File

@ -364,6 +364,17 @@ bool DIALOG_SHEET_PROPERTIES::TransferDataFromWindow()
if( positioningChanged( m_fields, m_sheet->GetFields() ) )
m_sheet->ClearFieldsAutoplaced();
for( int ii = m_fields->GetNumberRows() - 1; ii >= SHEET_MANDATORY_FIELDS; ii-- )
{
SCH_FIELD& field = m_fields->at( ii );
const wxString& fieldName = field.GetCanonicalName();
if( fieldName.IsEmpty() && field.GetText().IsEmpty() )
m_fields->erase( m_fields->begin() + ii );
else if( fieldName.IsEmpty() )
field.SetName( _( "untitled" ) );
}
m_sheet->SetFields( *m_fields );
m_sheet->SetBorderWidth( m_borderWidth.GetValue() );

View File

@ -769,8 +769,18 @@ bool DIALOG_SYMBOL_PROPERTIES::TransferDataFromWindow()
fields.clear();
for( size_t i = 0; i < m_fields->size(); ++i )
fields.push_back( m_fields->at( i ) );
for( size_t ii = 0; ii < m_fields->size(); ++ii )
{
SCH_FIELD& field = m_fields->at( ii );
const wxString& fieldName = field.GetCanonicalName();
if( fieldName.IsEmpty() && field.GetText().IsEmpty() )
continue;
else if( fieldName.IsEmpty() )
field.SetName( _( "untitled" ) );
fields.push_back( field );
}
// Reference has a specific initialization, depending on the current active sheet
// because for a given symbol, in a complex hierarchy, there are more than one

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Wayne Stambaugh, stambaughw@gmail.com
* Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -60,8 +60,7 @@ SCH_FIELD_VALIDATOR::SCH_FIELD_VALIDATOR( bool aIsLibEditor, int aFieldId, wxSt
// The reference, sheetname and sheetfilename fields cannot be empty.
if( aFieldId == REFERENCE_FIELD
|| aFieldId == SHEETNAME_V
|| aFieldId == SHEETFILENAME_V
|| aFieldId == FIELD_NAME )
|| aFieldId == SHEETFILENAME_V )
{
style |= wxFILTER_EMPTY;
}
@ -91,54 +90,12 @@ bool SCH_FIELD_VALIDATOR::Validate( wxWindow* aParent )
return false;
wxString val( text->GetValue() );
// The format of the error message for not allowed chars
wxString fieldCharError;
switch( m_fieldId )
{
case REFERENCE_FIELD:
fieldCharError = _( "The reference designator cannot contain %s character(s)." );
break;
case VALUE_FIELD:
fieldCharError = _( "The value field cannot contain %s character(s)." );
break;
case FOOTPRINT_FIELD:
fieldCharError = _( "The footprint field cannot contain %s character(s)." );
break;
case DATASHEET_FIELD:
fieldCharError = _( "The datasheet field cannot contain %s character(s)." );
break;
case SHEETNAME_V:
fieldCharError = _( "The sheet name cannot contain %s character(s)." );
break;
case SHEETFILENAME_V:
fieldCharError = _( "The sheet filename cannot contain %s character(s)." );
break;
default:
fieldCharError = _( "The field cannot contain %s character(s)." );
break;
};
wxString msg;
// We can only do some kinds of validation once the input is complete, so
// check for them here:
if( HasFlag( wxFILTER_EMPTY ) && val.empty() )
{
// Some fields cannot have an empty value, and user fields require a name:
if( m_fieldId == FIELD_NAME )
msg.Printf( _( "The name of the field cannot be empty." ) );
else // the FIELD_VALUE id or REFERENCE_FIELD or VALUE_FIELD
msg.Printf( _( "The value of the field cannot be empty." ) );
}
else if( HasFlag( wxFILTER_EXCLUDE_CHAR_LIST ) && ContainsExcludedCharacters( val ) )
msg.Printf( _( "The value of the field cannot be empty." ) );
if( HasFlag( wxFILTER_EXCLUDE_CHAR_LIST ) && ContainsExcludedCharacters( val ) )
{
wxArrayString badCharsFound;
@ -200,7 +157,36 @@ bool SCH_FIELD_VALIDATOR::Validate( wxWindow* aParent )
badChars += badCharsFound.Item( i );
}
msg.Printf( fieldCharError, badChars );
switch( m_fieldId )
{
case REFERENCE_FIELD:
msg.Printf( _( "The reference designator cannot contain %s character(s)." ), badChars );
break;
case VALUE_FIELD:
msg.Printf( _( "The value field cannot contain %s character(s)." ), badChars );
break;
case FOOTPRINT_FIELD:
msg.Printf( _( "The footprint field cannot contain %s character(s)." ), badChars );
break;
case DATASHEET_FIELD:
msg.Printf( _( "The datasheet field cannot contain %s character(s)." ), badChars );
break;
case SHEETNAME_V:
msg.Printf( _( "The sheet name cannot contain %s character(s)." ), badChars );
break;
case SHEETFILENAME_V:
msg.Printf( _( "The sheet filename cannot contain %s character(s)." ), badChars );
break;
default:
msg.Printf( _( "The field cannot contain %s character(s)." ), badChars );
break;
};
}
else if( m_fieldId == REFERENCE_FIELD && val.Contains( wxT( "${" ) ) )
{