From: <sv...@op...> - 2024-09-17 21:59:06
|
Author: sagamusix Date: Tue Sep 17 23:58:54 2024 New Revision: 21597 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=21597 Log: [Mod/Fix] Key handling: Redefine kcNull as 0 instead of -1. It creates an extra dummy command list entry, but for views that don't handle the WM_MOD_KEYCOMMAND, this now allows their unhandled SendMessage return value to be interpreted as kcNull instead of kcFirst. [Imp] Key map loading: When adding new default key bindings, allow multiple new bindings to be added for the same command. Modified: trunk/OpenMPT/mptrack/CommandSet.cpp trunk/OpenMPT/mptrack/CommandSet.h trunk/OpenMPT/mptrack/KeyConfigDlg.cpp Modified: trunk/OpenMPT/mptrack/CommandSet.cpp ============================================================================== --- trunk/OpenMPT/mptrack/CommandSet.cpp Tue Sep 17 23:58:22 2024 (r21596) +++ trunk/OpenMPT/mptrack/CommandSet.cpp Tue Sep 17 23:58:54 2024 (r21597) @@ -563,6 +563,7 @@ } CommandDefinitions[] = // clang-format off { + {KeyCommand::Dummy, kcNull, _T("")}, {1001, kcPatternRecord, _T("Enable Recording")}, {1002, kcPatternPlayRow, _T("Play Row")}, {1003, kcCursorCopy, _T("Quick Copy")}, @@ -1428,7 +1429,7 @@ #ifdef MPT_BUILD_DEBUG // Ensure that every visible command has a unique ID - for(size_t i = 0; i < kcNumCommands; i++) + for(size_t i = kcFirst; i < kcNumCommands; i++) { if(m_commands[i].ID() != 0 || !m_commands[i].IsHidden()) { @@ -1499,7 +1500,7 @@ { // In the first pass, only look for conflicts in the same context, since // such conflicts are errors. Cross-context conflicts only emit warnings. - for(int curCmd = 0; curCmd < kcNumCommands; curCmd++) + for(int curCmd = kcFirst; curCmd < kcNumCommands; curCmd++) { if(m_commands[curCmd].IsDummy()) continue; @@ -2012,7 +2013,7 @@ { //propagate to InstrumentView const auto newCmd = translatedCmds[std::distance(std::begin(propagateCmds), propCmd)]; - if(0 <= inCmd && inCmd < kcNumCommands) + if(kcFirst <= inCmd && inCmd < kcNumCommands) { m_commands[newCmd].kcList.reserve(m_commands[inCmd].kcList.size()); for(auto kc : m_commands[inCmd].kcList) @@ -2062,7 +2063,7 @@ const bool allowDupes = TrackerSettings::Instance().MiscAllowMultipleCommandsPerKey; // Copy commandlist content into map: - for(UINT cmd = 0; cmd < kcNumCommands; cmd++) + for(UINT cmd = kcFirst; cmd < kcNumCommands; cmd++) { if(m_commands[cmd].IsDummy()) continue; @@ -2268,7 +2269,7 @@ } // Error checking - if(cmd < 0 || cmd >= kcNumCommands || kc.Context() >= kCtxMaxInputContexts || tokens.size() < 4) + if(cmd < kcFirst || cmd >= kcNumCommands || kc.Context() >= kCtxMaxInputContexts || tokens.size() < 4) { errorCount++; if (errorCount < 10) @@ -2347,6 +2348,7 @@ std::vector<HKL> layouts(GetKeyboardLayoutList(0, nullptr)); GetKeyboardLayoutList(static_cast<int>(layouts.size()), layouts.data()); + CommandID lastAdded = kcNull; for(const auto &kb : DefaultKeybindings) { if(onlyCommandsAfterVersion != Version{}) @@ -2357,7 +2359,7 @@ // Do not map shortcuts that already have custom keys assigned. // In particular with default note keys, this can create awkward keymaps when loading // e.g. an IT-style keymap and it contains two keys mapped to the same notes. - if(GetKeyListSize(kb.cmd) != 0) + if(kb.cmd != lastAdded && GetKeyListSize(kb.cmd) != 0) continue; } @@ -2394,13 +2396,14 @@ m_commands[kb.cmd].kcList.push_back(kc); EnforceAll(kc, kb.cmd, true); + lastAdded = kb.cmd; } } CommandID CCommandSet::FindCmd(uint32 uid) const { - for(int i = 0; i < kcNumCommands; i++) + for(int i = kcFirst; i < kcNumCommands; i++) { if(m_commands[i].ID() == uid) return static_cast<CommandID>(i); Modified: trunk/OpenMPT/mptrack/CommandSet.h ============================================================================== --- trunk/OpenMPT/mptrack/CommandSet.h Tue Sep 17 23:58:22 2024 (r21596) +++ trunk/OpenMPT/mptrack/CommandSet.h Tue Sep 17 23:58:54 2024 (r21597) @@ -67,7 +67,7 @@ { kcCommandSetNumNotes = 59, // kcVPEndNotes - kcVPStartNotes - kcNull = -1, + kcNull = 0, // Must be same as unhandled SendMessage result kcFirst, //Global Modified: trunk/OpenMPT/mptrack/KeyConfigDlg.cpp ============================================================================== --- trunk/OpenMPT/mptrack/KeyConfigDlg.cpp Tue Sep 17 23:58:22 2024 (r21596) +++ trunk/OpenMPT/mptrack/KeyConfigDlg.cpp Tue Sep 17 23:58:54 2024 (r21597) @@ -662,7 +662,7 @@ m_cmbKeyChoice.ResetContent(); int numChoices = m_localCmdSet->GetKeyListSize(cmd); - if((cmd < kcNumCommands) && (numChoices > 0)) + if(cmd >= kcFirst && cmd < kcNumCommands && numChoices > 0) { for(int i = 0; i < numChoices; i++) { |