pcbnew: overwrite hotkeys cleanly

If user hotkeys do not map all available actions, we still want the most
recent change to be the primary value.  This can happen if the defaults
load a set of hotkeys that are not completely overwritten by the updated
hotkey preferences file.  We assume that the most recent hotkey is what
the user want to map.

Fixes: lp:1778408
* https://bugs.launchpad.net/kicad/+bug/1778408
This commit is contained in:
Seth Hillbrand 2019-01-26 07:42:18 -08:00
parent 4fc692f04b
commit 594d5c3e34
1 changed files with 17 additions and 17 deletions

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
@ -200,28 +201,27 @@ void ACTION_MANAGER::UpdateHotKeys()
TOOL_ACTION* action = actionName.second;
int hotkey = processHotKey( action );
if( hotkey > 0 )
if( hotkey <= 0 )
continue;
// Second hotkey takes priority as defaults are loaded first and updates
// are loaded after
if( action->GetScope() == AS_GLOBAL && m_actionHotKeys.count( hotkey ) )
{
for( auto it = m_actionHotKeys[hotkey].begin();
it != m_actionHotKeys[hotkey].end(); )
{
if( (*it)->GetScope() == AS_GLOBAL )
it = m_actionHotKeys[hotkey].erase( it );
else
it++;
}
}
m_actionHotKeys[hotkey].push_back( action );
m_hotkeys[action->GetId()] = hotkey;
}
}
#ifdef DEBUG
// Check if there are two global actions assigned to the same hotkey
for( const auto& action_list : m_actionHotKeys )
{
int global_actions_cnt = 0;
for( const TOOL_ACTION* action : action_list.second )
{
if( action->GetScope() == AS_GLOBAL )
++global_actions_cnt;
}
wxASSERT( global_actions_cnt <= 1 );
}
#endif /* not NDEBUG */
}