From 888f670004dc2fd8ae7ed85e57254494f3f6ee73 Mon Sep 17 00:00:00 2001
From: Cheng Sheng <chengsheng@google.com>
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 ++
 eeschema/dialogs/dialog_edit_component_in_schematic.cpp | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/AUTHORS.txt b/AUTHORS.txt
index f447c6de0..644540d7d 100644
--- a/AUTHORS.txt
+++ b/AUTHORS.txt
@@ -38,6 +38,8 @@ Chris Pavlina <pavlina.chris[at]gmail-dot-com>
 Simon Richter <Simon.Richter[at]hogyros-dot-de>
 Mario Luzeiro <mrluzeiro[at]ua-dot-pt>
 Mateusz Skowroński <skowri[at]gmail-dot-com>
+Cheng Sheng <chengsheng[at]google-dot-com>
+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 c66edd6a6..b0b889f5a 100644
--- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp
+++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp
@@ -27,6 +27,7 @@
 
 #include <wx/tooltip.h>
 #include <wx/hyperlink.h>
+#include <wx/url.h>
 
 #include <fctsys.h>
 #include <pgm_base.h>
@@ -51,6 +52,8 @@
 #include <netlist_exporter_pspice.h>
 #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 )
-- 
2.11.0 (Apple Git-81)

