From a55d9819bc67fc08320065b3765bdfb4306f36c1 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Sat, 26 Jan 2019 16:19:02 -0500 Subject: [PATCH] Do not use project path when searching for default library tables. When no default library tables are found, set the default wxFilePickerCtrl to the users configuration path instead of the current project path to prevent any project library tables from being used as the default. Fixes lp:1809769 https://bugs.launchpad.net/kicad/+bug/1809769 --- .../dialog_global_lib_table_config.cpp | 24 ++++++++++++++++--- common/fp_lib_table.cpp | 19 ++++++++++++--- eeschema/symbol_lib_table.cpp | 20 ++++++++++++---- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/common/dialogs/dialog_global_lib_table_config.cpp b/common/dialogs/dialog_global_lib_table_config.cpp index 29428e255c..d6b60c503b 100644 --- a/common/dialogs/dialog_global_lib_table_config.cpp +++ b/common/dialogs/dialog_global_lib_table_config.cpp @@ -20,7 +20,11 @@ #include "dialog_global_lib_table_config.h" -#include +#include +#include +#include + +#include DIALOG_GLOBAL_LIB_TABLE_CONFIG::DIALOG_GLOBAL_LIB_TABLE_CONFIG( wxWindow* aParent, @@ -98,14 +102,28 @@ bool DIALOG_GLOBAL_LIB_TABLE_CONFIG::TransferDataToWindow() wxFileName fn = GetGlobalTableFileName(); + SEARCH_STACK ss; + + SystemDirsAppend( &ss ); + + wxString templatePath = + Pgm().GetLocalEnvVariables().at( wxT( "KICAD_TEMPLATE_DIR" ) ).GetValue(); + + if( !templatePath.IsEmpty() ) + ss.AddPaths( templatePath, 0 ); + else + templatePath = wxStandardPaths::Get().GetUserConfigDir(); + + m_filePicker1->SetInitialDirectory( templatePath ); + // Attempt to find the default global file table from the KiCad template folder. - wxString fileName = Kiface().KifaceSearch().FindValidPath( fn.GetName() ); + wxString fileName = ss.FindValidPath( fn.GetName() ); m_defaultFileFound = wxFileName::FileExists( fileName ); if( m_defaultFileFound ) { - m_filePicker1->SetFileName( wxFileName( fileName ) ); + m_filePicker1->SetPath(fileName ); m_filePicker1->Enable( false ); } else diff --git a/common/fp_lib_table.cpp b/common/fp_lib_table.cpp index 7402bd4551..caf21c79be 100644 --- a/common/fp_lib_table.cpp +++ b/common/fp_lib_table.cpp @@ -2,8 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2010-2012 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2012-2016 Wayne Stambaugh - * Copyright (C) 2012-2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2012 Wayne Stambaugh + * Copyright (C) 2012-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 @@ -30,6 +30,9 @@ #include #include #include +#include +#include +#include #include #include @@ -475,7 +478,17 @@ bool FP_LIB_TABLE::LoadGlobalTable( FP_LIB_TABLE& aTable ) // Attempt to copy the default global file table from the KiCad // template folder to the user's home configuration path. - wxString fileName = Kiface().KifaceSearch().FindValidPath( global_tbl_name ); + SEARCH_STACK ss; + + SystemDirsAppend( &ss ); + + wxString templatePath = + Pgm().GetLocalEnvVariables().at( wxT( "KICAD_TEMPLATE_DIR" ) ).GetValue(); + + if( !templatePath.IsEmpty() ) + ss.AddPaths( templatePath, 0 ); + + wxString fileName = ss.FindValidPath( global_tbl_name ); // The fallback is to create an empty global footprint table for the user to populate. if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) ) diff --git a/eeschema/symbol_lib_table.cpp b/eeschema/symbol_lib_table.cpp index 2fa204b9a2..cb94e0b947 100644 --- a/eeschema/symbol_lib_table.cpp +++ b/eeschema/symbol_lib_table.cpp @@ -1,8 +1,8 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2016-2017 Wayne Stambaugh - * Copyright (C) 2016-2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016-2019 Wayne Stambaugh + * Copyright (C) 2016-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 @@ -25,10 +25,12 @@ #include #include -#include #include #include #include +#include +#include +#include #include #include @@ -489,7 +491,17 @@ bool SYMBOL_LIB_TABLE::LoadGlobalTable( SYMBOL_LIB_TABLE& aTable ) // Attempt to copy the default global file table from the KiCad // template folder to the user's home configuration path. - wxString fileName = Kiface().KifaceSearch().FindValidPath( global_tbl_name ); + SEARCH_STACK ss; + + SystemDirsAppend( &ss ); + + wxString templatePath = + Pgm().GetLocalEnvVariables().at( wxT( "KICAD_TEMPLATE_DIR" ) ).GetValue(); + + if( !templatePath.IsEmpty() ) + ss.AddPaths( templatePath, 0 ); + + wxString fileName = ss.FindValidPath( global_tbl_name ); // The fallback is to create an empty global symbol table for the user to populate. if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )