Improve directory handling for Project Save As.

1) don't change directory names that we don't recognize
2) when we do, make sure the child files get copied to the
changed name.

Fixes https://gitlab.com/kicad/code/kicad/issues/3834
This commit is contained in:
Jeff Young 2020-02-02 23:00:54 +00:00
parent b56998925b
commit a04fdf64da
7 changed files with 48 additions and 25 deletions

View File

@ -138,14 +138,13 @@ const std::string DrillFileExtension( "drl" );
const std::string SVGFileExtension( "svg" );
const std::string ReportFileExtension( "rpt" );
const std::string FootprintPlaceFileExtension( "pos" );
const std::string KiCadLib3DShapesPathExtension( "3dshapes" ); ///< 3D shapes default libpath
const std::string KiCadFootprintLibPathExtension( "pretty" ); ///< KICAD PLUGIN libpath
const std::string LegacyFootprintLibPathExtension( "mod" );
const std::string EagleFootprintLibPathExtension( "lbr" );
const std::string KiCadFootprintLibPathExtension( "pretty" ); // this is a directory
const std::string LegacyFootprintLibPathExtension( "mod" ); // this is a file
const std::string EagleFootprintLibPathExtension( "lbr" ); // this is a file
const std::string GedaPcbFootprintLibFileExtension( "fp" ); // this is a file
const std::string KiCadFootprintFileExtension( "kicad_mod" );
const std::string GedaPcbFootprintLibFileExtension( "fp" );
const std::string SpecctraDsnFileExtension( "dsn" );
const std::string IpcD356FileExtension( "d356" );

View File

@ -314,14 +314,23 @@ void IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aProje
const wxString& aSrcFilePath, wxString& aErrors )
{
wxFileName destFile( aSrcFilePath );
wxString destPath = destFile.GetPath();
wxString destPath = destFile.GetPathWithSep();
wxUniChar pathSep = wxFileName::GetPathSeparator();
wxString ext = destFile.GetExt();
if( destPath.StartsWith( aProjectBasePath ) )
{
if( destPath.StartsWith( aProjectBasePath + pathSep ) )
destPath.Replace( aProjectBasePath, aNewProjectBasePath, false );
destFile.SetPath( destPath );
}
#if 0
// WAYNE STAMBAUGH TODO:
// If we end up with a symbol equivalent to ".pretty" we'll want to handle it here....
wxString srcProjectSymbolLib = pathSep + aProjectName + ".sym_lib_dir_extension" + pathSep;
wxString newProjectSymbolLib = pathSep + aNewProjectName + ".sym_lib_dir_extension" + pathSep;
destPath.Replace( srcProjectSymbolLib, newProjectSymbolLib, true );
#endif
destFile.SetPath( destPath );
if( ext == "sch" || ext == "sch-bak" )
{

View File

@ -149,10 +149,11 @@ void IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aProje
const wxString& aSrcFilePath, wxString& aErrors )
{
wxFileName destFile( aSrcFilePath );
wxString destPath = destFile.GetPath();
wxString destPath = destFile.GetPathWithSep();
wxUniChar pathSep = wxFileName::GetPathSeparator();
wxString ext = destFile.GetExt();
if( destPath.StartsWith( aProjectBasePath ) )
if( destPath.StartsWith( aProjectBasePath + pathSep ) )
{
destPath.Replace( aProjectBasePath, aNewProjectBasePath, false );
destFile.SetPath( destPath );

View File

@ -141,7 +141,6 @@ extern const std::string GedaPcbFootprintLibFileExtension;
extern const std::string EagleFootprintLibPathExtension;
extern const std::string ComponentFileExtension;
extern const std::string PageLayoutDescrFileExtension;
extern const std::string KiCadLib3DShapesPathExtension;
extern const std::string SpecctraDsnFileExtension;
extern const std::string IpcD356FileExtension;

View File

@ -437,7 +437,6 @@ public:
KiCadFootprintLibPathExtension;
GedaPcbFootprintLibFileExtension;
EagleFootprintLibPathExtension;
KiCadLib3DShapesPathExtension;
SpecctraDsnFileExtension;
IpcD356FileExtension;
*/
@ -448,16 +447,26 @@ public:
virtual wxDirTraverseResult OnDir( const wxString& dirPath ) override
{
wxFileName destDir( dirPath );
wxString destDirPath = destDir.GetPath(); // strips off last directory
wxString destDirPath = destDir.GetPathWithSep();
wxUniChar pathSep = wxFileName::GetPathSeparator();
if( destDirPath.StartsWith( m_projectDirPath ) )
if( destDirPath.StartsWith( m_projectDirPath + pathSep ) )
{
destDirPath.Replace( m_projectDirPath, m_newProjectDirPath, false );
destDir.SetPath( destDirPath );
}
if( destDir.GetName() == m_projectName )
destDir.SetName( m_newProjectName );
{
if( destDir.GetExt() == "pretty" )
destDir.SetName( m_newProjectName );
#if 0
// WAYNE STAMBAUGH TODO:
// If we end up with a symbol equivalent to ".pretty" we'll want to handle it here....
else if( destDir.GetExt() == "sym_lib_dir_extension" )
destDir.SetName( m_newProjectName );
#endif
}
if( !wxMkdir( destDir.GetFullPath() ) )
{
@ -466,7 +475,7 @@ public:
if( !m_errors.empty() )
m_errors += "\n";
msg.Printf( _( "Cannot copy file \"%s\"." ), destDir.GetFullPath() );
msg.Printf( _( "Cannot copy folder \"%s\"." ), destDir.GetFullPath() );
m_errors += msg;
}

View File

@ -141,10 +141,11 @@ void IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcPr
const wxString& aSrcFilePath, wxString& aErrors )
{
wxFileName destFile( aSrcFilePath );
wxString destPath = destFile.GetPath();
wxString destPath = destFile.GetPathWithSep();
wxUniChar pathSep = wxFileName::GetPathSeparator();
wxString ext = destFile.GetExt();
if( destPath.StartsWith( aProjectBasePath ) )
if( destPath.StartsWith( aProjectBasePath + pathSep ) )
{
destPath.Replace( aProjectBasePath, aNewProjectBasePath, false );
destFile.SetPath( destPath );

View File

@ -384,14 +384,19 @@ void IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcPr
const wxString& aSrcFilePath, wxString& aErrors )
{
wxFileName destFile( aSrcFilePath );
wxString destPath = destFile.GetPath();
wxString destPath = destFile.GetPathWithSep();
wxUniChar pathSep = wxFileName::GetPathSeparator();
wxString ext = destFile.GetExt();
if( destPath.StartsWith( aProjectBasePath ) )
{
if( destPath.StartsWith( aProjectBasePath + pathSep ) )
destPath.Replace( aProjectBasePath, aNewProjectBasePath, false );
destFile.SetPath( destPath );
}
wxString srcProjectFootprintLib = pathSep + aSrcProjectName + ".pretty" + pathSep;
wxString newProjectFootprintLib = pathSep + aNewProjectName + ".pretty" + pathSep;
destPath.Replace( srcProjectFootprintLib, newProjectFootprintLib, true );
destFile.SetPath( destPath );
if( ext == "kicad_pcb" || ext == "kicad_pcb-bak" )
{