From: <sag...@us...> - 2015-06-03 20:59:44
|
Revision: 5243 http://sourceforge.net/p/modplug/code/5243 Author: saga-games Date: 2015-06-03 20:59:38 +0000 (Wed, 03 Jun 2015) Log Message: ----------- [Imp] Allow more than one shortcut being bound to the same key combination Modified Paths: -------------- trunk/OpenMPT/mptrack/CommandSet.cpp trunk/OpenMPT/mptrack/CommandSet.h trunk/OpenMPT/mptrack/InputHandler.cpp trunk/OpenMPT/mptrack/KeyConfigDlg.cpp Modified: trunk/OpenMPT/mptrack/CommandSet.cpp =================================================================== --- trunk/OpenMPT/mptrack/CommandSet.cpp 2015-06-03 09:55:49 UTC (rev 5242) +++ trunk/OpenMPT/mptrack/CommandSet.cpp 2015-06-03 20:59:38 UTC (rev 5243) @@ -744,12 +744,12 @@ { if (IsCrossContextConflict(kc, conflictCmd.second)) { - report += "Warning! the following commands may conflict:\r\n >" + GetCommandText(conflictCmd.first) + " in " + conflictCmd.second.GetContextText() + "\r\n >" + GetCommandText(cmd) + " in " + kc.GetContextText() + "\r\n\r\n"; + report += "The following commands may conflict:\r\n >" + GetCommandText(conflictCmd.first) + " in " + conflictCmd.second.GetContextText() + "\r\n >" + GetCommandText(cmd) + " in " + kc.GetContextText() + "\r\n\r\n"; Log("%s", report); } else { - Remove(conflictCmd.second, conflictCmd.first); - report += "Removed due to conflict in same context:\r\n >" + GetCommandText(conflictCmd.first) + " in " + conflictCmd.second.GetContextText() + "\r\n\r\n"; + //Remove(conflictCmd.second, conflictCmd.first); + report += "The following commands in same context share the same key combination:\r\n >" + GetCommandText(conflictCmd.first) + " in " + conflictCmd.second.GetContextText() + "\r\n\r\n"; Log("%s", report); } } @@ -1426,22 +1426,21 @@ std::vector<KeyEventType> eventTypes; std::vector<InputTargetContext> contexts; - //Clear map km.clear(); - //Copy commandlist content into map: + // Copy commandlist content into map: for(UINT cmd=0; cmd<kcNumCommands; cmd++) { if(IsDummyCommand((CommandID)cmd)) continue; - for(size_t k=0; k<commands[cmd].kcList.size(); k++) + for(size_t k = 0; k < commands[cmd].kcList.size(); k++) { std::vector<KeyEventType> eventTypes; std::vector<InputTargetContext> contexts; curKc = commands[cmd].kcList[k]; - //Handle keyEventType mask. + // Handle keyEventType mask. if (curKc.EventType() & kKeyEventDown) eventTypes.push_back(kKeyEventDown); if (curKc.EventType() & kKeyEventUp) @@ -1450,7 +1449,7 @@ eventTypes.push_back(kKeyEventRepeat); //ASSERT(eventTypes.GetSize()>0); - //Handle super-contexts (contexts that represent a set of sub contexts) + // Handle super-contexts (contexts that represent a set of sub contexts) if (curKc.Context() == kCtxViewPatterns) { contexts.push_back(kCtxViewPatternsNote); @@ -1466,11 +1465,11 @@ contexts.push_back(curKc.Context()); } - for (size_t cx=0; cx<contexts.size(); cx++) + for (size_t cx = 0; cx < contexts.size(); cx++) { - for (size_t ke=0; ke<eventTypes.size(); ke++) + for (size_t ke = 0; ke < eventTypes.size(); ke++) { - km[KeyCombination(contexts[cx], curKc.Modifier(), curKc.KeyCode(), eventTypes[ke])] = (CommandID)cmd; + km.insert(std::make_pair(KeyCombination(contexts[cx], curKc.Modifier(), curKc.KeyCode(), eventTypes[ke]), (CommandID)cmd)); } } } @@ -1479,8 +1478,8 @@ } -void CCommandSet::Copy(CCommandSet *source) -//----------------------------------------- +void CCommandSet::Copy(const CCommandSet *source) +//---------------------------------------------- { // copy constructors should take care of complexity (I hope) oldSpecs = nullptr; Modified: trunk/OpenMPT/mptrack/CommandSet.h =================================================================== --- trunk/OpenMPT/mptrack/CommandSet.h 2015-06-03 09:55:49 UTC (rev 5242) +++ trunk/OpenMPT/mptrack/CommandSet.h 2015-06-03 20:59:38 UTC (rev 5243) @@ -1233,10 +1233,11 @@ }; #if MPT_COMPILER_MSVC && MPT_MSVC_BEFORE(2010,0) -typedef std::tr1::unordered_map<KeyCombination, CommandID, KeyCombination::hash> KeyMap; +typedef std::tr1::unordered_multimap<KeyCombination, CommandID, KeyCombination::hash> KeyMap; #else -typedef std::unordered_map<KeyCombination, CommandID, KeyCombination::hash> KeyMap; +typedef std::unordered_multimap<KeyCombination, CommandID, KeyCombination::hash> KeyMap; #endif +typedef std::pair<KeyMap::const_iterator, KeyMap::const_iterator> KeyMapRange; //KeyMap @@ -1327,7 +1328,7 @@ CString GetKeyTextFromCommand(CommandID c, UINT key); //Pululation ;) - void Copy(CCommandSet *source); // copy the contents of a commandset into this command set + void Copy(const CCommandSet *source); // copy the contents of a commandset into this command set void GenKeyMap(KeyMap &km); // Generate a keymap from this command set bool SaveFile(const mpt::PathString &filename); bool LoadFile(const mpt::PathString &filename); Modified: trunk/OpenMPT/mptrack/InputHandler.cpp =================================================================== --- trunk/OpenMPT/mptrack/InputHandler.cpp 2015-06-03 09:55:49 UTC (rev 5242) +++ trunk/OpenMPT/mptrack/InputHandler.cpp 2015-06-03 20:59:38 UTC (rev 5243) @@ -56,7 +56,7 @@ if (!bSuccess) { // Load keybindings from resources. - Log("Loading keybindings from resources\n"); + Log(LogDebug, MPT_USTRING("Loading keybindings from resources\n")); bSuccess = activeCommandSet->LoadDefaultKeymap(); if (bSuccess && bNoExistingKbdFileSetting) { @@ -90,7 +90,7 @@ CommandID CInputHandler::GeneralKeyEvent(InputTargetContext context, int code, WPARAM wParam, LPARAM lParam) //---------------------------------------------------------------------------------------------------------- { - KeyMap::const_iterator cmd = keyMap.end(); + KeyMapRange cmd = std::make_pair(keyMap.end(), keyMap.end()); KeyEventType keyEventType; if(code == HC_ACTION) @@ -120,22 +120,25 @@ { // only execute command when the input handler is not locked // and the input is not a consequence of special key interception. - cmd = keyMap.find(KeyCombination(context, modifierMask, wParam, keyEventType)); + cmd = keyMap.equal_range(KeyCombination(context, modifierMask, wParam, keyEventType)); } } if(code == HC_MIDI) { - cmd = keyMap.find(KeyCombination(context, HOTKEYF_MIDI, wParam, kKeyEventDown)); + cmd = keyMap.equal_range(KeyCombination(context, HOTKEYF_MIDI, wParam, kKeyEventDown)); } CommandID executeCommand = kcNull; - if(m_pMainFrm && cmd != keyMap.end()) + if(m_pMainFrm) { - executeCommand = cmd->second; - if(!m_pMainFrm->SendMessage(WM_MOD_KEYCOMMAND, executeCommand, wParam)) + for(KeyMap::const_iterator i = cmd.first; i != cmd.second; i++) { - // Command was not handled, so let Windows process it. - return kcNull; + executeCommand = i->second; + if(!m_pMainFrm->SendMessage(WM_MOD_KEYCOMMAND, executeCommand, wParam)) + { + // Command was not handled, so let Windows process it. + return kcNull; + } } } @@ -148,19 +151,22 @@ { if(InterceptSpecialKeys(nChar, nFlags, false)) return kcNull; - KeyMap::const_iterator cmd = keyMap.find(KeyCombination(context, modifierMask, nChar, keyEventType)); + KeyMapRange cmd = keyMap.equal_range(KeyCombination(context, modifierMask, nChar, keyEventType)); CommandID executeCommand = kcNull; if(pSourceWnd == nullptr) pSourceWnd = m_pMainFrm; //by default, send command message to main frame. - if(pSourceWnd && cmd != keyMap.end()) + if(pSourceWnd != nullptr) { - executeCommand = cmd->second; - if(!pSourceWnd->SendMessage(WM_MOD_KEYCOMMAND, executeCommand, nChar)) + for(KeyMap::const_iterator i = cmd.first; i != cmd.second; i++) { - // Command was not handled, so let Windows process it. - return kcNull; + executeCommand = i->second; + if(!pSourceWnd->SendMessage(WM_MOD_KEYCOMMAND, executeCommand, nChar)) + { + // Command was not handled, so let Windows process it. + return kcNull; + } } } @@ -340,11 +346,11 @@ void CInputHandler::LogModifiers(UINT mask) //----------------------------------------- { - Log("----------------------------------\n"); - if (mask & HOTKEYF_CONTROL) Log("Ctrl On"); else Log("Ctrl --"); - if (mask & HOTKEYF_SHIFT) Log("\tShft On"); else Log("\tShft --"); - if (mask & HOTKEYF_ALT) Log("\tAlt On\n"); else Log("\tAlt --\n"); - if (mask & HOTKEYF_EXT) Log("\tWin On\n"); else Log("\tWin --\n"); // Feature: use Windows keys as modifier keys + Log(LogDebug, MPT_USTRING("----------------------------------\n")); + if (mask & HOTKEYF_CONTROL) Log(LogDebug, MPT_USTRING("Ctrl On")); else Log(LogDebug, MPT_USTRING("Ctrl --")); + if (mask & HOTKEYF_SHIFT) Log(LogDebug, MPT_USTRING("\tShft On")); else Log(LogDebug, MPT_USTRING("\tShft --")); + if (mask & HOTKEYF_ALT) Log(LogDebug, MPT_USTRING("\tAlt On\n")); else Log(LogDebug, MPT_USTRING("\tAlt --\n")); + if (mask & HOTKEYF_EXT) Log(LogDebug, MPT_USTRING("\tWin On\n")); else Log(LogDebug, MPT_USTRING("\tWin --\n")); // Feature: use Windows keys as modifier keys } Modified: trunk/OpenMPT/mptrack/KeyConfigDlg.cpp =================================================================== --- trunk/OpenMPT/mptrack/KeyConfigDlg.cpp 2015-06-03 09:55:49 UTC (rev 5242) +++ trunk/OpenMPT/mptrack/KeyConfigDlg.cpp 2015-06-03 20:59:38 UTC (rev 5243) @@ -776,18 +776,24 @@ std::pair<CommandID, KeyCombination> conflictCmd; if((conflictCmd = plocalCmdSet->IsConflicting(kc, cmd)).first != kcNull && conflictCmd.first != cmd - && !plocalCmdSet->IsCrossContextConflict(kc, conflictCmd.second) - && Reporting::Confirm("New shortcut (" + kc.GetKeyText() + ") conflicts with " + plocalCmdSet->GetCommandText(conflictCmd.first) + " in " + conflictCmd.second.GetContextText() + ".\nDelete the other shortcut and keep the new one?", MPT_USTRING("Shortcut Conflict"), false, false, this) == cnfNo) + && !plocalCmdSet->IsCrossContextConflict(kc, conflictCmd.second)) { - // Restore original choice - add = false; - if(m_nCurKeyChoice >= 0 && m_nCurKeyChoice < plocalCmdSet->GetKeyListSize(cmd)) + ConfirmAnswer delOld = Reporting::Confirm("New shortcut (" + kc.GetKeyText() + ") has the same key combination as " + plocalCmdSet->GetCommandText(conflictCmd.first) + " in " + conflictCmd.second.GetContextText() + ".\nDo you want to delete the other shortcut, only keeping the new one?", "Shortcut Conflict", true, false, this); + if(delOld == cnfYes) { - KeyCombination origKc = plocalCmdSet->GetKey(cmd, m_nCurKeyChoice); - m_eCustHotKey.SetKey(origKc.Modifier(), origKc.KeyCode()); - } else + plocalCmdSet->Remove(conflictCmd.second, conflictCmd.first); + } else if(delOld == cnfCancel) { - m_eCustHotKey.SetWindowText(_T("")); + // Cancel altogther; restore original choice + add = false; + if(m_nCurKeyChoice >= 0 && m_nCurKeyChoice < plocalCmdSet->GetKeyListSize(cmd)) + { + KeyCombination origKc = plocalCmdSet->GetKey(cmd, m_nCurKeyChoice); + m_eCustHotKey.SetKey(origKc.Modifier(), origKc.KeyCode()); + } else + { + m_eCustHotKey.SetWindowText(_T("")); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |