From 521e18ddbd876cae3c5a0ea60be9468329b97bb1 Mon Sep 17 00:00:00 2001 From: Cheng Sheng Date: Wed, 31 May 2017 23:34:31 +0200 Subject: [PATCH] "Show Datasheet" button: Resolve env-vars (like ${KIPRJMOD}) if appears. This way, the datasheets can be stored within the project dir, and referred as ${KIPRJMOD}/relative/path/to/datasheet. --- AUTHORS.txt | 2 ++ .../dialog_edit_component_in_schematic.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/AUTHORS.txt b/AUTHORS.txt index f447c6de09..644540d7db 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -38,6 +38,8 @@ Chris Pavlina Simon Richter Mario Luzeiro Mateusz SkowroĊ„ski +Cheng Sheng +Google Inc. See also CHANGELOG.txt for contributors. diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index c66edd6a67..b9fca23309 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -51,6 +52,8 @@ #include #endif /* KICAD_SPICE */ +#include "common.h" + /** * class DIALOG_EDIT_COMPONENT_IN_SCHEMATIC @@ -554,6 +557,18 @@ 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 ) { @@ -562,6 +577,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::showButtonHandler( wxCommandEvent& even if( fieldNdx == DATASHEET ) { wxString datasheet_uri = fieldValueTextCtrl->GetValue(); + datasheet_uri = resolveUriByEnvVars( datasheet_uri ); ::wxLaunchDefaultBrowser( datasheet_uri ); } else if( fieldNdx == FOOTPRINT )