From 3221877fe867aac47b5c81b11883036d316758d5 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 10 Oct 2022 14:03:10 +0100 Subject: [PATCH] Push autosave-require down in to EDA_BASE_FRAME. Fixes https://gitlab.com/kicad/code/kicad/issues/11790 --- common/eda_base_frame.cpp | 7 ++++++ eeschema/files-io.cpp | 8 +++++-- eeschema/sch_base_frame.h | 6 ----- eeschema/sch_edit_frame.cpp | 17 +++---------- eeschema/sch_edit_frame.h | 9 ++----- eeschema/symbol_editor/symbol_edit_frame.cpp | 3 +++ include/eda_base_frame.h | 9 ++++++- include/pcb_base_frame.h | 9 +++---- pagelayout_editor/pl_editor_frame.h | 4 +++- pcbnew/files.cpp | 25 ++++++++++++++++---- pcbnew/pcb_base_frame.cpp | 3 +++ pcbnew/pcb_edit_frame.cpp | 9 ------- pcbnew/pcb_edit_frame.h | 5 ---- 13 files changed, 59 insertions(+), 55 deletions(-) diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp index a8e40ccaa6..d88b23cbbb 100644 --- a/common/eda_base_frame.cpp +++ b/common/eda_base_frame.cpp @@ -127,6 +127,7 @@ void EDA_BASE_FRAME::commonInit( FRAME_T aFrameType ) m_isClosing = false; m_isNonUserClose = false; m_autoSaveTimer = new wxTimer( this, ID_AUTO_SAVE_TIMER ); + m_autoSaveRequired = false; m_mruPath = PATHS::GetDefaultUserProjectsPath(); m_frameSize = defaultSize( aFrameType ); m_displayIndex = -1; @@ -1300,6 +1301,12 @@ PICKED_ITEMS_LIST* EDA_BASE_FRAME::PopCommandFromRedoList( ) } +void EDA_BASE_FRAME::OnModify() +{ + m_autoSaveRequired = true; +} + + void EDA_BASE_FRAME::ChangeUserUnits( EDA_UNITS aUnits ) { SetUserUnits( aUnits ); diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index a37ebebd95..4cc7f285ae 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -1033,6 +1033,9 @@ bool SCH_EDIT_FRAME::SaveProject( bool aSaveAs ) success &= saveSchematicFile( screens.GetSheet( i ), tmpFn.GetFullPath() ); } + if( success ) + m_autoSaveRequired = false; + // One or more of the modified sheets did not save correctly so update the auto save file. if( !aSaveAs && !success ) success &= updateAutoSaveFile(); @@ -1154,10 +1157,11 @@ bool SCH_EDIT_FRAME::doAutoSave() if( autoSaveOk && updateAutoSaveFile() ) { + m_autoSaveRequired = false; m_autoSavePending = false; - if( !Kiface().IsSingle() && - GetSettingsManager()->GetCommonSettings()->m_Backup.backup_on_autosave ) + if( !Kiface().IsSingle() + && GetSettingsManager()->GetCommonSettings()->m_Backup.backup_on_autosave ) { GetSettingsManager()->TriggerBackupIfNeeded( NULL_REPORTER::GetInstance() ); } diff --git a/eeschema/sch_base_frame.h b/eeschema/sch_base_frame.h index 2ab1ec35db..2b7b5f3445 100644 --- a/eeschema/sch_base_frame.h +++ b/eeschema/sch_base_frame.h @@ -240,12 +240,6 @@ public: */ void SyncView(); - /** - * Must be called after a model change in order to set the "modify" flag and - * do other frame-specific processing. - */ - virtual void OnModify() {} - void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override; /** diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 83557a2e97..b15bcad5af 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -955,12 +955,15 @@ wxString SCH_EDIT_FRAME::GetUniqueFilenameForCurrentSheet() void SCH_EDIT_FRAME::OnModify() { + EDA_BASE_FRAME::OnModify(); + wxASSERT( GetScreen() ); if( !GetScreen() ) return; GetScreen()->SetContentModified(); + m_autoSaveRequired = true; if( ADVANCED_CFG::GetCfg().m_RealTimeConnectivity && CONNECTION_GRAPH::m_allowRealTime ) RecalculateConnections( NO_CLEANUP ); @@ -1281,20 +1284,6 @@ void SCH_EDIT_FRAME::PrintPage( const RENDER_SETTINGS* aSettings ) } -bool SCH_EDIT_FRAME::isAutoSaveRequired() const -{ - // In case this event happens before g_RootSheet is initialized which does happen - // on mingw64 builds. - - if( Schematic().IsValid() ) - { - return IsContentModified(); - } - - return false; -} - - void SCH_EDIT_FRAME::AutoRotateItem( SCH_SCREEN* aScreen, SCH_ITEM* aItem ) { if( aItem->IsType( { SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T } ) ) diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index d08038e1e1..e9f5dd3ea4 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -144,8 +144,8 @@ public: bool IsContentModified() const override; /** - * Must be called after a schematic change in order to set the "modify" flag of the - * current screen and update the date in frame reference. + * Must be called after a schematic change in order to set the "modify" flag and update other + * data structures and GUI elements. */ void OnModify() override; @@ -840,11 +840,6 @@ protected: */ bool doAutoSave() override; - /** - * Return true if the schematic has been modified. - */ - bool isAutoSaveRequired() const override; - /** * Send the KiCad netlist over to CVPCB. */ diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index 74bfc224be..e6573402d0 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -828,7 +828,10 @@ LIB_SYMBOL_LIBRARY_MANAGER& SYMBOL_EDIT_FRAME::GetLibManager() void SYMBOL_EDIT_FRAME::OnModify() { + EDA_BASE_FRAME::OnModify(); + GetScreen()->SetContentModified(); + m_autoSaveRequired = true; if( !IsSymbolFromSchematic() ) storeCurrentSymbol(); diff --git a/include/eda_base_frame.h b/include/eda_base_frame.h index 1884303c0e..53ac0618a9 100644 --- a/include/eda_base_frame.h +++ b/include/eda_base_frame.h @@ -564,6 +564,12 @@ public: int GetMaxUndoItems() const { return m_undoRedoCountMax; } + /** + * Must be called after a model change in order to set the "modify" flag and do other + * frame-specific processing. + */ + virtual void OnModify(); + bool NonUserClose( bool aForce ) { m_isNonUserClose = true; @@ -606,7 +612,7 @@ protected: * * Override this function if your derived frame supports automatic file saving. */ - virtual bool isAutoSaveRequired() const { return false; } + virtual bool isAutoSaveRequired() const { return m_autoSaveRequired; } /** * This should be overridden by the derived class to handle the auto save feature. @@ -724,6 +730,7 @@ private: bool m_supportsAutoSave; bool m_autoSavePending; + bool m_autoSaveRequired; wxTimer* m_autoSaveTimer; int m_undoRedoCountMax; // undo/Redo command Max depth diff --git a/include/pcb_base_frame.h b/include/pcb_base_frame.h index 252f427316..65c2bfea9b 100644 --- a/include/pcb_base_frame.h +++ b/include/pcb_base_frame.h @@ -243,13 +243,10 @@ public: FOOTPRINT* GetFootprintFromBoardByReference(); /** - * Must be called after a change in order to set the "modify" flag of the current screen - * and update the date in frame reference. - * - * Do not forget to call this basic OnModify function to update info in derived OnModify - * functions. + * Must be called after a change in order to set the "modify" flag and update other data + * structures and GUI elements. */ - virtual void OnModify(); + void OnModify() override; /** * Creates a new footprint, at position 0,0. diff --git a/pagelayout_editor/pl_editor_frame.h b/pagelayout_editor/pl_editor_frame.h index 0e054b99ce..2cf8541227 100644 --- a/pagelayout_editor/pl_editor_frame.h +++ b/pagelayout_editor/pl_editor_frame.h @@ -237,8 +237,10 @@ public: /** * Must be called after a change in order to set the "modify" flag. */ - void OnModify() + void OnModify() override { + EDA_BASE_FRAME::OnModify(); + GetScreen()->SetContentModified(); } diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 854ce8bd34..17b2440d87 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -418,7 +418,15 @@ bool PCB_EDIT_FRAME::Files_io_from_id( int id ) case ID_SAVE_BOARD: if( !GetBoard()->GetFileName().IsEmpty() ) - return SavePcbFile( Prj().AbsolutePath( GetBoard()->GetFileName() ) ); + { + if( SavePcbFile( Prj().AbsolutePath( GetBoard()->GetFileName() ) ) ) + { + m_autoSaveRequired = false; + return true; + } + + return false; + } KI_FALLTHROUGH; @@ -446,16 +454,24 @@ bool PCB_EDIT_FRAME::Files_io_from_id( int id ) wxFileName fn( savePath.GetPath(), orig_name, KiCadPcbFileExtension ); wxString filename = fn.GetFullPath(); bool createProject = false; + bool success = false; if( AskSaveBoardFileName( this, &filename, &createProject ) ) { if( id == ID_COPY_BOARD_AS ) - return SavePcbCopy( filename, createProject ); + { + success = SavePcbCopy( filename, createProject ); + } else - return SavePcbFile( filename, addToHistory, createProject ); + { + success = SavePcbFile( filename, addToHistory, createProject ); + + if( success ) + m_autoSaveRequired = false; + } } - return false; + return success; } default: @@ -1246,6 +1262,7 @@ bool PCB_EDIT_FRAME::doAutoSave() GetScreen()->SetContentModified(); GetBoard()->SetFileName( tmpFileName.GetFullPath() ); UpdateTitle(); + m_autoSaveRequired = false; m_autoSavePending = false; if( !Kiface().IsSingle() && diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index 8f3ae60674..ea1de508f2 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -995,7 +995,10 @@ void PCB_BASE_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVars void PCB_BASE_FRAME::OnModify() { + EDA_BASE_FRAME::OnModify(); + GetScreen()->SetContentModified(); + m_autoSaveRequired = true; GetBoard()->IncrementTimeStamp(); diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index cb8adf2e16..a231cf3db8 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -562,15 +562,6 @@ bool PCB_EDIT_FRAME::IsContentModified() const } -bool PCB_EDIT_FRAME::isAutoSaveRequired() const -{ - if( GetScreen() ) - return GetScreen()->IsContentModified(); - - return false; -} - - SELECTION& PCB_EDIT_FRAME::GetCurrentSelection() { return m_toolManager->GetTool()->GetSelection(); diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index 32500ab462..7cda7fd492 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -781,11 +781,6 @@ protected: */ bool doAutoSave() override; - /** - * Return true if the board has been modified. - */ - bool isAutoSaveRequired() const override; - /** * Load the given filename but sets the path to the current project path. *