diff --git a/eeschema/dialogs/dialog_eeschema_config.cpp b/eeschema/dialogs/dialog_eeschema_config.cpp index aea90816bf..b0f458dcab 100644 --- a/eeschema/dialogs/dialog_eeschema_config.cpp +++ b/eeschema/dialogs/dialog_eeschema_config.cpp @@ -314,6 +314,15 @@ void DIALOG_EESCHEMA_CONFIG::OnAddOrInsertLibClick( wxCommandEvent& event ) wxFileName fn; + // Build libs paths, to find later a relative path: + wxArrayString paths; + + for( unsigned ll=0; ll < m_DefaultLibraryPathslistBox->GetCount(); ++ll ) + paths.Add( m_DefaultLibraryPathslistBox->GetString( ll ) ); + + for( unsigned ll=0; ll < m_listUserPaths->GetCount(); ++ll ) + paths.Add( m_listUserPaths->GetString( ll ) ); + for( unsigned jj = 0; jj < filenames.GetCount(); jj++ ) { fn = filenames[jj]; @@ -321,10 +330,23 @@ void DIALOG_EESCHEMA_CONFIG::OnAddOrInsertLibClick( wxCommandEvent& event ) if( jj == 0 ) prj.SetRString( PROJECT::SCH_LIB_PATH, fn.GetPath() ); - // Remove extension: + // Extension is not stored, so remove extension: fn.SetExt( wxEmptyString ); - libfilename = fn.GetName(); + // Try to use relative path: + for( unsigned ll = 0; ll < paths.GetCount(); ll++ ) + { + wxFileName relfn = fn; + relfn.MakeRelativeTo( paths[ll] ); + + if( relfn.GetPath()[0] != '.' ) + { + fn = relfn; + break; + } + } + + libfilename = fn.GetFullPath(); // Add or insert new library name, if not already in list if( m_ListLibr->FindString( libfilename, fn.IsCaseSensitive() ) == wxNOT_FOUND ) diff --git a/kicad/project_template.cpp b/kicad/project_template.cpp index 675efe0bdc..b4f088cf9d 100644 --- a/kicad/project_template.cpp +++ b/kicad/project_template.cpp @@ -121,17 +121,32 @@ wxBitmap* PROJECT_TEMPLATE::GetIcon() bool PROJECT_TEMPLATE::CreateProject( wxFileName& aNewProjectPath ) { + // CreateProject copy the files from template to the new project folder + // and rename files which have the same name as the template .pro file bool result = true; std::vector srcFiles = GetFileList(); + // Find the template file name base. this is the name of the .pro templte file + wxString basename; + for( size_t i=0; i < srcFiles.size(); i++ ) + { + if( srcFiles[i].GetExt() == wxT( "pro" ) ) + { + basename = srcFiles[i].GetName(); + break; + } + } + for( size_t i=0; i < srcFiles.size(); i++ ) { // Replace the template path wxFileName destination = srcFiles[i]; // Replace the template filename with the project filename for the new project creation - destination.SetName( aNewProjectPath.GetName() ); + wxString currname = destination.GetName(); + currname.Replace( basename, aNewProjectPath.GetName() ); + destination.SetName( currname ); // Replace the template path with the project path for the new project creation // but keep the sub directory name, if exists