Browse Source

More fixes to autosaving migrated projects

- Add WasMigrated to project file

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

(cherry picked from commit 846f6127fd)
8.0
Jon Evans 10 months ago
parent
commit
d91d07d187
  1. 3
      common/project/project_file.cpp
  2. 8
      common/project/project_local_settings.cpp
  3. 7
      include/project/project_file.h
  4. 14
      kicad/kicad_manager_frame.cpp
  5. 3
      kicad/tools/kicad_manager_control.cpp

3
common/project/project_file.cpp

@ -41,7 +41,8 @@ PROJECT_FILE::PROJECT_FILE( const wxString& aFullPath ) :
m_BoardSettings(),
m_sheets(),
m_boards(),
m_project( nullptr )
m_project( nullptr ),
m_wasMigrated( false )
{
// Keep old files around
m_deleteLegacyAfterMigration = false;

8
common/project/project_local_settings.cpp

@ -361,6 +361,10 @@ bool PROJECT_LOCAL_SETTINGS::SaveToFile( const wxString& aDirectory, bool aForce
Set( "meta.filename", m_project->GetProjectName() + "." + FILEEXT::ProjectLocalSettingsFileExtension );
// If we're actually going ahead and doing the save, the flag that keeps code from doing the save
// should be cleared at this point
m_wasMigrated = false;
return JSON_SETTINGS::SaveToFile( aDirectory, aForce );
}
@ -370,6 +374,10 @@ bool PROJECT_LOCAL_SETTINGS::SaveAs( const wxString& aDirectory, const wxString&
Set( "meta.filename", aFile + "." + FILEEXT::ProjectLocalSettingsFileExtension );
SetFilename( aFile );
// If we're actually going ahead and doing the save, the flag that keeps code from doing the save
// should be cleared at this point
m_wasMigrated = false;
return JSON_SETTINGS::SaveToFile( aDirectory, true );
}

7
include/project/project_file.h

@ -103,6 +103,11 @@ public:
return m_NetSettings;
}
/**
* @return true if the local settings needed to be migrated, and shouldn't be auto-saved
*/
bool WasMigrated() const { return m_wasMigrated; }
protected:
wxString getFileExt() const override;
@ -188,6 +193,8 @@ private:
/// A link to the owning PROJECT
PROJECT* m_project;
bool m_wasMigrated;
};
// Specializations to allow directly reading/writing FILE_INFO_PAIRs from JSON

14
kicad/kicad_manager_frame.cpp

@ -80,6 +80,8 @@
#include "kicad_manager_frame.h"
#include "settings/kicad_settings.h"
#include <project/project_file.h>
#define SEP() wxFileName::GetPathSeparator()
@ -600,15 +602,21 @@ bool KICAD_MANAGER_FRAME::CloseProject( bool aSave )
if( !Kiway().PlayersClose( false ) )
return false;
bool shouldSaveProject = !Prj().GetLocalSettings().WasMigrated()
&& !Prj().GetProjectFile().WasMigrated();
// Save the project file for the currently loaded project.
if( m_active_project )
{
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
mgr.TriggerBackupIfNeeded( NULL_REPORTER::GetInstance() );
if( shouldSaveProject )
{
mgr.TriggerBackupIfNeeded( NULL_REPORTER::GetInstance() );
if( aSave )
mgr.SaveProject();
if( aSave )
mgr.SaveProject();
}
m_active_project = false;
mgr.UnloadProject( &Prj() );

3
kicad/tools/kicad_manager_control.cpp

@ -808,7 +808,8 @@ int KICAD_MANAGER_CONTROL::ShowPlayer( const TOOL_EVENT& aEvent )
// Save window state to disk now. Don't wait around for a crash.
if( Pgm().GetCommonSettings()->m_Session.remember_open_files
&& !player->GetCurrentFileName().IsEmpty() )
&& !player->GetCurrentFileName().IsEmpty()
&& !Prj().GetLocalSettings().WasMigrated() )
{
wxFileName rfn( player->GetCurrentFileName() );
rfn.MakeRelativeTo( Prj().GetProjectPath() );

Loading…
Cancel
Save