Fixed an assert when footprint viewer was closed before the pcbnew window.
This commit is contained in:
parent
6983f90b9f
commit
e9921d8eea
|
@ -37,15 +37,25 @@ ACTION_MANAGER::ACTION_MANAGER( TOOL_MANAGER* aToolManager ) :
|
|||
{
|
||||
// Register known actions
|
||||
std::list<TOOL_ACTION*>& actionList = GetActionList();
|
||||
|
||||
BOOST_FOREACH( TOOL_ACTION* action, actionList )
|
||||
RegisterAction( action );
|
||||
{
|
||||
if( action->m_id == -1 )
|
||||
action->m_id = MakeActionId( action->m_name );
|
||||
|
||||
RegisterAction( new TOOL_ACTION( *action ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ACTION_MANAGER::~ACTION_MANAGER()
|
||||
{
|
||||
while( !m_actionIdIndex.empty() )
|
||||
UnregisterAction( m_actionIdIndex.begin()->second );
|
||||
while( !m_actionNameIndex.empty() )
|
||||
{
|
||||
TOOL_ACTION* action = m_actionNameIndex.begin()->second;
|
||||
UnregisterAction( action );
|
||||
delete action;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -57,24 +67,19 @@ void ACTION_MANAGER::RegisterAction( TOOL_ACTION* aAction )
|
|||
|
||||
// TOOL_ACTIONs must have unique names & ids
|
||||
assert( m_actionNameIndex.find( aAction->m_name ) == m_actionNameIndex.end() );
|
||||
assert( m_actionIdIndex.find( aAction->m_id ) == m_actionIdIndex.end() );
|
||||
|
||||
if( aAction->m_id == -1 )
|
||||
aAction->m_id = MakeActionId( aAction->m_name );
|
||||
|
||||
m_actionNameIndex[aAction->m_name] = aAction;
|
||||
m_actionIdIndex[aAction->m_id] = aAction;
|
||||
}
|
||||
|
||||
|
||||
void ACTION_MANAGER::UnregisterAction( TOOL_ACTION* aAction )
|
||||
{
|
||||
m_actionNameIndex.erase( aAction->m_name );
|
||||
m_actionIdIndex.erase( aAction->m_id );
|
||||
int hotkey = GetHotKey( *aAction );
|
||||
|
||||
if( aAction->HasHotKey() )
|
||||
if( hotkey )
|
||||
{
|
||||
std::list<TOOL_ACTION*>& actions = m_actionHotKeys[aAction->m_currentHotKey];
|
||||
std::list<TOOL_ACTION*>& actions = m_actionHotKeys[hotkey];
|
||||
std::list<TOOL_ACTION*>::iterator action = std::find( actions.begin(), actions.end(), aAction );
|
||||
|
||||
if( action != actions.end() )
|
||||
|
@ -176,19 +181,31 @@ bool ACTION_MANAGER::RunHotKey( int aHotKey ) const
|
|||
}
|
||||
|
||||
|
||||
int ACTION_MANAGER::GetHotKey( const TOOL_ACTION& aAction ) const
|
||||
{
|
||||
std::map<int, int>::const_iterator it = m_hotkeys.find( aAction.GetId() );
|
||||
|
||||
if( it == m_hotkeys.end() )
|
||||
return 0;
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
void ACTION_MANAGER::UpdateHotKeys()
|
||||
{
|
||||
m_actionHotKeys.clear();
|
||||
std::list<TOOL_ACTION*>& actions = GetActionList();
|
||||
m_hotkeys.clear();
|
||||
|
||||
for( std::list<TOOL_ACTION*>::iterator it = actions.begin(); it != actions.end(); ++it )
|
||||
BOOST_FOREACH( TOOL_ACTION* action, m_actionNameIndex | boost::adaptors::map_values )
|
||||
{
|
||||
TOOL_ACTION* aAction = *it;
|
||||
|
||||
int hotkey = processHotKey( aAction, true );
|
||||
int hotkey = processHotKey( action );
|
||||
|
||||
if( hotkey > 0 )
|
||||
m_actionHotKeys[hotkey].push_back( aAction );
|
||||
{
|
||||
m_actionHotKeys[hotkey].push_back( action );
|
||||
m_hotkeys[action->GetId()] = hotkey;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
@ -209,14 +226,9 @@ void ACTION_MANAGER::UpdateHotKeys()
|
|||
}
|
||||
|
||||
|
||||
int ACTION_MANAGER::processHotKey( TOOL_ACTION* aAction, bool aForceUpdate )
|
||||
int ACTION_MANAGER::processHotKey( TOOL_ACTION* aAction )
|
||||
{
|
||||
int hotkey = 0;
|
||||
|
||||
if( aForceUpdate )
|
||||
hotkey = aAction->getDefaultHotKey();
|
||||
else
|
||||
hotkey = aAction->GetHotKey();
|
||||
int hotkey = aAction->getDefaultHotKey();
|
||||
|
||||
if( ( hotkey & TOOL_ACTION::LEGACY_HK ) )
|
||||
{
|
||||
|
@ -251,8 +263,6 @@ int ACTION_MANAGER::processHotKey( TOOL_ACTION* aAction, bool aForceUpdate )
|
|||
{
|
||||
hotkey = 0;
|
||||
}
|
||||
|
||||
aAction->setHotKey( hotkey );
|
||||
}
|
||||
|
||||
return hotkey;
|
||||
|
|
|
@ -198,16 +198,18 @@ TOOL_MANAGER* CONTEXT_MENU::getToolManager()
|
|||
|
||||
void CONTEXT_MENU::updateHotKeys()
|
||||
{
|
||||
TOOL_MANAGER* toolMgr = getToolManager();
|
||||
|
||||
for( std::map<int, const TOOL_ACTION*>::const_iterator it = m_toolActions.begin();
|
||||
it != m_toolActions.end(); ++it )
|
||||
{
|
||||
int id = it->first;
|
||||
const TOOL_ACTION& action = *it->second;
|
||||
int key = toolMgr->GetHotKey( action ) & ~MD_MODIFIER_MASK;
|
||||
|
||||
if( action.HasHotKey() )
|
||||
if( key )
|
||||
{
|
||||
int key = action.GetHotKey() & ~MD_MODIFIER_MASK;
|
||||
int mod = action.GetHotKey() & MD_MODIFIER_MASK;
|
||||
int mod = toolMgr->GetHotKey( action ) & MD_MODIFIER_MASK;
|
||||
int flags = 0;
|
||||
wxMenuItem* item = FindChildItem( id );
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ TOOL_ACTION::TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope,
|
|||
int aDefaultHotKey, const wxString aMenuItem, const wxString& aMenuDesc,
|
||||
const BITMAP_OPAQUE* aIcon, TOOL_ACTION_FLAGS aFlags, void* aParam ) :
|
||||
m_name( aName ), m_scope( aScope ), m_defaultHotKey( aDefaultHotKey ),
|
||||
m_currentHotKey( aDefaultHotKey ), m_menuItem( aMenuItem ), m_menuDescription( aMenuDesc ),
|
||||
m_menuItem( aMenuItem ), m_menuDescription( aMenuDesc ),
|
||||
m_icon( aIcon ), m_id( -1 ), m_flags( aFlags ), m_param( aParam )
|
||||
{
|
||||
ACTION_MANAGER::GetActionList().push_back( this );
|
||||
|
|
|
@ -332,6 +332,12 @@ void TOOL_MANAGER::RunAction( const TOOL_ACTION& aAction, bool aNow, void* aPara
|
|||
}
|
||||
|
||||
|
||||
int TOOL_MANAGER::GetHotKey( const TOOL_ACTION& aAction )
|
||||
{
|
||||
return m_actionMgr->GetHotKey( aAction );
|
||||
}
|
||||
|
||||
|
||||
void TOOL_MANAGER::UpdateHotKeys()
|
||||
{
|
||||
m_actionMgr->UpdateHotKeys();
|
||||
|
|
|
@ -90,6 +90,13 @@ public:
|
|||
*/
|
||||
bool RunHotKey( int aHotKey ) const;
|
||||
|
||||
/**
|
||||
* Function GetHotKey()
|
||||
* Returns the hot key associated with a given action or 0 if there is none.
|
||||
* @param aAction is the queried action.
|
||||
*/
|
||||
int GetHotKey( const TOOL_ACTION& aAction ) const;
|
||||
|
||||
/**
|
||||
* Function UpdateHotKeys()
|
||||
* Updates TOOL_ACTIONs hot key assignment according to the current frame's Hot Key Editor settings.
|
||||
|
@ -104,7 +111,6 @@ public:
|
|||
*/
|
||||
static std::list<TOOL_ACTION*>& GetActionList()
|
||||
{
|
||||
// TODO I am afraid this approach won't work when we reach multitab version of kicad.
|
||||
static std::list<TOOL_ACTION*> actionList;
|
||||
|
||||
return actionList;
|
||||
|
@ -113,23 +119,20 @@ public:
|
|||
private:
|
||||
///> Resolves a reference to legacy hot key settings to a particular hot key.
|
||||
///> @param aAction is the action to be resolved.
|
||||
///> @param aForceUpdate determines whether it should be resolved only when the current hot key
|
||||
///> setting contains a reference to legacy settings, or update the hot key basing on the
|
||||
///> originally assigned reference.
|
||||
int processHotKey( TOOL_ACTION* aAction, bool aForceUpdate = false );
|
||||
int processHotKey( TOOL_ACTION* aAction );
|
||||
|
||||
///> Tool manager needed to run actions
|
||||
TOOL_MANAGER* m_toolMgr;
|
||||
|
||||
///> Map for indexing actions by their IDs
|
||||
std::map<int, TOOL_ACTION*> m_actionIdIndex;
|
||||
|
||||
///> Map for indexing actions by their names
|
||||
std::map<std::string, TOOL_ACTION*> m_actionNameIndex;
|
||||
|
||||
///> Map for indexing actions by their hotkeys
|
||||
typedef std::map<int, std::list<TOOL_ACTION*> > HOTKEY_LIST;
|
||||
HOTKEY_LIST m_actionHotKeys;
|
||||
|
||||
///> Quick action<->hot key lookup
|
||||
std::map<int, int> m_hotkeys;
|
||||
};
|
||||
|
||||
#endif /* ACTION_MANAGER_H_ */
|
||||
|
|
|
@ -87,25 +87,12 @@ public:
|
|||
return m_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function GetHotKey()
|
||||
* Returns the associated hot key.
|
||||
*/
|
||||
int GetHotKey() const
|
||||
{
|
||||
return m_currentHotKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function HasHotKey()
|
||||
* Checks if the action has a hot key assigned.
|
||||
*
|
||||
* @return True if there is a hot key assigned, false otherwise.
|
||||
*/
|
||||
bool HasHotKey() const
|
||||
{
|
||||
return m_currentHotKey != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function MakeEvent()
|
||||
|
@ -190,6 +177,7 @@ public:
|
|||
|
||||
return aHotKey | LEGACY_HK;
|
||||
}
|
||||
|
||||
private:
|
||||
friend class ACTION_MANAGER;
|
||||
|
||||
|
@ -200,15 +188,6 @@ private:
|
|||
return m_defaultHotKey;
|
||||
}
|
||||
|
||||
/// Changes the assigned hot key.
|
||||
void setHotKey( int aHotKey )
|
||||
{
|
||||
// it is not the right moment to use legacy hot key, it should be given in the object definition
|
||||
assert( ( aHotKey & LEGACY_HK ) == 0 );
|
||||
|
||||
m_currentHotKey = aHotKey;
|
||||
}
|
||||
|
||||
/// Name of the action (convention is: app.[tool.]action.name)
|
||||
std::string m_name;
|
||||
|
||||
|
@ -218,9 +197,6 @@ private:
|
|||
/// Default hot key that activates the action.
|
||||
const int m_defaultHotKey;
|
||||
|
||||
/// Custom assigned hot key that activates the action.
|
||||
int m_currentHotKey;
|
||||
|
||||
/// Menu entry text
|
||||
wxString m_menuItem;
|
||||
|
||||
|
|
|
@ -146,6 +146,9 @@ public:
|
|||
RunAction( aAction, aNow, (void*) NULL );
|
||||
}
|
||||
|
||||
///> @copydoc ACTION_MANAGER::GetHotKey()
|
||||
int GetHotKey( const TOOL_ACTION& aAction );
|
||||
|
||||
///> @copydoc ACTION_MANAGER::UpdateHotKeys()
|
||||
void UpdateHotKeys();
|
||||
|
||||
|
|
Loading…
Reference in New Issue