mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-21 00:21:25 +00:00
Warn user when template field names contain trailing/leading white space.
When loading a schematic that contains fields with trailing/leading white space, show an infobar message. When editing the template field names, prompt the user to keep or remove any trailing or leading white space characters from field names. Fixes https://gitlab.com/kicad/code/kicad/-/issues/18601
This commit is contained in:
parent
fb0384d761
commit
d9d984d2c8
@ -22,6 +22,8 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <wx/msgdlg.h>
|
||||
|
||||
#include <pgm_base.h>
|
||||
#include <settings/settings_manager.h>
|
||||
#include <eeschema_settings.h>
|
||||
@ -186,10 +188,41 @@ bool PANEL_TEMPLATE_FIELDNAMES::TransferDataFromWindow()
|
||||
|
||||
m_templateMgr->DeleteAllFieldNameTemplates( m_global );
|
||||
|
||||
for( const TEMPLATE_FIELDNAME& field : m_fields )
|
||||
for( TEMPLATE_FIELDNAME& field : m_fields )
|
||||
{
|
||||
if( !field.m_Name.IsEmpty() )
|
||||
{
|
||||
wxString trimmedName = field.m_Name;
|
||||
|
||||
trimmedName.Trim();
|
||||
trimmedName.Trim( false );
|
||||
|
||||
// Check if the field name contains leading and/or trailing white space.
|
||||
if( field.m_Name != trimmedName )
|
||||
{
|
||||
wxString msg;
|
||||
|
||||
msg.Printf( _( "The field name \"%s\" contains trailing and/or leading white"
|
||||
"space." ), field.m_Name );
|
||||
|
||||
wxMessageDialog dlg( this, msg, _( "Warning" ),
|
||||
wxOK | wxCANCEL | wxCENTER | wxICON_WARNING );
|
||||
|
||||
dlg.SetExtendedMessage( _( "This may result in what appears to be duplicate field "
|
||||
"names but are actually unique names differing only by "
|
||||
"white space characters. Removing the white space "
|
||||
"characters will have no effect on existing symbol "
|
||||
"field names." ) );
|
||||
|
||||
dlg.SetOKCancelLabels( wxMessageDialog::ButtonLabel( _( "Remove White Space" ) ),
|
||||
wxMessageDialog::ButtonLabel( _( "Keep White Space" ) ) );
|
||||
|
||||
if( dlg.ShowModal() == wxID_OK )
|
||||
field.m_Name = trimmedName;
|
||||
}
|
||||
|
||||
m_templateMgr->AddTemplateFieldName( field, m_global );
|
||||
}
|
||||
}
|
||||
|
||||
if( m_global )
|
||||
|
@ -544,6 +544,13 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
|
||||
SCH_COMMIT dummy( this );
|
||||
|
||||
RecalculateConnections( &dummy, GLOBAL_CLEANUP );
|
||||
|
||||
if( schematic.HasSymbolFieldNamesWithWhiteSpace() )
|
||||
{
|
||||
m_infoBar->QueueShowMessage( _( "This schematic contains symbols that have leading "
|
||||
"and/or trailing white space field names." ),
|
||||
wxICON_WARNING );
|
||||
}
|
||||
}
|
||||
|
||||
// Load any exclusions from the project file
|
||||
|
@ -1669,6 +1669,31 @@ void SCH_SCREEN::PruneOrphanedSheetInstances( const wxString& aProjectName,
|
||||
}
|
||||
|
||||
|
||||
bool SCH_SCREEN::HasSymbolFieldNamesWithWhiteSpace() const
|
||||
{
|
||||
wxString trimmedFieldName;
|
||||
|
||||
for( const SCH_ITEM* item : Items().OfType( SCH_SYMBOL_T ) )
|
||||
{
|
||||
const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( item );
|
||||
|
||||
wxCHECK2( symbol, continue );
|
||||
|
||||
for( const SCH_FIELD& field : symbol->GetFields() )
|
||||
{
|
||||
trimmedFieldName = field.GetName();
|
||||
trimmedFieldName.Trim();
|
||||
trimmedFieldName.Trim( false );
|
||||
|
||||
if( field.GetName() != trimmedFieldName )
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#if defined(DEBUG)
|
||||
void SCH_SCREEN::Show( int nestLevel, std::ostream& os ) const
|
||||
{
|
||||
@ -2087,3 +2112,15 @@ void SCH_SCREENS::PruneOrphanedSheetInstances( const wxString& aProjectName,
|
||||
for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
|
||||
screen->PruneOrphanedSheetInstances( aProjectName, aValidSheetPaths );
|
||||
}
|
||||
|
||||
|
||||
bool SCH_SCREENS::HasSymbolFieldNamesWithWhiteSpace() const
|
||||
{
|
||||
for( const SCH_SCREEN* screen : m_screens )
|
||||
{
|
||||
if( screen->HasSymbolFieldNamesWithWhiteSpace() )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -548,6 +548,8 @@ public:
|
||||
*/
|
||||
bool AllSymbolDefaultInstancesNotSet();
|
||||
|
||||
bool HasSymbolFieldNamesWithWhiteSpace() const;
|
||||
|
||||
#if defined(DEBUG)
|
||||
void Show( int nestLevel, std::ostream& os ) const override;
|
||||
#endif
|
||||
@ -835,6 +837,8 @@ public:
|
||||
void PruneOrphanedSheetInstances( const wxString& aProjectName,
|
||||
const SCH_SHEET_LIST& aValidSheetPaths );
|
||||
|
||||
bool HasSymbolFieldNamesWithWhiteSpace() const;
|
||||
|
||||
private:
|
||||
void addScreenToList( SCH_SCREEN* aScreen, SCH_SHEET* aSheet );
|
||||
void buildScreenList( SCH_SHEET* aSheet);
|
||||
|
Loading…
Reference in New Issue
Block a user