From 594d5c3e34f177836aaa8d345db6aed023031dab Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sat, 26 Jan 2019 07:42:18 -0800 Subject: [PATCH] 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 --- common/tool/action_manager.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/common/tool/action_manager.cpp b/common/tool/action_manager.cpp index 61072ba624..e41f9af5db 100644 --- a/common/tool/action_manager.cpp +++ b/common/tool/action_manager.cpp @@ -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 * * 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 ) - { - m_actionHotKeys[hotkey].push_back( action ); - m_hotkeys[action->GetId()] = hotkey; - } - } + if( hotkey <= 0 ) + continue; -#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 ) + // Second hotkey takes priority as defaults are loaded first and updates + // are loaded after + if( action->GetScope() == AS_GLOBAL && m_actionHotKeys.count( hotkey ) ) { - if( action->GetScope() == AS_GLOBAL ) - ++global_actions_cnt; + 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++; + } } - wxASSERT( global_actions_cnt <= 1 ); + m_actionHotKeys[hotkey].push_back( action ); + m_hotkeys[action->GetId()] = hotkey; + } -#endif /* not NDEBUG */ }