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

(cherry picked from commit 9bfce26ce7)
This commit is contained in:
Seth Hillbrand 2019-03-10 08:34:05 -07:00
parent 73664e610b
commit de22148b44
7 changed files with 16 additions and 22 deletions

View File

@ -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 ../<filename>
*/
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;
}

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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();

View File

@ -1033,7 +1033,6 @@ void SCH_EDIT_FRAME::OnEditItem( wxCommandEvent& aEvent )
case ID_POPUP_SCH_DISPLAYDOC_CMP:
{
wxString text = static_cast<SCH_COMPONENT*>( item )->GetField( DATASHEET )->GetText();
text = ResolveUriByEnvVars( text );
if( !text.IsEmpty() )
GetAssociatedDocument( this, text );

View File

@ -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