From a04fdf64daf36037e8ae4232e128f9c6b285b5a1 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 2 Feb 2020 23:00:54 +0000 Subject: [PATCH] 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 --- common/wildcards_and_files_ext.cpp | 9 ++++----- eeschema/eeschema.cpp | 19 ++++++++++++++----- gerbview/gerbview.cpp | 5 +++-- include/wildcards_and_files_ext.h | 1 - kicad/tools/kicad_manager_control.cpp | 19 ++++++++++++++----- pagelayout_editor/pl_editor.cpp | 5 +++-- pcbnew/pcbnew.cpp | 15 ++++++++++----- 7 files changed, 48 insertions(+), 25 deletions(-) diff --git a/common/wildcards_and_files_ext.cpp b/common/wildcards_and_files_ext.cpp index 64529eb83d..8ccd3c9c4a 100644 --- a/common/wildcards_and_files_ext.cpp +++ b/common/wildcards_and_files_ext.cpp @@ -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" ); diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index 6586d9cc52..32529c7560 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -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" ) { diff --git a/gerbview/gerbview.cpp b/gerbview/gerbview.cpp index 90db4413f4..8d8edf82bf 100644 --- a/gerbview/gerbview.cpp +++ b/gerbview/gerbview.cpp @@ -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 ); diff --git a/include/wildcards_and_files_ext.h b/include/wildcards_and_files_ext.h index 9eec406bfe..ac94d8b18c 100644 --- a/include/wildcards_and_files_ext.h +++ b/include/wildcards_and_files_ext.h @@ -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; diff --git a/kicad/tools/kicad_manager_control.cpp b/kicad/tools/kicad_manager_control.cpp index 7ba84684ab..51d1126e6e 100644 --- a/kicad/tools/kicad_manager_control.cpp +++ b/kicad/tools/kicad_manager_control.cpp @@ -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; } diff --git a/pagelayout_editor/pl_editor.cpp b/pagelayout_editor/pl_editor.cpp index 08e4e34fad..d8b900eb89 100644 --- a/pagelayout_editor/pl_editor.cpp +++ b/pagelayout_editor/pl_editor.cpp @@ -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 ); diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index 1fa27df57b..8eee786fa2 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -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" ) {