Adding COMMIT support before/after invocation of a python script

Allows undo/redo of ACTION_SCRIPT commands
This commit is contained in:
Jean-Samuel Reynaud 2021-03-18 12:52:17 +00:00 committed by Seth Hillbrand
parent 16ef1910ff
commit e377f2667e
1 changed files with 13 additions and 2 deletions

View File

@ -243,6 +243,8 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin )
itemsList.ClearItemsList(); itemsList.ClearItemsList();
BOARD_COMMIT commit( this );
// Execute plugin itself... // Execute plugin itself...
ACTION_PLUGINS::SetActionRunning( true ); ACTION_PLUGINS::SetActionRunning( true );
aActionPlugin->Run(); aActionPlugin->Run();
@ -283,7 +285,7 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin )
for( ZONE* zone : currentPcb->Zones() ) for( ZONE* zone : currentPcb->Zones() )
currItemList.insert( zone ); currItemList.insert( zone );
// Found deleted footprints // Found deleted items
for( unsigned int i = 0; i < oldBuffer->GetCount(); i++ ) for( unsigned int i = 0; i < oldBuffer->GetCount(); i++ )
{ {
BOARD_ITEM* item = (BOARD_ITEM*) oldBuffer->GetPickedItem( i ); BOARD_ITEM* item = (BOARD_ITEM*) oldBuffer->GetPickedItem( i );
@ -292,15 +294,18 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin )
wxASSERT( item ); wxASSERT( item );
if( currItemList.find( item ) == currItemList.end() ) if( currItemList.find( item ) == currItemList.end() )
{
deletedItemsList.PushItem( picker ); deletedItemsList.PushItem( picker );
commit.Removed( item );
}
} }
// Mark deleted elements in undolist // Mark deleted elements in undolist
for( unsigned int i = 0; i < deletedItemsList.GetCount(); i++ ) for( unsigned int i = 0; i < deletedItemsList.GetCount(); i++ )
{ {
oldBuffer->PushItem( deletedItemsList.GetItemWrapper( i ) ); oldBuffer->PushItem( deletedItemsList.GetItemWrapper( i ) );
} }
// Find new footprints // Find new footprints
for( FOOTPRINT* item : currentPcb->Footprints() ) for( FOOTPRINT* item : currentPcb->Footprints() )
{ {
@ -308,6 +313,7 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin )
{ {
ITEM_PICKER picker( nullptr, item, UNDO_REDO::NEWITEM ); ITEM_PICKER picker( nullptr, item, UNDO_REDO::NEWITEM );
oldBuffer->PushItem( picker ); oldBuffer->PushItem( picker );
commit.Added( item );
} }
} }
@ -317,6 +323,7 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin )
{ {
ITEM_PICKER picker( nullptr, item, UNDO_REDO::NEWITEM ); ITEM_PICKER picker( nullptr, item, UNDO_REDO::NEWITEM );
oldBuffer->PushItem( picker ); oldBuffer->PushItem( picker );
commit.Added( item );
} }
} }
@ -326,6 +333,7 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin )
{ {
ITEM_PICKER picker( nullptr, item, UNDO_REDO::NEWITEM ); ITEM_PICKER picker( nullptr, item, UNDO_REDO::NEWITEM );
oldBuffer->PushItem( picker ); oldBuffer->PushItem( picker );
commit.Added( item );
} }
} }
@ -335,9 +343,11 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin )
{ {
ITEM_PICKER picker( nullptr, zone, UNDO_REDO::NEWITEM ); ITEM_PICKER picker( nullptr, zone, UNDO_REDO::NEWITEM );
oldBuffer->PushItem( picker ); oldBuffer->PushItem( picker );
commit.Added( zone );
} }
} }
if( oldBuffer->GetCount() ) if( oldBuffer->GetCount() )
{ {
OnModify(); OnModify();
@ -348,6 +358,7 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin )
delete oldBuffer; delete oldBuffer;
} }
commit.Push( _( "Apply action script" ) );
ActivateGalCanvas(); ActivateGalCanvas();
} }