diff --git a/eeschema/libedit_undo_redo.cpp b/eeschema/libedit_undo_redo.cpp index a29350081f..2774569c9d 100644 --- a/eeschema/libedit_undo_redo.cpp +++ b/eeschema/libedit_undo_redo.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2007 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2014 KiCad Developers, see CHANGELOG.TXT for contributors. + * Copyright (C) 2014-2017 KiCad Developers, see CHANGELOG.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -25,8 +25,6 @@ #include #include -//#include -//#include #include #include @@ -34,16 +32,15 @@ void LIB_EDIT_FRAME::SaveCopyInUndoList( EDA_ITEM* ItemToCopy ) { LIB_PART* CopyItem; - PICKED_ITEMS_LIST* lastcmd; + PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST(); CopyItem = new LIB_PART( * (LIB_PART*) ItemToCopy ); // Clear current flags (which can be temporary set by a current edit command). CopyItem->ClearStatus(); - lastcmd = new PICKED_ITEMS_LIST(); ITEM_PICKER wrapper( CopyItem, UR_LIBEDIT ); - lastcmd->PushItem(wrapper); + lastcmd->PushItem( wrapper ); GetScreen()->PushCommandToUndoList( lastcmd ); // Clear redo list, because after new save there is no redo to do. @@ -56,19 +53,17 @@ void LIB_EDIT_FRAME::GetComponentFromRedoList( wxCommandEvent& event ) if( GetScreen()->GetRedoCommandCount() <= 0 ) return; + // Store the current part in the undo buffer PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST(); - LIB_PART* part = GetCurPart(); - ITEM_PICKER wrapper( part, UR_LIBEDIT ); - lastcmd->PushItem( wrapper ); GetScreen()->PushCommandToUndoList( lastcmd ); + // Load the last redo entry lastcmd = GetScreen()->PopCommandFromRedoList(); - wrapper = lastcmd->PopItem(); - + delete lastcmd; part = (LIB_PART*) wrapper.GetItem(); // Do not delete the previous part by calling SetCurPart( part ) @@ -99,20 +94,18 @@ void LIB_EDIT_FRAME::GetComponentFromUndoList( wxCommandEvent& event ) if( GetScreen()->GetUndoCommandCount() <= 0 ) return; + // Store the current part in the redo buffer PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST(); - - LIB_PART* part = GetCurPart(); - + LIB_PART* part = GetCurPart(); ITEM_PICKER wrapper( part, UR_LIBEDIT ); - lastcmd->PushItem( wrapper ); GetScreen()->PushCommandToRedoList( lastcmd ); + // Load the last undo entry lastcmd = GetScreen()->PopCommandFromUndoList(); - wrapper = lastcmd->PopItem(); - - part = (LIB_PART* ) wrapper.GetItem(); + delete lastcmd; + part = (LIB_PART*) wrapper.GetItem(); // Do not delete the previous part by calling SetCurPart( part ), // which calls delete . diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 02f2030d10..f9e723487e 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -599,22 +599,13 @@ void SCH_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount if( aItemCount == 0 ) return; - unsigned icnt = aList.m_CommandsList.size(); - - if( aItemCount > 0 ) - icnt = aItemCount; - - for( unsigned ii = 0; ii < icnt; ii++ ) + for( auto& command : aList.m_CommandsList ) { - if( aList.m_CommandsList.size() == 0 ) - break; - - PICKED_ITEMS_LIST* curr_cmd = aList.m_CommandsList[0]; - aList.m_CommandsList.erase( aList.m_CommandsList.begin() ); - - curr_cmd->ClearListAndDeleteItems(); - delete curr_cmd; // Delete command + command->ClearListAndDeleteItems(); + delete command; } + + aList.m_CommandsList.clear(); }