Split the undo/redo event into the two stages "pre" and "post" for convenient synchronization of dependent state.

This commit is contained in:
decimad 2016-09-23 11:31:36 +02:00 committed by Maciej Suminski
parent 8ea643cefc
commit 6a9c1cb6a1
6 changed files with 23 additions and 11 deletions

View File

@ -89,7 +89,8 @@ const std::string TOOL_EVENT::Format() const
{ TA_CANCEL_TOOL, "cancel-tool" },
{ TA_CONTEXT_MENU_UPDATE, "context-menu-update" },
{ TA_CONTEXT_MENU_CHOICE, "context-menu-choice" },
{ TA_UNDO_REDO, "undo-redo" },
{ TA_UNDO_REDO_PRE, "undo-redo-pre" },
{ TA_UNDO_REDO_POST, "undo-redo-post" },
{ TA_ACTION, "action" },
{ TA_ACTIVATE, "activate" },
{ 0, "" }

View File

@ -95,13 +95,16 @@ enum TOOL_ACTIONS
TA_CONTEXT_MENU = TA_CONTEXT_MENU_UPDATE | TA_CONTEXT_MENU_CHOICE | TA_CONTEXT_MENU_CLOSED,
// This event is sent *before* undo/redo command is performed.
TA_UNDO_REDO = 0x20000,
TA_UNDO_REDO_PRE = 0x20000,
// This event is sent *after* undo/redo command is performed.
TA_UNDO_REDO_POST = 0x40000,
// Tool action (allows to control tools).
TA_ACTION = 0x40000,
TA_ACTION = 0x80000,
// Tool activation event.
TA_ACTIVATE = 0x80000,
TA_ACTIVATE = 0x100000,
TA_ANY = 0xffffffff
};

View File

@ -685,7 +685,11 @@ int ROUTER_TOOL::mainLoop( PNS::ROUTER_MODE aMode )
{
break; // Finish
}
else if( evt->Action() == TA_UNDO_REDO )
else if( evt->Action() == TA_UNDO_REDO_PRE )
{
m_router->ClearWorld();
}
else if( evt->Action() == TA_UNDO_REDO_POST )
{
m_router->SyncWorld();
}

View File

@ -173,7 +173,7 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
break; // Finish
}
else if( evt->Action() == TA_UNDO_REDO )
else if( evt->Action() == TA_UNDO_REDO_PRE )
{
unselect = true;
break;

View File

@ -260,7 +260,7 @@ int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
UnselectItem( *evt );
}
else if( evt->IsCancel() || evt->Action() == TA_UNDO_REDO ||
else if( evt->IsCancel() || evt->Action() == TA_UNDO_REDO_PRE ||
evt->IsAction( &COMMON_ACTIONS::selectionClear ) )
{
clearSelection();

View File

@ -321,8 +321,7 @@ void PCB_BASE_EDIT_FRAME::RestoreCopyFromUndoList( wxCommandEvent& aEvent )
return;
// Inform tools that undo command was issued
TOOL_EVENT event( TC_MESSAGE, TA_UNDO_REDO, AS_GLOBAL );
m_toolManager->ProcessEvent( event );
m_toolManager->ProcessEvent( { TC_MESSAGE, TA_UNDO_REDO_PRE, AS_GLOBAL } );
// Get the old list
PICKED_ITEMS_LIST* List = GetScreen()->PopCommandFromUndoList();
@ -335,6 +334,9 @@ void PCB_BASE_EDIT_FRAME::RestoreCopyFromUndoList( wxCommandEvent& aEvent )
GetScreen()->PushCommandToRedoList( List );
OnModify();
m_toolManager->ProcessEvent( { TC_MESSAGE, TA_UNDO_REDO_POST, AS_GLOBAL } );
m_canvas->Refresh();
}
@ -348,8 +350,7 @@ void PCB_BASE_EDIT_FRAME::RestoreCopyFromRedoList( wxCommandEvent& aEvent )
return;
// Inform tools that redo command was issued
TOOL_EVENT event( TC_MESSAGE, TA_UNDO_REDO, AS_GLOBAL );
m_toolManager->ProcessEvent( event );
m_toolManager->ProcessEvent( { TC_MESSAGE, TA_UNDO_REDO_PRE, AS_GLOBAL } );
// Get the old list
PICKED_ITEMS_LIST* List = GetScreen()->PopCommandFromRedoList();
@ -362,6 +363,9 @@ void PCB_BASE_EDIT_FRAME::RestoreCopyFromRedoList( wxCommandEvent& aEvent )
GetScreen()->PushCommandToUndoList( List );
OnModify();
m_toolManager->ProcessEvent( { TC_MESSAGE, TA_UNDO_REDO_POST, AS_GLOBAL } );
m_canvas->Refresh();
}