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
This commit is contained in:
Wayne Stambaugh 2019-01-26 16:19:02 -05:00
parent 594d5c3e34
commit a55d9819bc
3 changed files with 53 additions and 10 deletions

View File

@ -20,7 +20,11 @@
#include "dialog_global_lib_table_config.h"
#include <kiface_i.h>
#include <pgm_base.h>
#include <search_stack.h>
#include <systemdirsappend.h>
#include <wx/stdpaths.h>
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

View File

@ -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 <dick@softplc.com>
* Copyright (C) 2012-2016 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2012-2018 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com>
* 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 <footprint_info.h>
#include <lib_id.h>
#include <lib_table_lexer.h>
#include <pgm_base.h>
#include <search_stack.h>
#include <systemdirsappend.h>
#include <fp_lib_table.h>
#include <class_module.h>
@ -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 ) )

View File

@ -1,8 +1,8 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016-2017 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2016-2017 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2016-2019 Wayne Stambaugh <stambaughw@gmail.com>
* 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 <fctsys.h>
#include <common.h>
#include <kiface_i.h>
#include <macros.h>
#include <lib_id.h>
#include <lib_table_lexer.h>
#include <pgm_base.h>
#include <search_stack.h>
#include <systemdirsappend.h>
#include <symbol_lib_table.h>
#include <class_libentry.h>
@ -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 ) )