From 9bfce26ce741eab98ce716956fea801c8eb2fd9a Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sun, 10 Mar 2019 08:34:05 -0700 Subject: [PATCH] Move env var substitution into GetAssociatedDocument We always want the documents to have their variables replaced when opening the associated file. Fixes: lp:1819309 * https://bugs.launchpad.net/kicad/+bug/1819309 --- common/eda_doc.cpp | 23 ++++++++++--------- common/widgets/grid_text_button_helpers.cpp | 5 +--- .../dialogs/dialog_fields_editor_global.cpp | 1 - eeschema/fields_grid_table.cpp | 1 - eeschema/libedit/lib_edit_frame.cpp | 2 -- eeschema/schedit.cpp | 1 - include/eda_doc.h | 5 ++-- 7 files changed, 16 insertions(+), 22 deletions(-) diff --git a/common/eda_doc.cpp b/common/eda_doc.cpp index ddb6ce1e0b..5d073a02de 100644 --- a/common/eda_doc.cpp +++ b/common/eda_doc.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2014-2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2014-2019 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -103,18 +103,19 @@ bool GetAssociatedDocument( wxWindow* aParent, wxT( "file:" ) }; + // Replace before resolving as we might have a URL in a variable + docname = ResolveUriByEnvVars( aDocName ); + for( unsigned ii = 0; ii < arrayDim(url_header); ii++ ) { - if( aDocName.First( url_header[ii] ) == 0 ) // looks like an internet url + if( docname.First( url_header[ii] ) == 0 ) // looks like an internet url { - wxURI uri( aDocName ); + wxURI uri( docname ); wxLaunchDefaultBrowser( uri.BuildURI() ); return true; } } - docname = aDocName; - #ifdef __WINDOWS__ docname.Replace( UNIX_STRING_DIR_SEP, WIN_STRING_DIR_SEP ); #else @@ -123,17 +124,17 @@ bool GetAssociatedDocument( wxWindow* aParent, /* Compute the full file name */ - if( wxIsAbsolutePath( aDocName ) || aPaths == NULL) - fullfilename = aDocName; + if( wxIsAbsolutePath( docname ) || aPaths == NULL) + fullfilename = docname; /* If the file exists, this is a trivial case: return the filename * "as this". the name can be an absolute path, or a relative path * like ./filename or ../ */ - else if( wxFileName::FileExists( aDocName ) ) - fullfilename = aDocName; + else if( wxFileName::FileExists( docname ) ) + fullfilename = docname; else { - fullfilename = aPaths->FindValidPath( aDocName ); + fullfilename = aPaths->FindValidPath( docname ); } wxString mask( wxT( "*" ) ), extension; @@ -160,7 +161,7 @@ bool GetAssociatedDocument( wxWindow* aParent, if( !wxFileExists( fullfilename ) ) { - msg.Printf( _( "Doc File \"%s\" not found" ), GetChars( aDocName ) ); + msg.Printf( _( "Doc File \"%s\" not found" ), GetChars( docname ) ); DisplayError( aParent, msg ); return false; } diff --git a/common/widgets/grid_text_button_helpers.cpp b/common/widgets/grid_text_button_helpers.cpp index b4ce2f0356..a0ca512ae7 100644 --- a/common/widgets/grid_text_button_helpers.cpp +++ b/common/widgets/grid_text_button_helpers.cpp @@ -279,10 +279,7 @@ protected: wxString filename = GetValue(); if( !filename.IsEmpty() && filename != wxT( "~" ) ) - { - wxString uri = ResolveUriByEnvVars( GetValue() ); - GetAssociatedDocument( m_dlg, uri ); - } + GetAssociatedDocument( m_dlg, GetValue() ); } DIALOG_SHIM* m_dlg; diff --git a/eeschema/dialogs/dialog_fields_editor_global.cpp b/eeschema/dialogs/dialog_fields_editor_global.cpp index 31f537a12a..dd2c9ae73c 100644 --- a/eeschema/dialogs/dialog_fields_editor_global.cpp +++ b/eeschema/dialogs/dialog_fields_editor_global.cpp @@ -95,7 +95,6 @@ protected: else if (event.GetId() == MYID_SHOW_DATASHEET ) { wxString datasheet_uri = m_grid->GetCellValue( m_grid->GetGridCursorRow(), DATASHEET ); - datasheet_uri = ResolveUriByEnvVars( datasheet_uri ); GetAssociatedDocument( m_dlg, datasheet_uri ); } else diff --git a/eeschema/fields_grid_table.cpp b/eeschema/fields_grid_table.cpp index 5e9980fcd6..45b942b534 100644 --- a/eeschema/fields_grid_table.cpp +++ b/eeschema/fields_grid_table.cpp @@ -522,7 +522,6 @@ void FIELDS_GRID_TRICKS::doPopupSelection( wxCommandEvent& event ) else if (event.GetId() == MYID_SHOW_DATASHEET ) { wxString datasheet_uri = m_grid->GetCellValue( DATASHEET, FDC_VALUE ); - datasheet_uri = ResolveUriByEnvVars( datasheet_uri ); GetAssociatedDocument( m_dlg, datasheet_uri ); } else diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp index 8f6de9f9f9..9a81b354e1 100644 --- a/eeschema/libedit/lib_edit_frame.cpp +++ b/eeschema/libedit/lib_edit_frame.cpp @@ -617,8 +617,6 @@ void LIB_EDIT_FRAME::OnViewEntryDoc( wxCommandEvent& event ) else filename = part->GetAlias( 0 )->GetDocFileName(); - filename = ResolveUriByEnvVars( filename ); - if( !filename.IsEmpty() && filename != wxT( "~" ) ) { SEARCH_STACK* lib_search = Prj().SchSearchS(); diff --git a/eeschema/schedit.cpp b/eeschema/schedit.cpp index 0be43ca843..c83b110d8a 100644 --- a/eeschema/schedit.cpp +++ b/eeschema/schedit.cpp @@ -1033,7 +1033,6 @@ void SCH_EDIT_FRAME::OnEditItem( wxCommandEvent& aEvent ) case ID_POPUP_SCH_DISPLAYDOC_CMP: { wxString text = static_cast( item )->GetField( DATASHEET )->GetText(); - text = ResolveUriByEnvVars( text ); if( !text.IsEmpty() ) GetAssociatedDocument( this, text ); diff --git a/include/eda_doc.h b/include/eda_doc.h index 194783e0f8..1c6663814b 100644 --- a/include/eda_doc.h +++ b/include/eda_doc.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2009-2014 Jerry Jacobs - * Copyright (C) 1992-2014 KiCad Developers, see CHANGELOG.TXT for contributors. + * Copyright (C) 1992-2019 KiCad Developers, see CHANGELOG.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -42,7 +42,8 @@ bool KeywordMatch( const wxString& aKeys, const wxString& aDatabase ); /** * Function GetAssociatedDocument - * open a document (file) with the suitable browser + * open a document (file) with the suitable browser. Environmental variables are + * substituted before the document name is resolved for either browser or file * @param aParent = main frame * @param aDocName = filename of file to open (Full filename or short filename) * if \a aDocName begins with http: or ftp: or www. the default internet browser is launched