mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
Handle undo when changing new item before placing.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/21391 (cherry picked from commit a191d4e6e5620cbf0cd17698e0e83d08d68c45c1)
This commit is contained in:
parent
9d2b6ce033
commit
2a246801eb
@ -127,6 +127,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 );
|
||||
|
@ -2431,7 +2431,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 )
|
||||
{
|
||||
@ -2773,14 +2777,15 @@ int SCH_EDIT_TOOL::ChangeTextType( const TOOL_EVENT& aEvent )
|
||||
if( selected )
|
||||
m_toolMgr->RunAction<EDA_ITEM*>( SCH_ACTIONS::removeItemFromSel, item );
|
||||
|
||||
if( !item->IsNew() )
|
||||
{
|
||||
m_frame->RemoveFromScreen( item, m_frame->GetScreen() );
|
||||
commit.Removed( item, 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() );
|
||||
}
|
||||
commit->Added( newtext, m_frame->GetScreen() );
|
||||
|
||||
if( selected )
|
||||
m_toolMgr->RunAction<EDA_ITEM*>( SCH_ACTIONS::addItemToSel, newtext );
|
||||
@ -2791,8 +2796,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( SCH_ACTIONS::clearSelection );
|
||||
|
@ -867,8 +867,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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user