diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp index f33042afaa..71a9a30ec7 100644 --- a/common/eda_base_frame.cpp +++ b/common/eda_base_frame.cpp @@ -796,14 +796,14 @@ bool EDA_BASE_FRAME::IsContentModified() void EDA_BASE_FRAME::ClearUndoRedoList() { - ClearUndoORRedoList( m_UndoList ); - ClearUndoORRedoList( m_RedoList ); + ClearUndoORRedoList( UNDO_LIST ); + ClearUndoORRedoList( REDO_LIST ); } void EDA_BASE_FRAME::PushCommandToUndoList( PICKED_ITEMS_LIST* aNewitem ) { - m_UndoList.PushCommand( aNewitem ); + m_undoList.PushCommand( aNewitem ); // Delete the extra items, if count max reached if( m_UndoRedoCountMax > 0 ) @@ -811,14 +811,14 @@ void EDA_BASE_FRAME::PushCommandToUndoList( PICKED_ITEMS_LIST* aNewitem ) int extraitems = GetUndoCommandCount() - m_UndoRedoCountMax; if( extraitems > 0 ) - ClearUndoORRedoList( m_UndoList, extraitems ); + ClearUndoORRedoList( UNDO_LIST, extraitems ); } } void EDA_BASE_FRAME::PushCommandToRedoList( PICKED_ITEMS_LIST* aNewitem ) { - m_RedoList.PushCommand( aNewitem ); + m_redoList.PushCommand( aNewitem ); // Delete the extra items, if count max reached if( m_UndoRedoCountMax > 0 ) @@ -826,20 +826,20 @@ void EDA_BASE_FRAME::PushCommandToRedoList( PICKED_ITEMS_LIST* aNewitem ) int extraitems = GetRedoCommandCount() - m_UndoRedoCountMax; if( extraitems > 0 ) - ClearUndoORRedoList( m_RedoList, extraitems ); + ClearUndoORRedoList( REDO_LIST, extraitems ); } } PICKED_ITEMS_LIST* EDA_BASE_FRAME::PopCommandFromUndoList( ) { - return m_UndoList.PopCommand(); + return m_undoList.PopCommand(); } PICKED_ITEMS_LIST* EDA_BASE_FRAME::PopCommandFromRedoList( ) { - return m_RedoList.PopCommand(); + return m_redoList.PopCommand(); } diff --git a/eeschema/dialogs/dialog_symbol_remap.cpp b/eeschema/dialogs/dialog_symbol_remap.cpp index 41f2dc8478..870244d0e5 100644 --- a/eeschema/dialogs/dialog_symbol_remap.cpp +++ b/eeschema/dialogs/dialog_symbol_remap.cpp @@ -99,7 +99,7 @@ void DIALOG_SYMBOL_REMAP::OnRemapSymbols( wxCommandEvent& aEvent ) if( viewer ) viewer->ReCreateListLib(); - parent->ClearUndoORRedoList( parent->m_UndoList, 1 ); + parent->ClearUndoORRedoList( EDA_BASE_FRAME::UNDO_LIST, 1 ); parent->SyncView(); parent->GetCanvas()->Refresh(); parent->OnModify(); diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp index ab523e7f08..00425f615e 100644 --- a/eeschema/libedit/lib_edit_frame.cpp +++ b/eeschema/libedit/lib_edit_frame.cpp @@ -910,18 +910,20 @@ bool LIB_EDIT_FRAME::IsContentModified() } -void LIB_EDIT_FRAME::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount ) +void LIB_EDIT_FRAME::ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCount ) { if( aItemCount == 0 ) return; - for( auto& command : aList.m_CommandsList ) + UNDO_REDO_CONTAINER& list = whichList == UNDO_LIST ? m_undoList : m_redoList; + + for( PICKED_ITEMS_LIST* command : list.m_CommandsList ) { command->ClearListAndDeleteItems(); delete command; } - aList.m_CommandsList.clear(); + list.m_CommandsList.clear(); } diff --git a/eeschema/libedit/lib_edit_frame.h b/eeschema/libedit/lib_edit_frame.h index 6fb9041dbf..65a1d89e69 100644 --- a/eeschema/libedit/lib_edit_frame.h +++ b/eeschema/libedit/lib_edit_frame.h @@ -349,12 +349,12 @@ public: * - data pointed by wrappers are deleted if not in use in schematic * i.e. when they are copy of a schematic item or they are no more in use (DELETED) * - * @param aList = the UNDO_REDO_CONTAINER to clear + * @param whichList = the UNDO_REDO_CONTAINER to clear * @param aItemCount = the count of items to remove. < 0 for all items * items are removed from the beginning of the list. * So this function can be called to remove old commands */ - void ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount = -1 ) override; + void ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCount = -1 ) override; private: /** diff --git a/eeschema/libedit/libedit_undo_redo.cpp b/eeschema/libedit/libedit_undo_redo.cpp index 6d31517d1a..e7d8f5e80a 100644 --- a/eeschema/libedit/libedit_undo_redo.cpp +++ b/eeschema/libedit/libedit_undo_redo.cpp @@ -56,7 +56,7 @@ void LIB_EDIT_FRAME::SaveCopyInUndoList( EDA_ITEM* ItemToCopy, UNDO_REDO_T undoT PushCommandToUndoList( lastcmd ); // Clear redo list, because after new save there is no redo to do. - ClearUndoORRedoList( m_RedoList ); + ClearUndoORRedoList( REDO_LIST ); } diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index f7d088b388..28934b9c08 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -847,12 +847,12 @@ public: * - data pointed by wrappers are deleted if not in use in schematic * i.e. when they are copy of a schematic item or they are no more in use (DELETED) * - * @param aList = the UNDO_REDO_CONTAINER to clear + * @param whichList = the UNDO_REDO_CONTAINER to clear * @param aItemCount = the count of items to remove. < 0 for all items * items are removed from the beginning of the list. * So this function can be called to remove old commands */ - void ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount = -1 ) override; + void ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCount = -1 ) override; /** * Clone \a aItem and owns that clone in this container. diff --git a/eeschema/schematic_undo_redo.cpp b/eeschema/schematic_undo_redo.cpp index efac143376..753bcd0088 100644 --- a/eeschema/schematic_undo_redo.cpp +++ b/eeschema/schematic_undo_redo.cpp @@ -146,7 +146,7 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( SCH_SCREEN* aScreen, PushCommandToUndoList( commandToUndo ); /* Clear redo list, because after new save there is no redo to do */ - ClearUndoORRedoList( m_RedoList ); + ClearUndoORRedoList( REDO_LIST ); } else { @@ -242,7 +242,7 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, PushCommandToUndoList( commandToUndo ); /* Clear redo list, because after new save there is no redo to do */ - ClearUndoORRedoList( m_RedoList ); + ClearUndoORRedoList( REDO_LIST ); } else // Should not occur { @@ -369,18 +369,20 @@ void SCH_EDIT_FRAME::RollbackSchematicFromUndo() } -void SCH_EDIT_FRAME::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount ) +void SCH_EDIT_FRAME::ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCount ) { if( aItemCount == 0 ) return; - for( auto& command : aList.m_CommandsList ) + UNDO_REDO_CONTAINER& list = whichList == UNDO_LIST ? m_undoList : m_redoList; + + for( PICKED_ITEMS_LIST* command : list.m_CommandsList ) { command->ClearListAndDeleteItems(); delete command; } - aList.m_CommandsList.clear(); + list.m_CommandsList.clear(); } diff --git a/include/eda_base_frame.h b/include/eda_base_frame.h index b7393d9822..faa6e41da7 100644 --- a/include/eda_base_frame.h +++ b/include/eda_base_frame.h @@ -152,12 +152,9 @@ protected: bool m_FlagSave; // Indicates automatic file save. int m_UndoRedoCountMax; // undo/Redo command Max depth -public: - // Undo/redo list of commands - UNDO_REDO_CONTAINER m_UndoList; // Objects list for the undo command (old data) - UNDO_REDO_CONTAINER m_RedoList; // Objects list for the redo command (old data) + UNDO_REDO_CONTAINER m_undoList; // Objects list for the undo command (old data) + UNDO_REDO_CONTAINER m_redoList; // Objects list for the redo command (old data) -protected: wxString m_mruPath; // Most recently used path. EDA_UNITS m_userUnits; @@ -551,7 +548,8 @@ public: * old commands this will empty the list of commands. * Commands are deleted from the older to the last. */ - virtual void ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount = -1 ) + enum UNDO_REDO_LIST { UNDO_LIST, REDO_LIST }; + virtual void ClearUndoORRedoList( UNDO_REDO_LIST aList, int aItemCount = -1 ) { } /** @@ -592,28 +590,10 @@ public: */ virtual PICKED_ITEMS_LIST* PopCommandFromRedoList(); - int GetUndoCommandCount() const - { - return m_UndoList.m_CommandsList.size(); - } - - int GetRedoCommandCount() const - { - return m_RedoList.m_CommandsList.size(); - } + int GetUndoCommandCount() const { return m_undoList.m_CommandsList.size(); } + int GetRedoCommandCount() const { return m_redoList.m_CommandsList.size(); } int GetMaxUndoItems() const { return m_UndoRedoCountMax; } - - void SetMaxUndoItems( int aMax ) - { - if( aMax >= 0 && aMax < ABS_MAX_UNDO_ITEMS ) - m_UndoRedoCountMax = aMax; - else - { - wxFAIL_MSG( "Maximum undo items not within limits" ); - m_UndoRedoCountMax = DEFAULT_MAX_UNDO_ITEMS; - } - } }; diff --git a/pagelayout_editor/pl_editor_frame.cpp b/pagelayout_editor/pl_editor_frame.cpp index 2f7d23f6e9..4120d17fce 100644 --- a/pagelayout_editor/pl_editor_frame.cpp +++ b/pagelayout_editor/pl_editor_frame.cpp @@ -833,23 +833,24 @@ void PL_EDITOR_FRAME::OnNewPageLayout() } -void PL_EDITOR_FRAME::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount ) +void PL_EDITOR_FRAME::ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCount ) { if( aItemCount == 0 ) return; - unsigned icnt = aList.m_CommandsList.size(); + UNDO_REDO_CONTAINER& list = whichList == UNDO_LIST ? m_undoList : m_redoList; + unsigned icnt = list.m_CommandsList.size(); if( aItemCount > 0 ) icnt = aItemCount; for( unsigned ii = 0; ii < icnt; ii++ ) { - if( aList.m_CommandsList.size() == 0 ) + if( list.m_CommandsList.size() == 0 ) break; - PICKED_ITEMS_LIST* curr_cmd = aList.m_CommandsList[0]; - aList.m_CommandsList.erase( aList.m_CommandsList.begin() ); + PICKED_ITEMS_LIST* curr_cmd = list.m_CommandsList[0]; + list.m_CommandsList.erase( list.m_CommandsList.begin() ); curr_cmd->ClearListAndDeleteItems(); delete curr_cmd; // Delete command diff --git a/pagelayout_editor/pl_editor_frame.h b/pagelayout_editor/pl_editor_frame.h index 6678f34be0..363d156326 100644 --- a/pagelayout_editor/pl_editor_frame.h +++ b/pagelayout_editor/pl_editor_frame.h @@ -285,7 +285,7 @@ public: /** * Function ClearUndoORRedoList */ - void ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount = -1 ) override; + void ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCount = -1 ) override; protected: bool saveCurrentPageLayout(); diff --git a/pagelayout_editor/pl_editor_undo_redo.cpp b/pagelayout_editor/pl_editor_undo_redo.cpp index b75e136f13..1dae6746d6 100644 --- a/pagelayout_editor/pl_editor_undo_redo.cpp +++ b/pagelayout_editor/pl_editor_undo_redo.cpp @@ -42,7 +42,7 @@ void PL_EDITOR_FRAME::SaveCopyInUndoList() PushCommandToUndoList( lastcmd ); // Clear redo list, because after new save there is no redo to do. - ClearUndoORRedoList( m_RedoList ); + ClearUndoORRedoList( REDO_LIST ); } diff --git a/pcbnew/pcb_base_edit_frame.h b/pcbnew/pcb_base_edit_frame.h index 3d44d1ed54..59ecf35d7c 100644 --- a/pcbnew/pcb_base_edit_frame.h +++ b/pcbnew/pcb_base_edit_frame.h @@ -198,12 +198,12 @@ public: * datas pointed by wrappers are deleted if not in use in schematic * i.e. when they are copy of a schematic item or they are no more in use * (DELETED) - * @param aList = the UNDO_REDO_CONTAINER to clear + * @param whichList = the UNDO_REDO_CONTAINER to clear * @param aItemCount = the count of items to remove. < 0 for all items * items are removed from the beginning of the list. * So this function can be called to remove old commands */ - void ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount = -1 ) override; + void ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCount = -1 ) override; protected: /// User defined rotation angle (in tenths of a degree). diff --git a/pcbnew/undo_redo.cpp b/pcbnew/undo_redo.cpp index 8355c00a48..b100931d79 100644 --- a/pcbnew/undo_redo.cpp +++ b/pcbnew/undo_redo.cpp @@ -318,7 +318,7 @@ void PCB_BASE_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsLis PushCommandToUndoList( commandToUndo ); /* Clear redo list, because after a new command one cannot redo a command */ - ClearUndoORRedoList( m_RedoList ); + ClearUndoORRedoList( REDO_LIST ); } else { @@ -585,23 +585,24 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool -void PCB_BASE_EDIT_FRAME::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount ) +void PCB_BASE_EDIT_FRAME::ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCount ) { if( aItemCount == 0 ) return; - unsigned icnt = aList.m_CommandsList.size(); + UNDO_REDO_CONTAINER& list = whichList == UNDO_LIST ? m_undoList : m_redoList; + unsigned icnt = list.m_CommandsList.size(); if( aItemCount > 0 ) icnt = aItemCount; for( unsigned ii = 0; ii < icnt; ii++ ) { - if( aList.m_CommandsList.size() == 0 ) + if( list.m_CommandsList.size() == 0 ) break; - PICKED_ITEMS_LIST* curr_cmd = aList.m_CommandsList[0]; - aList.m_CommandsList.erase( aList.m_CommandsList.begin() ); + PICKED_ITEMS_LIST* curr_cmd = list.m_CommandsList[0]; + list.m_CommandsList.erase( list.m_CommandsList.begin() ); curr_cmd->ClearListAndDeleteItems(); delete curr_cmd; // Delete command