Consistently handle env/prj variables

User-defined variables cannot be used for internally-reserved variables

Fixes https://gitlab.com/kicad/code/kicad/issues/11232

(cherry picked from commit c23679d9bd)
This commit is contained in:
Seth Hillbrand 2022-03-31 17:04:08 -07:00
parent 6b99a937d8
commit 49c48e2fe0
4 changed files with 21 additions and 39 deletions

View File

@ -160,9 +160,8 @@ wxString DS_DRAW_ITEM_LIST::BuildFullText( const wxString& aTextbase )
} }
else if( m_titleBlock ) else if( m_titleBlock )
{ {
m_titleBlock->TextVarResolver( token, m_project );
// no need for tokenUpdated; TextVarResolver() did a full resolve // no need for tokenUpdated; TextVarResolver() did a full resolve
return true; return m_titleBlock->TextVarResolver( token, m_project );
} }
if( tokenUpdated ) if( tokenUpdated )

View File

@ -94,14 +94,9 @@ bool TITLE_BLOCK::TextVarResolver( wxString* aToken, const PROJECT* aProject ) c
if( aToken->IsSameAs( wxT( "ISSUE_DATE" ) ) ) if( aToken->IsSameAs( wxT( "ISSUE_DATE" ) ) )
{ {
wxString ret = GetDate(); *aToken = GetDate();
if( !ret.empty() )
{
*aToken = ret;
tokenUpdated = true; tokenUpdated = true;
} }
}
else if( aToken->IsSameAs( wxT( "CURRENT_DATE" ) ) ) else if( aToken->IsSameAs( wxT( "CURRENT_DATE" ) ) )
{ {
// We can choose different formats. Should probably be kept in sync with ISSUE_DATE // We can choose different formats. Should probably be kept in sync with ISSUE_DATE
@ -116,34 +111,19 @@ bool TITLE_BLOCK::TextVarResolver( wxString* aToken, const PROJECT* aProject ) c
} }
else if( aToken->IsSameAs( wxT( "REVISION" ) ) ) else if( aToken->IsSameAs( wxT( "REVISION" ) ) )
{ {
wxString ret = GetRevision(); *aToken = GetRevision();
if( !ret.empty() )
{
*aToken = ret;
tokenUpdated = true; tokenUpdated = true;
} }
}
else if( aToken->IsSameAs( wxT( "TITLE" ) ) ) else if( aToken->IsSameAs( wxT( "TITLE" ) ) )
{ {
wxString ret = GetTitle(); *aToken = GetTitle();
if( !ret.empty() )
{
*aToken = ret;
tokenUpdated = true; tokenUpdated = true;
} }
}
else if( aToken->IsSameAs( wxT( "COMPANY" ) ) ) else if( aToken->IsSameAs( wxT( "COMPANY" ) ) )
{ {
wxString ret = GetCompany(); *aToken = GetCompany();
if( !ret.empty() )
{
*aToken = ret;
tokenUpdated = true; tokenUpdated = true;
} }
}
else if( aToken->Left( aToken->Len() - 1 ).IsSameAs( wxT( "COMMENT" ) ) ) else if( aToken->Left( aToken->Len() - 1 ).IsSameAs( wxT( "COMMENT" ) ) )
{ {
wxChar c = aToken->Last(); wxChar c = aToken->Last();
@ -159,15 +139,10 @@ bool TITLE_BLOCK::TextVarResolver( wxString* aToken, const PROJECT* aProject ) c
case '7': case '7':
case '8': case '8':
case '9': case '9':
wxString ret = GetComment( c - '1' ); *aToken = GetComment( c - '1' );
if( !ret.empty() )
{
*aToken = ret;
tokenUpdated = true; tokenUpdated = true;
} }
} }
}
if( tokenUpdated ) if( tokenUpdated )
{ {

View File

@ -1246,7 +1246,15 @@ wxString DIALOG_PLOT_SCHEMATIC::getOutputPath()
wxStandardPaths::Get().GetDocumentsDir() ); wxStandardPaths::Get().GetDocumentsDir() );
// Build the absolute path of current output directory to preselect it in the file browser. // Build the absolute path of current output directory to preselect it in the file browser.
wxString path = ExpandEnvVarSubstitutions( m_outputDirectoryName->GetValue(), &Prj() ); std::function<bool( wxString* )> textResolver =
[&]( wxString* token ) -> bool
{
return m_parent->Schematic().ResolveTextVar( token, 0 );
};
wxString path = m_outputDirectoryName->GetValue();
path = ExpandTextVars( path, &textResolver, nullptr, &Prj() );
path = ExpandEnvVarSubstitutions( path, &Prj() );
fn.SetPath( path ); fn.SetPath( path );

View File

@ -806,7 +806,7 @@ void DIALOG_PLOT::Plot( wxCommandEvent& event )
wxString path = m_plotOpts.GetOutputDirectory(); wxString path = m_plotOpts.GetOutputDirectory();
path = ExpandTextVars( path, &textResolver, nullptr, board->GetProject() ); path = ExpandTextVars( path, &textResolver, nullptr, board->GetProject() );
path = ExpandEnvVarSubstitutions( path, nullptr ); path = ExpandEnvVarSubstitutions( path, board->GetProject() );
wxFileName outputDir = wxFileName::DirName( path ); wxFileName outputDir = wxFileName::DirName( path );
wxString boardFilename = m_parent->GetBoard()->GetFileName(); wxString boardFilename = m_parent->GetBoard()->GetFileName();