diff --git a/common/project/project_file.cpp b/common/project/project_file.cpp index 13a2fe0797..034fc7f1c8 100644 --- a/common/project/project_file.cpp +++ b/common/project/project_file.cpp @@ -569,9 +569,42 @@ bool PROJECT_FILE::SaveToFile( const wxString& aDirectory, bool aForce ) bool PROJECT_FILE::SaveAs( const wxString& aDirectory, const wxString& aFile ) { + wxFileName oldFilename( GetFilename() ); + wxString oldProjectName = oldFilename.GetName(); + wxString oldProjectPath = oldFilename.GetPath(); + Set( "meta.filename", aFile + "." + ProjectFileExtension ); SetFilename( aFile ); + auto updatePath = + [&]( wxString& aPath ) + { + if( aPath.StartsWith( oldProjectName + wxS( "." ) ) ) + aPath.Replace( oldProjectName, aFile, false ); + else if( aPath.StartsWith( oldProjectPath + wxS( "/" ) ) ) + aPath.Replace( oldProjectPath, aDirectory, false ); + }; + + updatePath( m_BoardDrawingSheetFile ); + + for( int ii = LAST_PATH_FIRST; ii < (int) LAST_PATH_SIZE; ++ii ) + updatePath( m_PcbLastPath[ ii ] ); + + auto updatePathByPtr = + [&]( const std::string& aPtr ) + { + if( std::optional path = Get( aPtr ) ) + { + updatePath( path.value() ); + Set( aPtr, path.value() ); + } + }; + + updatePathByPtr( "schematic.page_layout_descr_file" ); + updatePathByPtr( "schematic.plot_directory" ); + updatePathByPtr( "schematic.ngspice.workbook_filename" ); + updatePathByPtr( "pcbnew.page_layout_descr_file" ); + // While performing Save As, we have already checked that we can write to the directory // so don't carry the previous flag SetReadOnly( false ); diff --git a/include/project/project_file.h b/include/project/project_file.h index 2d52a42225..39fffb5b29 100644 --- a/include/project/project_file.h +++ b/include/project/project_file.h @@ -45,7 +45,8 @@ typedef std::pair FILE_INFO_PAIR; */ enum LAST_PATH_TYPE : unsigned int { - LAST_PATH_NETLIST = 0, + LAST_PATH_FIRST = 0, + LAST_PATH_NETLIST = LAST_PATH_FIRST, LAST_PATH_STEP, LAST_PATH_IDF, LAST_PATH_VRML,