Resolve env vars when looking up documentation files.

Fixes: lp:1729276
* https://bugs.launchpad.net/kicad/+bug/1729276
This commit is contained in:
Jeff Young 2018-03-08 22:57:31 +00:00
parent e4b847b345
commit 4693fd6200
5 changed files with 26 additions and 15 deletions

View File

@ -39,6 +39,7 @@
#include <wx/config.h>
#include <wx/utils.h>
#include <wx/stdpaths.h>
#include <wx/url.h>
#include <pgm_base.h>
@ -264,6 +265,20 @@ const wxString ExpandEnvVarSubstitutions( const wxString& aString )
return wxExpandEnvVars( aString );
}
const wxString ResolveUriByEnvVars( const wxString& aUri )
{
// URL-like URI: return as is.
wxURL url( aUri );
if( url.GetError() == wxURL_NOERR )
return aUri;
// Otherwise, the path points to a local file. Resolve environment
// variables if any.
return ExpandEnvVarSubstitutions( aUri );
}
bool EnsureFileDirectoryExists( wxFileName* aTargetFullFileName,
const wxString& aBaseFilename,
REPORTER* aReporter )

View File

@ -599,18 +599,6 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::deleteFieldButtonHandler( wxCommandEven
m_skipCopyFromPanel = false;
}
static wxString resolveUriByEnvVars( const wxString& aUri )
{
// URL-like URI: return as is.
wxURL url( aUri );
if( url.GetError() == wxURL_NOERR )
{
return aUri;
}
// Otherwise, the path points to a local file. Resolve environment
// variables if any.
return ExpandEnvVarSubstitutions( aUri );
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::showButtonHandler( wxCommandEvent& event )
{
@ -619,7 +607,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::showButtonHandler( wxCommandEvent& even
if( fieldNdx == DATASHEET )
{
wxString datasheet_uri = fieldValueTextCtrl->GetValue();
datasheet_uri = resolveUriByEnvVars( datasheet_uri );
datasheet_uri = ResolveUriByEnvVars( datasheet_uri );
GetAssociatedDocument( this, datasheet_uri );
}
else if( fieldNdx == FOOTPRINT )

View File

@ -502,6 +502,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::showButtonHandler( wxCommandEvent& even
if( fieldNdx == DATASHEET )
{
wxString datasheet_uri = fieldValueTextCtrl->GetValue();
datasheet_uri = ResolveUriByEnvVars( datasheet_uri );
GetAssociatedDocument( this, datasheet_uri );
}
else if( fieldNdx == FOOTPRINT )

View File

@ -285,8 +285,8 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
// Ensure the struct is a component (could be a piece of a component, like Field, text..)
if( item && item->Type() == SCH_COMPONENT_T )
{
wxString text = static_cast<SCH_COMPONENT*>( item )->
GetField( DATASHEET )->GetFullyQualifiedText();
wxString text = static_cast<SCH_COMPONENT*>( item )->GetField( DATASHEET )->GetText();
text = ResolveUriByEnvVars( text );
if( !text.IsEmpty() )
GetAssociatedDocument( this, text );

View File

@ -316,6 +316,13 @@ wxString GetKicadConfigPath();
*/
const wxString ExpandEnvVarSubstitutions( const wxString& aString );
/**
* Function ResolveUriByEnvVars
* replaces any environment variables in file-path uris (leaving network-path
* uris alone).
*/
const wxString ResolveUriByEnvVars( const wxString& aUri );
#ifdef __WXMAC__
/**