From d7f219e98fef94eeb28845d994775bfebb029b68 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 27 May 2021 16:07:48 -0700 Subject: [PATCH] Unify IsSave and IsModify The flags and calls were used identically, leading to potential confusion/bugs. Testing for modification should go through IsContentModified() --- common/base_screen.cpp | 1 - common/eda_base_frame.cpp | 2 +- cvpcb/cvpcb_mainframe.h | 2 +- eeschema/files-io.cpp | 7 +++++-- eeschema/sch_edit_frame.cpp | 11 ++--------- eeschema/sch_edit_frame.h | 2 +- eeschema/symbol_editor/symbol_edit_frame.cpp | 2 +- eeschema/symbol_editor/symbol_edit_frame.h | 4 ++-- include/base_screen.h | 4 ---- include/eda_base_frame.h | 2 +- pagelayout_editor/pl_editor_frame.cpp | 2 +- pagelayout_editor/pl_editor_frame.h | 2 +- pcbnew/files.cpp | 5 ++++- pcbnew/footprint_edit_frame.cpp | 2 +- pcbnew/footprint_edit_frame.h | 2 +- pcbnew/pcb_base_frame.cpp | 1 - pcbnew/pcb_edit_frame.cpp | 4 ++-- pcbnew/pcb_edit_frame.h | 2 +- 18 files changed, 25 insertions(+), 32 deletions(-) diff --git a/common/base_screen.cpp b/common/base_screen.cpp index bd64e7955f..961224401c 100644 --- a/common/base_screen.cpp +++ b/common/base_screen.cpp @@ -40,7 +40,6 @@ BASE_SCREEN::BASE_SCREEN( EDA_ITEM* aParent, KICAD_T aType ) : m_Center = true; 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. } diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp index 76464e2762..b6cac098fe 100644 --- a/common/eda_base_frame.cpp +++ b/common/eda_base_frame.cpp @@ -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 return false; diff --git a/cvpcb/cvpcb_mainframe.h b/cvpcb/cvpcb_mainframe.h index 0f15b9ed16..d1e2b53936 100644 --- a/cvpcb/cvpcb_mainframe.h +++ b/cvpcb/cvpcb_mainframe.h @@ -139,7 +139,7 @@ public: * * @return true if the any changes have not been saved */ - bool IsContentModified() override + bool IsContentModified() const override { return m_modified; } diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 60ddfd829b..352274c00e 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -188,7 +188,6 @@ bool SCH_EDIT_FRAME::SaveEEFile( SCH_SHEET* aSheet, bool aSaveUnderNewName ) UpdateFileHistory( schematicFileName.GetFullPath() ); } - screen->ClrSave(); screen->ClrModify(); UpdateTitle(); @@ -1029,6 +1028,10 @@ bool SCH_EDIT_FRAME::doAutoSave() wxFileName tmp; SCH_SCREENS screens( Schematic().Root() ); + // Don't run autosave if content has not been modified + if( !IsContentModified() ) + return true; + bool autoSaveOk = true; if( fn.GetPath().IsEmpty() ) @@ -1047,7 +1050,7 @@ bool SCH_EDIT_FRAME::doAutoSave() for( size_t i = 0; i < screens.GetCount(); i++ ) { // Only create auto save files for the schematics that have been modified. - if( !screens.GetScreen( i )->IsSave() ) + if( !screens.GetScreen( i )->IsModify() ) continue; tmpFileName = fn = screens.GetScreen( i )->GetFileName(); diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index a883230b65..8fd5a6bf32 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -783,7 +783,6 @@ void SCH_EDIT_FRAME::OnModify() return; GetScreen()->SetModify(); - GetScreen()->SetSave(); if( ADVANCED_CFG::GetCfg().m_RealTimeConnectivity && CONNECTION_GRAPH::m_allowRealTime ) RecalculateConnections( NO_CLEANUP ); @@ -1099,13 +1098,7 @@ bool SCH_EDIT_FRAME::isAutoSaveRequired() const if( Schematic().IsValid() ) { - SCH_SCREENS screenList( Schematic().Root() ); - - for( SCH_SCREEN* screen = screenList.GetFirst(); screen; screen = screenList.GetNext() ) - { - if( screen->IsSave() ) - return true; - } + return IsContentModified(); } 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(); } diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index 847bf47e86..093d14b7dd 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -175,7 +175,7 @@ public: * * @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 diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index 7ff427b871..4d2d0fcbcd 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -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 ); diff --git a/eeschema/symbol_editor/symbol_edit_frame.h b/eeschema/symbol_editor/symbol_edit_frame.h index b6b6b72abc..5e6eef860f 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.h +++ b/eeschema/symbol_editor/symbol_edit_frame.h @@ -66,7 +66,7 @@ public: * * @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. @@ -100,7 +100,7 @@ public: * * 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. diff --git a/include/base_screen.h b/include/base_screen.h index 17342ce85c..02f04386ba 100644 --- a/include/base_screen.h +++ b/include/base_screen.h @@ -58,10 +58,7 @@ public: void SetModify() { m_flagModified = true; } void ClrModify() { m_flagModified = false; } - void SetSave() { m_flagSave = true; } - void ClrSave() { m_flagSave = false; } bool IsModify() const { return m_flagModified; } - bool IsSave() const { return m_flagSave; } /** * Return the class name. @@ -134,7 +131,6 @@ protected: private: 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 diff --git a/include/eda_base_frame.h b/include/eda_base_frame.h index 2aedf8d177..4cda7c4b33 100644 --- a/include/eda_base_frame.h +++ b/include/eda_base_frame.h @@ -498,7 +498,7 @@ public: * * @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. diff --git a/pagelayout_editor/pl_editor_frame.cpp b/pagelayout_editor/pl_editor_frame.cpp index 0985719b43..caed9888e0 100644 --- a/pagelayout_editor/pl_editor_frame.cpp +++ b/pagelayout_editor/pl_editor_frame.cpp @@ -328,7 +328,7 @@ bool PL_EDITOR_FRAME::OpenProjectFiles( const std::vector& aFileSet, i } -bool PL_EDITOR_FRAME::IsContentModified() +bool PL_EDITOR_FRAME::IsContentModified() const { return GetScreen() && GetScreen()->IsModify(); } diff --git a/pagelayout_editor/pl_editor_frame.h b/pagelayout_editor/pl_editor_frame.h index 774384f794..5334d728fc 100644 --- a/pagelayout_editor/pl_editor_frame.h +++ b/pagelayout_editor/pl_editor_frame.h @@ -101,7 +101,7 @@ public: * * @return true if the any changes have not been saved */ - bool IsContentModified() override; + bool IsContentModified() const override; /* * Function OnExit diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index ca8f415c6a..b03deaaa68 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -1065,7 +1065,6 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool addToHistory, m_infoBar->Dismiss(); GetScreen()->ClrModify(); - GetScreen()->ClrSave(); UpdateTitle(); return true; } @@ -1140,6 +1139,10 @@ bool PCB_EDIT_FRAME::doAutoSave() { 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 if( GetBoard()->GetFileName().IsEmpty() ) diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index 7ddccdb14c..1b3b744896 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -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(); } diff --git a/pcbnew/footprint_edit_frame.h b/pcbnew/footprint_edit_frame.h index 16235e5c5b..60bd9eb185 100644 --- a/pcbnew/footprint_edit_frame.h +++ b/pcbnew/footprint_edit_frame.h @@ -55,7 +55,7 @@ public: * * @return true if the any changes have not been saved */ - bool IsContentModified() override; + bool IsContentModified() const override; bool IsCurrentFPFromBoard() const; diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index efa952fe01..674ed679c4 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -690,7 +690,6 @@ void PCB_BASE_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVars void PCB_BASE_FRAME::OnModify() { GetScreen()->SetModify(); - GetScreen()->SetSave(); GetBoard()->IncrementTimeStamp(); diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index cf68c78041..e9d5c7ada7 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -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(); } @@ -456,7 +456,7 @@ bool PCB_EDIT_FRAME::IsContentModified() bool PCB_EDIT_FRAME::isAutoSaveRequired() const { if( GetScreen() ) - return GetScreen()->IsSave(); + return GetScreen()->IsModify(); return false; } diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index b829fef5f9..7c90ea77ba 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -91,7 +91,7 @@ public: * * @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