Use canonical names when saving sheet name and filename fields

This commit is contained in:
Roberto Fernandez Bautista 2021-11-27 20:28:35 +00:00
parent a746d31038
commit 3660597082
3 changed files with 20 additions and 6 deletions

View File

@ -1151,7 +1151,7 @@ void SCH_SEXPR_PLUGIN::saveField( SCH_FIELD* aField, int aNestLevel )
else if( aField->GetParent()->Type() == SCH_SHEET_T ) else if( aField->GetParent()->Type() == SCH_SHEET_T )
{ {
if( aField->GetId() >= 0 && aField->GetId() < SHEET_MANDATORY_FIELDS ) if( aField->GetId() >= 0 && aField->GetId() < SHEET_MANDATORY_FIELDS )
fieldName = SCH_SHEET::GetDefaultFieldName( aField->GetId() ); fieldName = SCH_SHEET::GetDefaultFieldName( aField->GetId(), false );
} }
if( aField->GetId() == -1 /* undefined ID */ ) if( aField->GetId() == -1 /* undefined ID */ )

View File

@ -42,21 +42,35 @@
#include <pgm_base.h> #include <pgm_base.h>
#include <wx/log.h> #include <wx/log.h>
#define SHEET_NAME_CANONICAL "Sheet name"
#define SHEET_FILE_CANONICAL "Sheet file"
#define USER_FIELD_CANONICAL "Field%d"
const wxString SCH_SHEET::GetDefaultFieldName( int aFieldNdx )
const wxString SCH_SHEET::GetDefaultFieldName( int aFieldNdx, bool aTranslated )
{ {
static void* locale = nullptr; static void* locale = nullptr;
static wxString sheetnameDefault; static wxString sheetnameDefault;
static wxString sheetfilenameDefault; static wxString sheetfilenameDefault;
static wxString userFieldDefault; static wxString userFieldDefault;
if( !aTranslated )
{
switch( aFieldNdx )
{
case SHEETNAME: return SHEET_NAME_CANONICAL;
case SHEETFILENAME: return SHEET_FILE_CANONICAL;
default: return wxString::Format( USER_FIELD_CANONICAL, aFieldNdx );
}
}
// Fetching translations can take a surprising amount of time when loading libraries, // Fetching translations can take a surprising amount of time when loading libraries,
// so only do it when necessary. // so only do it when necessary.
if( Pgm().GetLocale() != locale ) if( Pgm().GetLocale() != locale )
{ {
sheetnameDefault = _( "Sheet name" ); sheetnameDefault = _( SHEET_NAME_CANONICAL );
sheetfilenameDefault = _( "Sheet file" ); sheetfilenameDefault = _( SHEET_FILE_CANONICAL );
userFieldDefault = _( "Field%d" ); userFieldDefault = _( USER_FIELD_CANONICAL );
locale = Pgm().GetLocale(); locale = Pgm().GetLocale();
} }

View File

@ -430,7 +430,7 @@ public:
void Show( int nestLevel, std::ostream& os ) const override; void Show( int nestLevel, std::ostream& os ) const override;
#endif #endif
static const wxString GetDefaultFieldName( int aFieldNdx ); static const wxString GetDefaultFieldName( int aFieldNdx, bool aTranslated = true );
protected: protected:
/** /**