Make undo/redo lists protected.

This commit is contained in:
Jeff Young 2020-07-13 14:50:35 +01:00
parent fa9937701f
commit 1cd2a51db2
13 changed files with 49 additions and 63 deletions

View File

@ -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();
}

View File

@ -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();

View File

@ -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();
}

View File

@ -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:
/**

View File

@ -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 );
}

View File

@ -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.

View File

@ -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();
}

View File

@ -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;
}
}
};

View File

@ -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

View File

@ -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();

View File

@ -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 );
}

View File

@ -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).

View File

@ -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