Moved UndoInhibit related functions from TOOL_MANAGER to EDIT_TOOL.
This commit is contained in:
parent
aafdfd015e
commit
f7a32e839e
|
@ -195,8 +195,7 @@ private:
|
||||||
|
|
||||||
|
|
||||||
TOOL_MANAGER::TOOL_MANAGER() :
|
TOOL_MANAGER::TOOL_MANAGER() :
|
||||||
m_model( NULL ), m_view( NULL ), m_viewControls( NULL ), m_editFrame( NULL ),
|
m_model( NULL ), m_view( NULL ), m_viewControls( NULL ), m_editFrame( NULL )
|
||||||
m_undoInhibit( false )
|
|
||||||
{
|
{
|
||||||
m_actionMgr = new ACTION_MANAGER( this );
|
m_actionMgr = new ACTION_MANAGER( this );
|
||||||
|
|
||||||
|
@ -635,7 +634,7 @@ bool TOOL_MANAGER::ProcessEvent( const TOOL_EVENT& aEvent )
|
||||||
|
|
||||||
if( m_view->IsDirty() )
|
if( m_view->IsDirty() )
|
||||||
{
|
{
|
||||||
PCB_EDIT_FRAME* f = static_cast<PCB_EDIT_FRAME*>( GetEditFrame() );
|
EDA_DRAW_FRAME* f = static_cast<EDA_DRAW_FRAME*>( GetEditFrame() );
|
||||||
f->GetGalCanvas()->Refresh(); // fixme: ugly hack, provide a method in TOOL_DISPATCHER.
|
f->GetGalCanvas()->Refresh(); // fixme: ugly hack, provide a method in TOOL_DISPATCHER.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -714,23 +713,3 @@ bool TOOL_MANAGER::isActive( TOOL_BASE* aTool )
|
||||||
// Just check if the tool is on the active tools stack
|
// Just check if the tool is on the active tools stack
|
||||||
return std::find( m_activeTools.begin(), m_activeTools.end(), aTool->GetId() ) != m_activeTools.end();
|
return std::find( m_activeTools.begin(), m_activeTools.end(), aTool->GetId() ) != m_activeTools.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TOOL_MANAGER::IncUndoInhibit()
|
|
||||||
{
|
|
||||||
m_undoInhibit++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TOOL_MANAGER::DecUndoInhibit()
|
|
||||||
{
|
|
||||||
m_undoInhibit--;
|
|
||||||
|
|
||||||
wxASSERT_MSG( m_undoInhibit >= 0, wxT( "Undo inhibit count decremented past zero" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool TOOL_MANAGER::IsUndoInhibited() const
|
|
||||||
{
|
|
||||||
return m_undoInhibit > 0;
|
|
||||||
}
|
|
||||||
|
|
|
@ -30,8 +30,6 @@
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include <math/vector2d.h>
|
|
||||||
|
|
||||||
#include <tool/tool_base.h>
|
#include <tool/tool_base.h>
|
||||||
|
|
||||||
class TOOL_BASE;
|
class TOOL_BASE;
|
||||||
|
@ -301,29 +299,6 @@ public:
|
||||||
return actionList;
|
return actionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Increments the undo inhibit counter. This will indicate that tools
|
|
||||||
* should not create an undo point, as another tool is doing it already,
|
|
||||||
* and considers that its operation is atomic, even if it calls another one
|
|
||||||
* (for example a duplicate calls a move)
|
|
||||||
*/
|
|
||||||
void IncUndoInhibit();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Decrements the inhibit counter. An assert is raised if the counter drops
|
|
||||||
* below zero
|
|
||||||
*/
|
|
||||||
void DecUndoInhibit();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Report if the tool manager has been told at least once that undo
|
|
||||||
* points should not be created. This can be ignored if the undo point
|
|
||||||
* is still required.
|
|
||||||
*
|
|
||||||
* @return true if undo are inhibited
|
|
||||||
*/
|
|
||||||
bool IsUndoInhibited() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct TOOL_STATE;
|
struct TOOL_STATE;
|
||||||
typedef std::pair<TOOL_EVENT_LIST, TOOL_STATE_FUNC> TRANSITION;
|
typedef std::pair<TOOL_EVENT_LIST, TOOL_STATE_FUNC> TRANSITION;
|
||||||
|
@ -451,9 +426,6 @@ private:
|
||||||
|
|
||||||
/// Flag saying if the currently processed event should be passed to other tools.
|
/// Flag saying if the currently processed event should be passed to other tools.
|
||||||
bool m_passEvent;
|
bool m_passEvent;
|
||||||
|
|
||||||
/// Counter of undo inhibitions. When zero, undo is not inhibited
|
|
||||||
int m_undoInhibit;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -123,9 +123,6 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
|
||||||
// cumulative translation
|
// cumulative translation
|
||||||
wxPoint totalMovement( 0, 0 );
|
wxPoint totalMovement( 0, 0 );
|
||||||
|
|
||||||
// make sure nothing is inhibiting undo points
|
|
||||||
bool inhibitUndo = m_toolMgr->IsUndoInhibited();
|
|
||||||
|
|
||||||
// Main loop: keep receiving events
|
// Main loop: keep receiving events
|
||||||
while( OPT_TOOL_EVENT evt = Wait() )
|
while( OPT_TOOL_EVENT evt = Wait() )
|
||||||
{
|
{
|
||||||
|
@ -218,7 +215,7 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Save items, so changes can be undone
|
// Save items, so changes can be undone
|
||||||
if( !inhibitUndo )
|
if( !isUndoInhibited() )
|
||||||
{
|
{
|
||||||
editFrame->OnModify();
|
editFrame->OnModify();
|
||||||
editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED );
|
editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED );
|
||||||
|
@ -248,7 +245,7 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
|
||||||
|
|
||||||
controls->SetAutoPan( true );
|
controls->SetAutoPan( true );
|
||||||
m_dragging = true;
|
m_dragging = true;
|
||||||
m_toolMgr->IncUndoInhibit();
|
incUndoInhibit();
|
||||||
}
|
}
|
||||||
|
|
||||||
selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
||||||
|
@ -260,7 +257,7 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
|
||||||
}
|
}
|
||||||
|
|
||||||
if( m_dragging )
|
if( m_dragging )
|
||||||
m_toolMgr->DecUndoInhibit();
|
decUndoInhibit();
|
||||||
|
|
||||||
m_dragging = false;
|
m_dragging = false;
|
||||||
m_offset.x = 0;
|
m_offset.x = 0;
|
||||||
|
@ -382,7 +379,7 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
|
||||||
wxPoint rotatePoint = getModificationPoint( selection );
|
wxPoint rotatePoint = getModificationPoint( selection );
|
||||||
|
|
||||||
// If it is being dragged, then it is already saved with UR_CHANGED flag
|
// If it is being dragged, then it is already saved with UR_CHANGED flag
|
||||||
if( !m_toolMgr->IsUndoInhibited() )
|
if( !isUndoInhibited() )
|
||||||
{
|
{
|
||||||
editFrame->OnModify();
|
editFrame->OnModify();
|
||||||
editFrame->SaveCopyInUndoList( selection.items, UR_ROTATED, rotatePoint );
|
editFrame->SaveCopyInUndoList( selection.items, UR_ROTATED, rotatePoint );
|
||||||
|
@ -436,7 +433,7 @@ int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent )
|
||||||
|
|
||||||
wxPoint flipPoint = getModificationPoint( selection );
|
wxPoint flipPoint = getModificationPoint( selection );
|
||||||
|
|
||||||
if( !m_toolMgr->IsUndoInhibited() ) // If it is being dragged, then it is already saved with UR_CHANGED flag
|
if( !isUndoInhibited() ) // If it is being dragged, then it is already saved with UR_CHANGED flag
|
||||||
{
|
{
|
||||||
editFrame->OnModify();
|
editFrame->OnModify();
|
||||||
editFrame->SaveCopyInUndoList( selection.items, UR_FLIPPED, flipPoint );
|
editFrame->SaveCopyInUndoList( selection.items, UR_FLIPPED, flipPoint );
|
||||||
|
@ -614,7 +611,7 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent )
|
||||||
|
|
||||||
if( ret == DIALOG_MOVE_EXACT::MOVE_OK )
|
if( ret == DIALOG_MOVE_EXACT::MOVE_OK )
|
||||||
{
|
{
|
||||||
if( !m_toolMgr->IsUndoInhibited() )
|
if( !isUndoInhibited() )
|
||||||
{
|
{
|
||||||
editFrame->OnModify();
|
editFrame->OnModify();
|
||||||
// Record an action of move and rotate
|
// Record an action of move and rotate
|
||||||
|
@ -676,7 +673,7 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
|
||||||
// prevent other tools making undo points while the duplicate is going on
|
// prevent other tools making undo points while the duplicate is going on
|
||||||
// so that if you cancel, you don't get a duplicate object hiding over
|
// so that if you cancel, you don't get a duplicate object hiding over
|
||||||
// the original
|
// the original
|
||||||
m_toolMgr->IncUndoInhibit();
|
incUndoInhibit();
|
||||||
|
|
||||||
std::vector<BOARD_ITEM*> old_items;
|
std::vector<BOARD_ITEM*> old_items;
|
||||||
|
|
||||||
|
@ -731,7 +728,7 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
|
||||||
Main( evt );
|
Main( evt );
|
||||||
|
|
||||||
// and re-enable undos
|
// and re-enable undos
|
||||||
m_toolMgr->DecUndoInhibit();
|
decUndoInhibit();
|
||||||
|
|
||||||
setTransitions();
|
setTransitions();
|
||||||
|
|
||||||
|
|
|
@ -142,6 +142,9 @@ private:
|
||||||
/// Edit module mode flag
|
/// Edit module mode flag
|
||||||
bool m_editModules;
|
bool m_editModules;
|
||||||
|
|
||||||
|
/// Counter of undo inhibitions. When zero, undo is not inhibited.
|
||||||
|
int m_undoInhibit;
|
||||||
|
|
||||||
///> Removes and frees a single BOARD_ITEM.
|
///> Removes and frees a single BOARD_ITEM.
|
||||||
void remove( BOARD_ITEM* aItem );
|
void remove( BOARD_ITEM* aItem );
|
||||||
|
|
||||||
|
@ -173,6 +176,40 @@ private:
|
||||||
|
|
||||||
///> Updates view with the changes in the list.
|
///> Updates view with the changes in the list.
|
||||||
void processChanges( const PICKED_ITEMS_LIST* aList );
|
void processChanges( const PICKED_ITEMS_LIST* aList );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increments the undo inhibit counter. This will indicate that tools
|
||||||
|
* should not create an undo point, as another tool is doing it already,
|
||||||
|
* and considers that its operation is atomic, even if it calls another one
|
||||||
|
* (for example a duplicate calls a move).
|
||||||
|
*/
|
||||||
|
inline void incUndoInhibit()
|
||||||
|
{
|
||||||
|
m_undoInhibit++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrements the inhibit counter. An assert is raised if the counter drops
|
||||||
|
* below zero.
|
||||||
|
*/
|
||||||
|
inline void decUndoInhibit()
|
||||||
|
{
|
||||||
|
m_undoInhibit--;
|
||||||
|
|
||||||
|
wxASSERT_MSG( m_undoInhibit >= 0, wxT( "Undo inhibit count decremented past zero" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report if the tool manager has been told at least once that undo
|
||||||
|
* points should not be created. This can be ignored if the undo point
|
||||||
|
* is still required.
|
||||||
|
*
|
||||||
|
* @return true if undo are inhibited
|
||||||
|
*/
|
||||||
|
inline bool isUndoInhibited() const
|
||||||
|
{
|
||||||
|
return m_undoInhibit > 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue