diff --git a/common/project/project_file.cpp b/common/project/project_file.cpp index bc8caade42..d8080e09a1 100644 --- a/common/project/project_file.cpp +++ b/common/project/project_file.cpp @@ -556,6 +556,15 @@ bool PROJECT_FILE::SaveToFile( const wxString& aDirectory, bool aForce ) } +bool PROJECT_FILE::SaveAs( const wxString& aDirectory, const wxString& aFile ) +{ + Set( "meta.filename", aFile + "." + ProjectFileExtension ); + SetFilename( aFile ); + + return JSON_SETTINGS::SaveToFile( aDirectory, true ); +} + + wxString PROJECT_FILE::getFileExt() const { return ProjectFileExtension; diff --git a/include/project/project_file.h b/include/project/project_file.h index 9f2fc6c9d7..78ed0e584a 100644 --- a/include/project/project_file.h +++ b/include/project/project_file.h @@ -76,6 +76,8 @@ public: bool SaveToFile( const wxString& aDirectory = "", bool aForce = false ) override; + bool SaveAs( const wxString& aDirectory, const wxString& aFile ); + void SetProject( PROJECT* aProject ) { m_project = aProject; diff --git a/kicad/tools/kicad_manager_control.cpp b/kicad/tools/kicad_manager_control.cpp index 19b30ab6df..ef923adfbb 100644 --- a/kicad/tools/kicad_manager_control.cpp +++ b/kicad/tools/kicad_manager_control.cpp @@ -24,6 +24,7 @@ #include <kiway.h> #include <kicad_manager_frame.h> #include <confirm.h> +#include <project/project_file.h> #include <settings/settings_manager.h> #include <tool/selection.h> #include <tool/tool_event.h> @@ -31,12 +32,10 @@ #include <tools/kicad_manager_control.h> #include <dialogs/dialog_template_selector.h> #include <gestfich.h> -#include <string_utils.h> #include <paths.h> #include <wx/checkbox.h> #include <wx/dir.h> #include <wx/filedlg.h> -#include <common.h> #ifdef PCM #include "dialog_pcm.h" @@ -364,7 +363,7 @@ public: wxString ext = destFile.GetExt(); bool atRoot = destFile.GetPath() == m_projectDirPath; - if( ext == "pro" ) + if( ext == LegacyProjectFileExtension || ext == ProjectFileExtension ) { wxString destPath = destFile.GetPath(); @@ -382,9 +381,16 @@ public: m_newProjectFile = destFile; } - // Currently all paths in the settings file are relative, so we can just do a - // straight copy - KiCopyFile( aSrcFilePath, destFile.GetFullPath(), m_errors ); + if( ext == LegacyProjectFileExtension ) + { + // All paths in the settings file are relative so we can just do a straight copy + KiCopyFile( aSrcFilePath, destFile.GetFullPath(), m_errors ); + } + else + { + PROJECT_FILE projectFile( aSrcFilePath ); + projectFile.SaveAs( destFile.GetPath(), destFile.GetName() ); + } } else if( ext == KiCadSchematicFileExtension || ext == KiCadSchematicFileExtension + BackupFileSuffix @@ -431,9 +437,9 @@ public: else { // Everything we don't recognize just gets a straight copy. - wxString destPath = destFile.GetPathWithSep(); - wxString destName = destFile.GetName(); - wxUniChar pathSep = wxFileName::GetPathSeparator(); + wxString destPath = destFile.GetPathWithSep(); + wxString destName = destFile.GetName(); + wxUniChar pathSep = wxFileName::GetPathSeparator(); wxString srcProjectFootprintLib = pathSep + m_projectName + ".pretty" + pathSep; wxString newProjectFootprintLib = pathSep + m_newProjectName + ".pretty" + pathSep; @@ -450,7 +456,6 @@ public: destPath.Replace( srcProjectFootprintLib, newProjectFootprintLib, true ); destFile.SetPath( destPath ); - KiCopyFile( aSrcFilePath, destFile.GetFullPath(), m_errors ); }