Correct path of pcb drawing sheet file on saveAs.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15551

(cherry picked from commit 722a90213c)
This commit is contained in:
Jeff Young 2023-09-21 17:02:15 +01:00
parent 2b106a2b34
commit e14aef9bd5
2 changed files with 35 additions and 1 deletions

View File

@ -569,9 +569,42 @@ bool PROJECT_FILE::SaveToFile( const wxString& aDirectory, bool aForce )
bool PROJECT_FILE::SaveAs( const wxString& aDirectory, const wxString& aFile ) 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 ); Set( "meta.filename", aFile + "." + ProjectFileExtension );
SetFilename( aFile ); 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<wxString> path = Get<wxString>( 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 // While performing Save As, we have already checked that we can write to the directory
// so don't carry the previous flag // so don't carry the previous flag
SetReadOnly( false ); SetReadOnly( false );

View File

@ -45,7 +45,8 @@ typedef std::pair<KIID, wxString> FILE_INFO_PAIR;
*/ */
enum LAST_PATH_TYPE : unsigned int 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_STEP,
LAST_PATH_IDF, LAST_PATH_IDF,
LAST_PATH_VRML, LAST_PATH_VRML,