From b219fbc3d2089823a227c1ef1b0534362f69e372 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 20 Aug 2019 16:26:49 +0100 Subject: [PATCH] Implement undo/redo for lock/unlock/toggle lock. Fixes: lp:1840770 * https://bugs.launchpad.net/kicad/+bug/1840770 --- pcbnew/tools/pcb_editor_control.cpp | 32 +++++++++++++++-------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index ddadc98449..0fa242a846 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -786,39 +786,41 @@ int PCB_EDITOR_CONTROL::modifyLockSelected( MODIFY_MODE aMode ) { SELECTION_TOOL* selTool = m_toolMgr->GetTool(); const PCBNEW_SELECTION& selection = selTool->GetSelection(); + BOARD_COMMIT commit( m_frame ); if( selection.Empty() ) m_toolMgr->RunAction( PCB_ACTIONS::selectionCursor, true ); bool modified = false; - for( auto i : selection ) + for( EDA_ITEM* item : selection ) { - auto item = static_cast( i ); - bool prevState = item->IsLocked(); + BOARD_ITEM* board_item = static_cast( item ); + bool prevState = board_item->IsLocked(); + + commit.Modify( board_item ); switch( aMode ) { - case ON: - item->SetLocked( true ); - break; - - case OFF: - item->SetLocked( false ); - break; - - case TOGGLE: - item->SetLocked( !prevState ); - break; + case ON: board_item->SetLocked( true ); break; + case OFF: board_item->SetLocked( false ); break; + case TOGGLE: board_item->SetLocked( !prevState ); break; } // Check if we really modified an item - if( !modified && prevState != item->IsLocked() ) + if( !modified && prevState != board_item->IsLocked() ) modified = true; } if( modified ) { + switch( aMode ) + { + case ON: commit.Push( _( "Lock" ) ); break; + case OFF: commit.Push( _( "Unlock" ) ); break; + case TOGGLE: commit.Push( _( "Toggle Locking" ) ); break; + } + m_toolMgr->PostEvent( EVENTS::SelectedItemsModified ); m_frame->OnModify(); }