From 391d26d3bf65b7768dfa0b866cdc8a651c14c2b8 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 22 Jan 2014 18:28:08 -0500 Subject: [PATCH] [DolphinWX] Prevent hotkeys from being assigned to more than one button/function. Prior to this commit it was possible to assign the same keycode to more than one button. ie. Say I assigned Open with the hotkey Ctrl+O; well, it was possible to also add it to another function as well, which leads to hotkey clashing. Now, say I assign Open with Ctrl+O, but then assign that same hotkey to Refresh List; it will unbind the hotkey from Open and then assign it to refresh list. --- Source/Core/DolphinWX/HotkeyDlg.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Source/Core/DolphinWX/HotkeyDlg.cpp b/Source/Core/DolphinWX/HotkeyDlg.cpp index 03b40dd286..5fe375c04f 100644 --- a/Source/Core/DolphinWX/HotkeyDlg.cpp +++ b/Source/Core/DolphinWX/HotkeyDlg.cpp @@ -72,6 +72,26 @@ void HotkeyConfigDialog::OnKeyDown(wxKeyEvent& event) } else { + // Check if the hotkey combination was already applied to another button + // and unapply it if necessary. + for (wxButton* btn : m_Button_Hotkeys) + { + // We compare against this to see if we have a duplicate bind attempt. + wxString existingHotkey = btn->GetLabel(); + + wxString tentativeModKey = InputCommon::WXKeymodToString(g_Modkey); + wxString tentativePressedKey = InputCommon::WXKeyToString(g_Pressed); + wxString tentativeHotkey(tentativeModKey + tentativePressedKey); + + // Found a button that already has this binding. Unbind it. + if (tentativeHotkey == existingHotkey) + { + SaveButtonMapping(btn->GetId(), -1, 0); + SetButtonText(btn->GetId(), wxString()); + } + } + + // Proceed to apply the binding to the selected button. SetButtonText(ClickedButton->GetId(), InputCommon::WXKeyToString(g_Pressed), InputCommon::WXKeymodToString(g_Modkey));