Preferences: Detect conflict assigning hotkeys already assigned in common

CHANGED: Currently KiCad only checks for hotkey assignment conflicts
within the same program.  However, if a hotkey is already assigned in
"common", it will also assign it to the specific program requested.  When
the hotkey is pressed, the original asignment in "common" will take
precedence and it's action performed instead of the new action.

This MR looks for and detects hotkey assignment conflicts in both the
current program section and the "common" section.

Fixes https://gitlab.com/kicad/code/kicad/issues/1920
This commit is contained in:
PJM 2020-11-29 19:15:28 -08:00 committed by Jon Evans
parent 7c2b66fc2a
commit 21bd1c0f00
1 changed files with 13 additions and 4 deletions

View File

@ -183,14 +183,23 @@ bool HOTKEY_STORE::CheckKeyConflicts( TOOL_ACTION* aAction, long aKey, HOTKEY**
{
wxString sectionName = GetSectionName( aAction );
for( HOTKEY_SECTION& section: m_hk_sections )
// Create a fake "TOOL_ACTION" so we can get the section name for "Common" through the API.
// Simply declaring a wxString with the value "Common" works, but the goal is to futureproof
// the code here as much as possible.
TOOL_ACTION commonAction( "common.Control.Fake", AS_GLOBAL, 0, "", "", "", nullptr );
wxString commonName = GetSectionName( &commonAction );
for( HOTKEY_SECTION& section : m_hk_sections )
{
if( section.m_SectionName != sectionName )
// We can have the same hotkey in multiple sections (i.e. Kicad programs), but if a hotkey
// is in "Common" it can't be in any other section and vice versa.
if( !( section.m_SectionName == sectionName || section.m_SectionName == commonName ) )
continue;
for( HOTKEY& hotkey: section.m_HotKeys )
for( HOTKEY& hotkey : section.m_HotKeys )
{
if( hotkey.m_Actions[ 0 ] == aAction )
if( hotkey.m_Actions[0] == aAction )
continue;
if( hotkey.m_EditKeycode == aKey )