Make tool init order dependent on registration order
Previously, init order depended on the ordering of the tool state map, which is opaque from the point of view of registration. This makes it challenging to make one tool's init depend on another. With this change, registration order defines init order.
This commit is contained in:
parent
4c5db9681c
commit
3b252c696d
|
@ -236,6 +236,8 @@ void TOOL_MANAGER::RegisterTool( TOOL_BASE* aTool )
|
|||
wxASSERT_MSG( m_toolTypes.find( typeid( *aTool ).name() ) == m_toolTypes.end(),
|
||||
wxT( "Adding two tools of the same type may result in unexpected behaviour.") );
|
||||
|
||||
m_toolOrder.push_back( aTool );
|
||||
|
||||
TOOL_STATE* st = new TOOL_STATE( aTool );
|
||||
|
||||
m_toolState[aTool] = st;
|
||||
|
@ -550,10 +552,11 @@ void TOOL_MANAGER::ResetTools( TOOL_BASE::RESET_REASON aReason )
|
|||
|
||||
void TOOL_MANAGER::InitTools()
|
||||
{
|
||||
for( auto it = m_toolState.begin(); it != m_toolState.end(); /* iteration in the loop */ )
|
||||
for( TOOL_VEC::iterator it = m_toolOrder.begin(); it != m_toolOrder.end(); /* iter inside */ )
|
||||
{
|
||||
TOOL_BASE* tool = it->first;
|
||||
TOOL_STATE* state = it->second;
|
||||
TOOL_BASE* tool = *it;
|
||||
wxASSERT( m_toolState.count( tool ) );
|
||||
TOOL_STATE* state = m_toolState[tool];
|
||||
setActiveState( state );
|
||||
++it; // keep the iterator valid if the element is going to be erased
|
||||
|
||||
|
|
|
@ -63,6 +63,7 @@ public:
|
|||
typedef std::map<std::string, TOOL_STATE*> NAME_STATE_MAP;
|
||||
typedef std::map<TOOL_ID, TOOL_STATE*> ID_STATE_MAP;
|
||||
typedef std::list<TOOL_ID> ID_LIST;
|
||||
typedef std::vector<TOOL_BASE*> TOOL_VEC;
|
||||
|
||||
/**
|
||||
* Generates a unique ID from for a tool with given name.
|
||||
|
@ -525,6 +526,9 @@ private:
|
|||
*/
|
||||
void setActiveState( TOOL_STATE* aState );
|
||||
|
||||
/// List of tools in the order they were registered
|
||||
TOOL_VEC m_toolOrder;
|
||||
|
||||
/// Index of registered tools current states, associated by tools' objects.
|
||||
TOOL_STATE_MAP m_toolState;
|
||||
|
||||
|
|
Loading…
Reference in New Issue