Handle undo when changing new item before placing.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/21391
This commit is contained in:
@@ -119,6 +119,26 @@ COMMIT& COMMIT::Stage( const PICKED_ITEMS_LIST &aItems, UNDO_REDO aModFlag, BASE
|
||||
}
|
||||
|
||||
|
||||
void COMMIT::Unstage( EDA_ITEM* aItem, BASE_SCREEN* aScreen )
|
||||
{
|
||||
std::erase_if( m_changes,
|
||||
[&]( COMMIT_LINE& line )
|
||||
{
|
||||
if( line.m_item == aItem && line.m_screen == aScreen )
|
||||
{
|
||||
// Only new items which have never been committed can be unstaged
|
||||
wxASSERT( line.m_item->IsNew() );
|
||||
|
||||
delete line.m_item;
|
||||
delete line.m_copy;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
int COMMIT::GetStatus( EDA_ITEM* aItem, BASE_SCREEN *aScreen )
|
||||
{
|
||||
COMMIT_LINE* entry = findEntry( parentObject( aItem ), aScreen );
|
||||
|
||||
@@ -2468,7 +2468,11 @@ int SCH_EDIT_TOOL::ChangeTextType( const TOOL_EVENT& aEvent )
|
||||
SCH_SELECTION selection = m_selectionTool->RequestSelection( { SCH_LABEL_LOCATE_ANY_T,
|
||||
SCH_TEXT_T,
|
||||
SCH_TEXTBOX_T } );
|
||||
SCH_COMMIT commit( m_toolMgr );
|
||||
SCH_COMMIT localCommit( m_toolMgr );
|
||||
SCH_COMMIT* commit = dynamic_cast<SCH_COMMIT*>( aEvent.Commit() );
|
||||
|
||||
if( !commit )
|
||||
commit = &localCommit;
|
||||
|
||||
for( unsigned int i = 0; i < selection.GetSize(); ++i )
|
||||
{
|
||||
@@ -2806,14 +2810,15 @@ int SCH_EDIT_TOOL::ChangeTextType( const TOOL_EVENT& aEvent )
|
||||
if( selected )
|
||||
m_toolMgr->RunAction<EDA_ITEM*>( ACTIONS::unselectItem, item );
|
||||
|
||||
if( !item->IsNew() )
|
||||
{
|
||||
m_frame->RemoveFromScreen( item, m_frame->GetScreen() );
|
||||
commit.Removed( item, m_frame->GetScreen() );
|
||||
m_frame->RemoveFromScreen( item, m_frame->GetScreen() );
|
||||
|
||||
m_frame->AddToScreen( newtext, m_frame->GetScreen() );
|
||||
commit.Added( newtext, m_frame->GetScreen() );
|
||||
}
|
||||
if( item->IsNew() )
|
||||
commit->Unstage( item, m_frame->GetScreen() );
|
||||
else
|
||||
commit->Removed( item, m_frame->GetScreen() );
|
||||
|
||||
m_frame->AddToScreen( newtext, m_frame->GetScreen() );
|
||||
commit->Added( newtext, m_frame->GetScreen() );
|
||||
|
||||
if( selected )
|
||||
m_toolMgr->RunAction<EDA_ITEM*>( ACTIONS::selectItem, newtext );
|
||||
@@ -2824,8 +2829,8 @@ int SCH_EDIT_TOOL::ChangeTextType( const TOOL_EVENT& aEvent )
|
||||
}
|
||||
}
|
||||
|
||||
if( !commit.Empty() )
|
||||
commit.Push( _( "Change To" ) );
|
||||
if( !localCommit.Empty() )
|
||||
localCommit.Push( _( "Change To" ) );
|
||||
|
||||
if( selection.IsHover() )
|
||||
m_toolMgr->RunAction( ACTIONS::selectionClear );
|
||||
|
||||
@@ -891,8 +891,31 @@ bool SCH_MOVE_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, SCH_COMMIT* aComm
|
||||
}
|
||||
else if( evt->IsAction( &ACTIONS::increment ) )
|
||||
{
|
||||
m_toolMgr->RunSynchronousAction( ACTIONS::increment, aCommit,
|
||||
evt->Parameter<ACTIONS::INCREMENT>() );
|
||||
m_toolMgr->RunSynchronousAction( ACTIONS::increment, aCommit, evt->Parameter<ACTIONS::INCREMENT>() );
|
||||
}
|
||||
else if( evt->IsAction( &SCH_ACTIONS::toCLabel ) )
|
||||
{
|
||||
m_toolMgr->RunSynchronousAction( SCH_ACTIONS::toCLabel, aCommit );
|
||||
}
|
||||
else if( evt->IsAction( &SCH_ACTIONS::toGLabel ) )
|
||||
{
|
||||
m_toolMgr->RunSynchronousAction( SCH_ACTIONS::toGLabel, aCommit );
|
||||
}
|
||||
else if( evt->IsAction( &SCH_ACTIONS::toHLabel ) )
|
||||
{
|
||||
m_toolMgr->RunSynchronousAction( SCH_ACTIONS::toHLabel, aCommit );
|
||||
}
|
||||
else if( evt->IsAction( &SCH_ACTIONS::toLabel ) )
|
||||
{
|
||||
m_toolMgr->RunSynchronousAction( SCH_ACTIONS::toLabel, aCommit );
|
||||
}
|
||||
else if( evt->IsAction( &SCH_ACTIONS::toText ) )
|
||||
{
|
||||
m_toolMgr->RunSynchronousAction( SCH_ACTIONS::toText, aCommit );
|
||||
}
|
||||
else if( evt->IsAction( &SCH_ACTIONS::toTextBox ) )
|
||||
{
|
||||
m_toolMgr->RunSynchronousAction( SCH_ACTIONS::toTextBox, aCommit );
|
||||
}
|
||||
else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
|
||||
{
|
||||
|
||||
@@ -141,6 +141,8 @@ public:
|
||||
UNDO_REDO aModFlag = UNDO_REDO::UNSPECIFIED,
|
||||
BASE_SCREEN *aScreen = nullptr );
|
||||
|
||||
void Unstage( EDA_ITEM* aItem, BASE_SCREEN* aScreen );
|
||||
|
||||
/// Execute the changes.
|
||||
virtual void Push( const wxString& aMessage = wxT( "A commit" ), int aFlags = 0 ) = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user