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 )
{
m_titleBlock->TextVarResolver( token, m_project );
// no need for tokenUpdated; TextVarResolver() did a full resolve
return true;
return m_titleBlock->TextVarResolver( token, m_project );
}
if( tokenUpdated )

View File

@ -94,13 +94,8 @@ bool TITLE_BLOCK::TextVarResolver( wxString* aToken, const PROJECT* aProject ) c
if( aToken->IsSameAs( wxT( "ISSUE_DATE" ) ) )
{
wxString ret = GetDate();
if( !ret.empty() )
{
*aToken = ret;
tokenUpdated = true;
}
*aToken = GetDate();
tokenUpdated = true;
}
else if( aToken->IsSameAs( wxT( "CURRENT_DATE" ) ) )
{
@ -116,33 +111,18 @@ bool TITLE_BLOCK::TextVarResolver( wxString* aToken, const PROJECT* aProject ) c
}
else if( aToken->IsSameAs( wxT( "REVISION" ) ) )
{
wxString ret = GetRevision();
if( !ret.empty() )
{
*aToken = ret;
tokenUpdated = true;
}
*aToken = GetRevision();
tokenUpdated = true;
}
else if( aToken->IsSameAs( wxT( "TITLE" ) ) )
{
wxString ret = GetTitle();
if( !ret.empty() )
{
*aToken = ret;
tokenUpdated = true;
}
*aToken = GetTitle();
tokenUpdated = true;
}
else if( aToken->IsSameAs( wxT( "COMPANY" ) ) )
{
wxString ret = GetCompany();
if( !ret.empty() )
{
*aToken = ret;
tokenUpdated = true;
}
*aToken = GetCompany();
tokenUpdated = true;
}
else if( aToken->Left( aToken->Len() - 1 ).IsSameAs( wxT( "COMMENT" ) ) )
{
@ -159,13 +139,8 @@ bool TITLE_BLOCK::TextVarResolver( wxString* aToken, const PROJECT* aProject ) c
case '7':
case '8':
case '9':
wxString ret = GetComment( c - '1' );
if( !ret.empty() )
{
*aToken = ret;
tokenUpdated = true;
}
*aToken = GetComment( c - '1' );
tokenUpdated = true;
}
}

View File

@ -1246,7 +1246,15 @@ wxString DIALOG_PLOT_SCHEMATIC::getOutputPath()
wxStandardPaths::Get().GetDocumentsDir() );
// 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 );

View File

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