diff --git a/common/common.cpp b/common/common.cpp index 0ec528cbcc..c547b60f39 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include @@ -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 ) diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index 77322d4854..4d42c1f655 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -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 ) diff --git a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp index 8c67d1ae0e..b0849c3f9e 100644 --- a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp +++ b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp @@ -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 ) diff --git a/eeschema/schedit.cpp b/eeschema/schedit.cpp index bc3525bdf6..af8c2e49c2 100644 --- a/eeschema/schedit.cpp +++ b/eeschema/schedit.cpp @@ -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( item )-> - GetField( DATASHEET )->GetFullyQualifiedText(); + wxString text = static_cast( item )->GetField( DATASHEET )->GetText(); + text = ResolveUriByEnvVars( text ); if( !text.IsEmpty() ) GetAssociatedDocument( this, text ); diff --git a/include/common.h b/include/common.h index 2f821ee538..9ec3a091d1 100644 --- a/include/common.h +++ b/include/common.h @@ -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__ /**