From 3e61a32fbe34029cf23c67adb64bea9d5790b7bf Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 15 Sep 2018 01:37:40 +0100 Subject: [PATCH] Attempt to use envVars when adding new libraries. Fixes: lp:1785441 * https://bugs.launchpad.net/kicad/+bug/1785441 --- eeschema/lib_manager.cpp | 11 +++++++++-- pcbnew/footprint_libraries_utils.cpp | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/eeschema/lib_manager.cpp b/eeschema/lib_manager.cpp index 2545947d25..f09024b2cd 100644 --- a/eeschema/lib_manager.cpp +++ b/eeschema/lib_manager.cpp @@ -27,7 +27,8 @@ #include #include #include - +#include +#include #include #include #include @@ -622,7 +623,13 @@ bool LIB_MANAGER::addLibrary( const wxString& aFilePath, bool aCreate, SYMBOL_LI wxString libName = getLibraryName( aFilePath ); wxCHECK( !LibraryExists( libName ), false ); // either create or add an existing one - SYMBOL_LIB_TABLE_ROW* libRow = new SYMBOL_LIB_TABLE_ROW( libName, aFilePath, + // try to use path normalized to an environmental variable or project path + wxString relPath = NormalizePath( aFilePath, &Pgm().GetLocalEnvVariables(), &m_frame.Prj() ); + + if( relPath.IsEmpty() ) + relPath = aFilePath; + + SYMBOL_LIB_TABLE_ROW* libRow = new SYMBOL_LIB_TABLE_ROW( libName, relPath, SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_LEGACY ) ); aTable->InsertRow( libRow ); diff --git a/pcbnew/footprint_libraries_utils.cpp b/pcbnew/footprint_libraries_utils.cpp index 7d96e5bf30..706ba5512b 100644 --- a/pcbnew/footprint_libraries_utils.cpp +++ b/pcbnew/footprint_libraries_utils.cpp @@ -53,6 +53,7 @@ #include #include #include +#include // unique, "file local" translations: @@ -500,15 +501,21 @@ wxString PCB_BASE_EDIT_FRAME::CreateNewLibrary(const wxString& aLibName ) pi->FootprintLibCreate( libPath ); + // try to use path normalized to an environmental variable or project path + wxString path = NormalizePath( libPath, &Pgm().GetLocalEnvVariables(), &Prj() ); + + if( path.IsEmpty() ) + path = libPath; + if( saveInGlobalTable ) { - auto row = new FP_LIB_TABLE_ROW( fn.GetName(), libPath, wxT( "KiCad" ), wxEmptyString ); + auto row = new FP_LIB_TABLE_ROW( fn.GetName(), path, wxT( "KiCad" ), wxEmptyString ); GFootprintTable.InsertRow( row ); GFootprintTable.Save( FP_LIB_TABLE::GetGlobalTableFileName() ); } else if( saveInProjectTable ) { - auto row = new FP_LIB_TABLE_ROW( fn.GetName(), libPath, wxT( "KiCad" ), wxEmptyString ); + auto row = new FP_LIB_TABLE_ROW( fn.GetName(), path, wxT( "KiCad" ), wxEmptyString ); Prj().PcbFootprintLibs()->InsertRow( row ); Prj().PcbFootprintLibs()->Save( Prj().FootprintLibTblName() ); }