Save as for current version project files.

Fixes https://gitlab.com/kicad/code/kicad/issues/9455
This commit is contained in:
Jeff Young 2021-10-30 23:01:19 +01:00
parent 8367c7f238
commit c8a8efa67b
3 changed files with 26 additions and 10 deletions

View File

@ -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 wxString PROJECT_FILE::getFileExt() const
{ {
return ProjectFileExtension; return ProjectFileExtension;

View File

@ -76,6 +76,8 @@ public:
bool SaveToFile( const wxString& aDirectory = "", bool aForce = false ) override; bool SaveToFile( const wxString& aDirectory = "", bool aForce = false ) override;
bool SaveAs( const wxString& aDirectory, const wxString& aFile );
void SetProject( PROJECT* aProject ) void SetProject( PROJECT* aProject )
{ {
m_project = aProject; m_project = aProject;

View File

@ -24,6 +24,7 @@
#include <kiway.h> #include <kiway.h>
#include <kicad_manager_frame.h> #include <kicad_manager_frame.h>
#include <confirm.h> #include <confirm.h>
#include <project/project_file.h>
#include <settings/settings_manager.h> #include <settings/settings_manager.h>
#include <tool/selection.h> #include <tool/selection.h>
#include <tool/tool_event.h> #include <tool/tool_event.h>
@ -31,12 +32,10 @@
#include <tools/kicad_manager_control.h> #include <tools/kicad_manager_control.h>
#include <dialogs/dialog_template_selector.h> #include <dialogs/dialog_template_selector.h>
#include <gestfich.h> #include <gestfich.h>
#include <string_utils.h>
#include <paths.h> #include <paths.h>
#include <wx/checkbox.h> #include <wx/checkbox.h>
#include <wx/dir.h> #include <wx/dir.h>
#include <wx/filedlg.h> #include <wx/filedlg.h>
#include <common.h>
#ifdef PCM #ifdef PCM
#include "dialog_pcm.h" #include "dialog_pcm.h"
@ -364,7 +363,7 @@ public:
wxString ext = destFile.GetExt(); wxString ext = destFile.GetExt();
bool atRoot = destFile.GetPath() == m_projectDirPath; bool atRoot = destFile.GetPath() == m_projectDirPath;
if( ext == "pro" ) if( ext == LegacyProjectFileExtension || ext == ProjectFileExtension )
{ {
wxString destPath = destFile.GetPath(); wxString destPath = destFile.GetPath();
@ -382,10 +381,17 @@ public:
m_newProjectFile = destFile; m_newProjectFile = destFile;
} }
// Currently all paths in the settings file are relative, so we can just do a if( ext == LegacyProjectFileExtension )
// straight copy {
// All paths in the settings file are relative so we can just do a straight copy
KiCopyFile( aSrcFilePath, destFile.GetFullPath(), m_errors ); KiCopyFile( aSrcFilePath, destFile.GetFullPath(), m_errors );
} }
else
{
PROJECT_FILE projectFile( aSrcFilePath );
projectFile.SaveAs( destFile.GetPath(), destFile.GetName() );
}
}
else if( ext == KiCadSchematicFileExtension else if( ext == KiCadSchematicFileExtension
|| ext == KiCadSchematicFileExtension + BackupFileSuffix || ext == KiCadSchematicFileExtension + BackupFileSuffix
|| ext == LegacySchematicFileExtension || ext == LegacySchematicFileExtension
@ -450,7 +456,6 @@ public:
destPath.Replace( srcProjectFootprintLib, newProjectFootprintLib, true ); destPath.Replace( srcProjectFootprintLib, newProjectFootprintLib, true );
destFile.SetPath( destPath ); destFile.SetPath( destPath );
KiCopyFile( aSrcFilePath, destFile.GetFullPath(), m_errors ); KiCopyFile( aSrcFilePath, destFile.GetFullPath(), m_errors );
} }