Unify IsSave and IsModify

The flags and calls were used identically, leading to potential
confusion/bugs.  Testing for modification should go through
IsContentModified()
This commit is contained in:
Seth Hillbrand 2021-05-27 16:07:48 -07:00
parent f399dc7dd0
commit d7f219e98f
18 changed files with 25 additions and 32 deletions

View File

@ -40,7 +40,6 @@ BASE_SCREEN::BASE_SCREEN( EDA_ITEM* aParent, KICAD_T aType ) :
m_Center = true; m_Center = true;
m_flagModified = false; // Set when any change is made on board. m_flagModified = false; // Set when any change is made on board.
m_flagSave = false; // Used in auto save set when an auto save is required.
} }

View File

@ -1025,7 +1025,7 @@ void EDA_BASE_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName )
} }
bool EDA_BASE_FRAME::IsContentModified() bool EDA_BASE_FRAME::IsContentModified() const
{ {
// This function should be overridden in child classes // This function should be overridden in child classes
return false; return false;

View File

@ -139,7 +139,7 @@ public:
* *
* @return true if the any changes have not been saved * @return true if the any changes have not been saved
*/ */
bool IsContentModified() override bool IsContentModified() const override
{ {
return m_modified; return m_modified;
} }

View File

@ -188,7 +188,6 @@ bool SCH_EDIT_FRAME::SaveEEFile( SCH_SHEET* aSheet, bool aSaveUnderNewName )
UpdateFileHistory( schematicFileName.GetFullPath() ); UpdateFileHistory( schematicFileName.GetFullPath() );
} }
screen->ClrSave();
screen->ClrModify(); screen->ClrModify();
UpdateTitle(); UpdateTitle();
@ -1029,6 +1028,10 @@ bool SCH_EDIT_FRAME::doAutoSave()
wxFileName tmp; wxFileName tmp;
SCH_SCREENS screens( Schematic().Root() ); SCH_SCREENS screens( Schematic().Root() );
// Don't run autosave if content has not been modified
if( !IsContentModified() )
return true;
bool autoSaveOk = true; bool autoSaveOk = true;
if( fn.GetPath().IsEmpty() ) if( fn.GetPath().IsEmpty() )
@ -1047,7 +1050,7 @@ bool SCH_EDIT_FRAME::doAutoSave()
for( size_t i = 0; i < screens.GetCount(); i++ ) for( size_t i = 0; i < screens.GetCount(); i++ )
{ {
// Only create auto save files for the schematics that have been modified. // Only create auto save files for the schematics that have been modified.
if( !screens.GetScreen( i )->IsSave() ) if( !screens.GetScreen( i )->IsModify() )
continue; continue;
tmpFileName = fn = screens.GetScreen( i )->GetFileName(); tmpFileName = fn = screens.GetScreen( i )->GetFileName();

View File

@ -783,7 +783,6 @@ void SCH_EDIT_FRAME::OnModify()
return; return;
GetScreen()->SetModify(); GetScreen()->SetModify();
GetScreen()->SetSave();
if( ADVANCED_CFG::GetCfg().m_RealTimeConnectivity && CONNECTION_GRAPH::m_allowRealTime ) if( ADVANCED_CFG::GetCfg().m_RealTimeConnectivity && CONNECTION_GRAPH::m_allowRealTime )
RecalculateConnections( NO_CLEANUP ); RecalculateConnections( NO_CLEANUP );
@ -1099,13 +1098,7 @@ bool SCH_EDIT_FRAME::isAutoSaveRequired() const
if( Schematic().IsValid() ) if( Schematic().IsValid() )
{ {
SCH_SCREENS screenList( Schematic().Root() ); return IsContentModified();
for( SCH_SCREEN* screen = screenList.GetFirst(); screen; screen = screenList.GetNext() )
{
if( screen->IsSave() )
return true;
}
} }
return false; return false;
@ -1555,7 +1548,7 @@ void SCH_EDIT_FRAME::FixupJunctions()
} }
bool SCH_EDIT_FRAME::IsContentModified() bool SCH_EDIT_FRAME::IsContentModified() const
{ {
return Schematic().GetSheets().IsModified(); return Schematic().GetSheets().IsModified();
} }

View File

@ -175,7 +175,7 @@ public:
* *
* @return true if the any changes have not been saved * @return true if the any changes have not been saved
*/ */
bool IsContentModified() override; bool IsContentModified() const override;
/** /**
* Must be called after a schematic change in order to set the "modify" flag of the * Must be called after a schematic change in order to set the "modify" flag of the

View File

@ -1230,7 +1230,7 @@ bool SYMBOL_EDIT_FRAME::HasLibModifications() const
} }
bool SYMBOL_EDIT_FRAME::IsContentModified() bool SYMBOL_EDIT_FRAME::IsContentModified() const
{ {
wxCHECK( m_libMgr, false ); wxCHECK( m_libMgr, false );

View File

@ -66,7 +66,7 @@ public:
* *
* @return true if the any changes have not been saved * @return true if the any changes have not been saved
*/ */
bool IsContentModified() override; bool IsContentModified() const override;
/** /**
* Check if any pending libraries have been modified. * Check if any pending libraries have been modified.
@ -100,7 +100,7 @@ public:
* *
* This is a LIB_PART that I own, it is at best a copy of one in a library. * This is a LIB_PART that I own, it is at best a copy of one in a library.
*/ */
LIB_PART* GetCurPart() { return m_my_part; } LIB_PART* GetCurPart() const { return m_my_part; }
/** /**
* Take ownership of aPart and notes that it is the one currently being edited. * Take ownership of aPart and notes that it is the one currently being edited.

View File

@ -58,10 +58,7 @@ public:
void SetModify() { m_flagModified = true; } void SetModify() { m_flagModified = true; }
void ClrModify() { m_flagModified = false; } void ClrModify() { m_flagModified = false; }
void SetSave() { m_flagSave = true; }
void ClrSave() { m_flagSave = false; }
bool IsModify() const { return m_flagModified; } bool IsModify() const { return m_flagModified; }
bool IsSave() const { return m_flagSave; }
/** /**
* Return the class name. * Return the class name.
@ -134,7 +131,6 @@ protected:
private: private:
bool m_flagModified; ///< Indicates current drawing has been modified. bool m_flagModified; ///< Indicates current drawing has been modified.
bool m_flagSave; ///< Indicates automatic file save.
/** /**
* The cross hair position in logical (drawing) units. The cross hair is not the cursor * The cross hair position in logical (drawing) units. The cross hair is not the cursor

View File

@ -498,7 +498,7 @@ public:
* *
* @return true if the contents of the frame have not been saved * @return true if the contents of the frame have not been saved
*/ */
virtual bool IsContentModified(); virtual bool IsContentModified() const;
/** /**
* Get the undecorated window size that can be used for restoring the window size. * Get the undecorated window size that can be used for restoring the window size.

View File

@ -328,7 +328,7 @@ bool PL_EDITOR_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, i
} }
bool PL_EDITOR_FRAME::IsContentModified() bool PL_EDITOR_FRAME::IsContentModified() const
{ {
return GetScreen() && GetScreen()->IsModify(); return GetScreen() && GetScreen()->IsModify();
} }

View File

@ -101,7 +101,7 @@ public:
* *
* @return true if the any changes have not been saved * @return true if the any changes have not been saved
*/ */
bool IsContentModified() override; bool IsContentModified() const override;
/* /*
* Function OnExit * Function OnExit

View File

@ -1065,7 +1065,6 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool addToHistory,
m_infoBar->Dismiss(); m_infoBar->Dismiss();
GetScreen()->ClrModify(); GetScreen()->ClrModify();
GetScreen()->ClrSave();
UpdateTitle(); UpdateTitle();
return true; return true;
} }
@ -1140,6 +1139,10 @@ bool PCB_EDIT_FRAME::doAutoSave()
{ {
wxFileName tmpFileName; wxFileName tmpFileName;
// Don't run autosave if content has not been modified
if( !IsContentModified() )
return true;
wxString title = GetTitle(); // Save frame title, that can be modified by the save process wxString title = GetTitle(); // Save frame title, that can be modified by the save process
if( GetBoard()->GetFileName().IsEmpty() ) if( GetBoard()->GetFileName().IsEmpty() )

View File

@ -316,7 +316,7 @@ FOOTPRINT_EDIT_FRAME::~FOOTPRINT_EDIT_FRAME()
} }
bool FOOTPRINT_EDIT_FRAME::IsContentModified() bool FOOTPRINT_EDIT_FRAME::IsContentModified() const
{ {
return GetScreen() && GetScreen()->IsModify() && GetBoard() && GetBoard()->GetFirstFootprint(); return GetScreen() && GetScreen()->IsModify() && GetBoard() && GetBoard()->GetFirstFootprint();
} }

View File

@ -55,7 +55,7 @@ public:
* *
* @return true if the any changes have not been saved * @return true if the any changes have not been saved
*/ */
bool IsContentModified() override; bool IsContentModified() const override;
bool IsCurrentFPFromBoard() const; bool IsCurrentFPFromBoard() const;

View File

@ -690,7 +690,6 @@ void PCB_BASE_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVars
void PCB_BASE_FRAME::OnModify() void PCB_BASE_FRAME::OnModify()
{ {
GetScreen()->SetModify(); GetScreen()->SetModify();
GetScreen()->SetSave();
GetBoard()->IncrementTimeStamp(); GetBoard()->IncrementTimeStamp();

View File

@ -447,7 +447,7 @@ void PCB_EDIT_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
} }
bool PCB_EDIT_FRAME::IsContentModified() bool PCB_EDIT_FRAME::IsContentModified() const
{ {
return GetScreen() && GetScreen()->IsModify(); return GetScreen() && GetScreen()->IsModify();
} }
@ -456,7 +456,7 @@ bool PCB_EDIT_FRAME::IsContentModified()
bool PCB_EDIT_FRAME::isAutoSaveRequired() const bool PCB_EDIT_FRAME::isAutoSaveRequired() const
{ {
if( GetScreen() ) if( GetScreen() )
return GetScreen()->IsSave(); return GetScreen()->IsModify();
return false; return false;
} }

View File

@ -91,7 +91,7 @@ public:
* *
* @return true if the any changes have not been saved * @return true if the any changes have not been saved
*/ */
bool IsContentModified() override; bool IsContentModified() const override;
/** /**
* Reload the Python plugins if they are newer than the already loaded, and load new * Reload the Python plugins if they are newer than the already loaded, and load new