diff --git a/common/commit.cpp b/common/commit.cpp index 3316f76529..9c75d8a843 100644 --- a/common/commit.cpp +++ b/common/commit.cpp @@ -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 ); diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index f9c2757093..d69785d422 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -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( 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( SCH_ACTIONS::removeItemFromSel, 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( 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 ); diff --git a/eeschema/tools/sch_move_tool.cpp b/eeschema/tools/sch_move_tool.cpp index 91ed29494d..1d17620fc7 100644 --- a/eeschema/tools/sch_move_tool.cpp +++ b/eeschema/tools/sch_move_tool.cpp @@ -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() ); + m_toolMgr->RunSynchronousAction( ACTIONS::increment, aCommit, evt->Parameter() ); + } + 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 ) { diff --git a/include/commit.h b/include/commit.h index 74bd0afffa..05e8969964 100644 --- a/include/commit.h +++ b/include/commit.h @@ -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;