From 2979dc7d157a4c17fcc985047689f760ced8a666 Mon Sep 17 00:00:00 2001 From: Masaru Iritani <25241373+masaru-iritani@users.noreply.github.com> Date: Thu, 15 Aug 2024 17:05:16 +0900 Subject: [PATCH] [KBM] Convert `RemapBufferRow` to a struct with descriptive field names (#32545) Use struct for RemapBufferRow Co-authored-by: Stefan Markovic --- .../BufferValidationHelpers.cpp | 38 ++++++++--------- .../EditShortcutsWindow.cpp | 2 +- .../KeyDropDownControl.cpp | 10 ++--- .../LoadingAndSavingRemappingHelper.cpp | 24 +++++------ .../ShortcutControl.cpp | 42 +++++++++---------- .../SingleKeyRemapControl.cpp | 2 +- .../BufferValidationTests.cpp | 40 +++++++++--------- src/modules/keyboardmanager/common/Shortcut.h | 10 ++++- 8 files changed, 87 insertions(+), 81 deletions(-) diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/BufferValidationHelpers.cpp b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/BufferValidationHelpers.cpp index 98dfdd5ff2..4557c73430 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/BufferValidationHelpers.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/BufferValidationHelpers.cpp @@ -29,9 +29,9 @@ namespace BufferValidationHelpers if (selectedKeyCode != -1) { // Check if the value being set is the same as the other column - if (remapBuffer[rowIndex].first[std::abs(colIndex - 1)].index() == 0) + if (remapBuffer[rowIndex].mapping[std::abs(colIndex - 1)].index() == 0) { - DWORD otherColumnKeyCode = std::get(remapBuffer[rowIndex].first[std::abs(colIndex - 1)]); + DWORD otherColumnKeyCode = std::get(remapBuffer[rowIndex].mapping[std::abs(colIndex - 1)]); if (otherColumnKeyCode == selectedKeyCode || IsKeyRemappingToItsCombinedKey(selectedKeyCode, otherColumnKeyCode)) { errorType = ShortcutErrorType::MapToSameKey; @@ -47,9 +47,9 @@ namespace BufferValidationHelpers { if (i != rowIndex) { - if (remapBuffer[i].first[colIndex].index() == 0) + if (remapBuffer[i].mapping[colIndex].index() == 0) { - ShortcutErrorType result = EditorHelpers::DoKeysOverlap(std::get(remapBuffer[i].first[colIndex]), selectedKeyCode); + ShortcutErrorType result = EditorHelpers::DoKeysOverlap(std::get(remapBuffer[i].mapping[colIndex]), selectedKeyCode); if (result != ShortcutErrorType::NoError) { errorType = result; @@ -65,17 +65,17 @@ namespace BufferValidationHelpers // If there is no error, set the buffer if (errorType == ShortcutErrorType::NoError) { - remapBuffer[rowIndex].first[colIndex] = (DWORD)selectedKeyCode; + remapBuffer[rowIndex].mapping[colIndex] = (DWORD)selectedKeyCode; } else { - remapBuffer[rowIndex].first[colIndex] = (DWORD)0; + remapBuffer[rowIndex].mapping[colIndex] = (DWORD)0; } } else { // Reset to null if the key is not found - remapBuffer[rowIndex].first[colIndex] = (DWORD)0; + remapBuffer[rowIndex].mapping[colIndex] = (DWORD)0; } return errorType; @@ -245,9 +245,9 @@ namespace BufferValidationHelpers if (tempShortcut.index() == 1) { // If shortcut to shortcut - if (remapBuffer[rowIndex].first[std::abs(colIndex - 1)].index() == 1) + if (remapBuffer[rowIndex].mapping[std::abs(colIndex - 1)].index() == 1) { - auto& shortcut = std::get(remapBuffer[rowIndex].first[std::abs(colIndex - 1)]); + auto& shortcut = std::get(remapBuffer[rowIndex].mapping[std::abs(colIndex - 1)]); if (shortcut == std::get(tempShortcut) && EditorHelpers::IsValidShortcut(shortcut) && EditorHelpers::IsValidShortcut(std::get(tempShortcut))) { errorType = ShortcutErrorType::MapToSameShortcut; @@ -259,9 +259,9 @@ namespace BufferValidationHelpers else { // If key to key - if (remapBuffer[rowIndex].first[std::abs(colIndex - 1)].index() == 0) + if (remapBuffer[rowIndex].mapping[std::abs(colIndex - 1)].index() == 0) { - DWORD otherColumnKeyCode = std::get(remapBuffer[rowIndex].first[std::abs(colIndex - 1)]); + DWORD otherColumnKeyCode = std::get(remapBuffer[rowIndex].mapping[std::abs(colIndex - 1)]); DWORD shortcutKeyCode = std::get(tempShortcut); if ((otherColumnKeyCode == shortcutKeyCode || IsKeyRemappingToItsCombinedKey(otherColumnKeyCode, shortcutKeyCode)) && otherColumnKeyCode != NULL && shortcutKeyCode != NULL) { @@ -277,7 +277,7 @@ namespace BufferValidationHelpers // Check if the key is already remapped to something else for the same target app for (int i = 0; i < remapBuffer.size(); i++) { - std::wstring currAppName = remapBuffer[i].second; + std::wstring currAppName = remapBuffer[i].appName; std::transform(currAppName.begin(), currAppName.end(), currAppName.begin(), towlower); if (i != rowIndex && currAppName == appName) @@ -285,23 +285,23 @@ namespace BufferValidationHelpers ShortcutErrorType result = ShortcutErrorType::NoError; if (!isHybridControl) { - result = EditorHelpers::DoShortcutsOverlap(std::get(remapBuffer[i].first[colIndex]), std::get(tempShortcut)); + result = EditorHelpers::DoShortcutsOverlap(std::get(remapBuffer[i].mapping[colIndex]), std::get(tempShortcut)); } else { - if (tempShortcut.index() == 0 && remapBuffer[i].first[colIndex].index() == 0) + if (tempShortcut.index() == 0 && remapBuffer[i].mapping[colIndex].index() == 0) { - if (std::get(tempShortcut) != NULL && std::get(remapBuffer[i].first[colIndex]) != NULL) + if (std::get(tempShortcut) != NULL && std::get(remapBuffer[i].mapping[colIndex]) != NULL) { - result = EditorHelpers::DoKeysOverlap(std::get(remapBuffer[i].first[colIndex]), std::get(tempShortcut)); + result = EditorHelpers::DoKeysOverlap(std::get(remapBuffer[i].mapping[colIndex]), std::get(tempShortcut)); } } - else if (tempShortcut.index() == 1 && remapBuffer[i].first[colIndex].index() == 1) + else if (tempShortcut.index() == 1 && remapBuffer[i].mapping[colIndex].index() == 1) { - auto& shortcut = std::get(remapBuffer[i].first[colIndex]); + auto& shortcut = std::get(remapBuffer[i].mapping[colIndex]); if (EditorHelpers::IsValidShortcut(std::get(tempShortcut)) && EditorHelpers::IsValidShortcut(shortcut)) { - result = EditorHelpers::DoShortcutsOverlap(std::get(remapBuffer[i].first[colIndex]), std::get(tempShortcut)); + result = EditorHelpers::DoShortcutsOverlap(std::get(remapBuffer[i].mapping[colIndex]), std::get(tempShortcut)); } } // Other scenarios not possible since key to shortcut is with key to key, and shortcut to key is with shortcut to shortcut diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/EditShortcutsWindow.cpp b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/EditShortcutsWindow.cpp index 149f3de7d5..e36bcf4d7c 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/EditShortcutsWindow.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/EditShortcutsWindow.cpp @@ -348,7 +348,7 @@ inline void CreateEditShortcutsWindowImpl(HINSTANCE hInst, KBMEditor::KeyboardMa auto indexToDelete = -1; for (int i = 0; i < ShortcutControl::shortcutRemapBuffer.size(); i++) { - auto tempShortcut = std::get(ShortcutControl::shortcutRemapBuffer[i].first[0]); + auto tempShortcut = std::get(ShortcutControl::shortcutRemapBuffer[i].mapping[0]); if (tempShortcut.ToHstringVK() == keysForShortcutToEdit) { indexToDelete = i; diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/KeyDropDownControl.cpp b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/KeyDropDownControl.cpp index e83c55a073..5eb65e3266 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/KeyDropDownControl.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/KeyDropDownControl.cpp @@ -281,19 +281,19 @@ void KeyDropDownControl::SetSelectionHandler(StackPanel& table, StackPanel row, std::vector selectedKeyCodes = GetSelectedCodesFromStackPanel(parent); if (!isHybridControl) { - std::get(shortcutRemapBuffer[validationResult.second].first[colIndex]).SetKeyCodes(selectedKeyCodes); + std::get(shortcutRemapBuffer[validationResult.second].mapping[colIndex]).SetKeyCodes(selectedKeyCodes); } else { // If exactly one key is selected consider it to be a key remap if (GetNumberOfSelectedKeys(selectedKeyCodes) == 1) { - shortcutRemapBuffer[validationResult.second].first[colIndex] = (DWORD)selectedKeyCodes[0]; + shortcutRemapBuffer[validationResult.second].mapping[colIndex] = (DWORD)selectedKeyCodes[0]; } else { // Assign instead of setting the value in the buffer since the previous value may not be a Shortcut - shortcutRemapBuffer[validationResult.second].first[colIndex] = Shortcut(selectedKeyCodes); + shortcutRemapBuffer[validationResult.second].mapping[colIndex] = Shortcut(selectedKeyCodes); } } @@ -305,11 +305,11 @@ void KeyDropDownControl::SetSelectionHandler(StackPanel& table, StackPanel row, std::transform(lowercaseDefAppName.begin(), lowercaseDefAppName.end(), lowercaseDefAppName.begin(), towlower); if (newText == lowercaseDefAppName) { - shortcutRemapBuffer[validationResult.second].second = L""; + shortcutRemapBuffer[validationResult.second].appName = L""; } else { - shortcutRemapBuffer[validationResult.second].second = targetApp.Text().c_str(); + shortcutRemapBuffer[validationResult.second].appName = targetApp.Text().c_str(); } } } diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/LoadingAndSavingRemappingHelper.cpp b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/LoadingAndSavingRemappingHelper.cpp index d1777e574b..e5fe17fdfc 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/LoadingAndSavingRemappingHelper.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/LoadingAndSavingRemappingHelper.cpp @@ -20,9 +20,9 @@ namespace LoadingAndSavingRemappingHelper std::map> ogKeys; for (int i = 0; i < remappings.size(); i++) { - KeyShortcutTextUnion ogKey = remappings[i].first[0]; - KeyShortcutTextUnion newKey = remappings[i].first[1]; - std::wstring appName = remappings[i].second; + KeyShortcutTextUnion ogKey = remappings[i].mapping[0]; + KeyShortcutTextUnion newKey = remappings[i].mapping[1]; + std::wstring appName = remappings[i].appName; const bool ogKeyValidity = (ogKey.index() == 0 && std::get(ogKey) != NULL) || (ogKey.index() == 1 && EditorHelpers::IsValidShortcut(std::get(ogKey))); const bool newKeyValidity = (newKey.index() == 0 && std::get(newKey) != NULL) || (newKey.index() == 1 && EditorHelpers::IsValidShortcut(std::get(newKey))) || (newKey.index() == 2 && !std::get(newKey).empty()); @@ -58,8 +58,8 @@ namespace LoadingAndSavingRemappingHelper for (int i = 0; i < remappings.size(); i++) { - DWORD ogKey = std::get(remappings[i].first[0]); - KeyShortcutTextUnion newKey = remappings[i].first[1]; + DWORD ogKey = std::get(remappings[i].mapping[0]); + KeyShortcutTextUnion newKey = remappings[i].mapping[1]; const bool hasValidKeyRemapping = newKey.index() == 0 && std::get(newKey) != 0; const bool hasValidShortcutRemapping = newKey.index() == 1 && EditorHelpers::IsValidShortcut(std::get(newKey)); @@ -69,7 +69,7 @@ namespace LoadingAndSavingRemappingHelper ogKeys.insert(ogKey); // newKey should be added only if the target is a key - if (remappings[i].first[1].index() == 0) + if (remappings[i].mapping[1].index() == 0) { newKeys.insert(std::get(newKey)); } @@ -125,8 +125,8 @@ namespace LoadingAndSavingRemappingHelper DWORD successfulKeyToTextRemapCount = 0; for (int i = 0; i < remappings.size(); i++) { - const DWORD originalKey = std::get(remappings[i].first[0]); - KeyShortcutTextUnion newKey = remappings[i].first[1]; + const DWORD originalKey = std::get(remappings[i].mapping[0]); + KeyShortcutTextUnion newKey = remappings[i].mapping[1]; if (originalKey != NULL && !(newKey.index() == 0 && std::get(newKey) == NULL) && !(newKey.index() == 1 && !EditorHelpers::IsValidShortcut(std::get(newKey))) && !(newKey.index() == 2 && std::get(newKey).empty())) { @@ -203,12 +203,12 @@ namespace LoadingAndSavingRemappingHelper // Save the shortcuts that are valid and report if any of them were invalid for (int i = 0; i < remappings.size(); i++) { - Shortcut originalShortcut = std::get(remappings[i].first[0]); - KeyShortcutTextUnion newShortcut = remappings[i].first[1]; + Shortcut originalShortcut = std::get(remappings[i].mapping[0]); + KeyShortcutTextUnion newShortcut = remappings[i].mapping[1]; if (EditorHelpers::IsValidShortcut(originalShortcut) && ((newShortcut.index() == 0 && std::get(newShortcut) != NULL) || (newShortcut.index() == 1 && EditorHelpers::IsValidShortcut(std::get(newShortcut))) || (newShortcut.index() == 2 && !std::get(newShortcut).empty()))) { - if (remappings[i].second == L"") + if (remappings[i].appName == L"") { bool result = mappingConfiguration.AddOSLevelShortcut(originalShortcut, newShortcut); if (result) @@ -225,7 +225,7 @@ namespace LoadingAndSavingRemappingHelper } else { - bool result = mappingConfiguration.AddAppSpecificShortcut(remappings[i].second, originalShortcut, newShortcut); + bool result = mappingConfiguration.AddAppSpecificShortcut(remappings[i].appName, originalShortcut, newShortcut); if (result) { if (newShortcut.index() == 0) diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp index 563a61a5d3..54722164de 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp @@ -217,7 +217,7 @@ ShortcutControl& ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, s return; } - shortcutRemapBuffer[rowIndex].first[1] = text.c_str(); + shortcutRemapBuffer[rowIndex].mapping[1] = text.c_str(); }); const bool textSelected = newKeys.index() == 2; @@ -338,7 +338,7 @@ ShortcutControl& ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, s KeyDropDownControl::ValidateShortcutFromDropDownList(parent, row, keyboardRemapControlObjects[rowIndex][1]->shortcutDropDownVariableSizedWrapGrid.as(), 1, ShortcutControl::shortcutRemapBuffer, keyboardRemapControlObjects[rowIndex][1]->keyDropDownControlObjects, targetAppTextBox, true, false); // Reset the buffer based on the selected drop down items - std::get(shortcutRemapBuffer[rowIndex].first[0]).SetKeyCodes(KeyDropDownControl::GetSelectedCodesFromStackPanel(keyboardRemapControlObjects[rowIndex][0]->shortcutDropDownVariableSizedWrapGrid.as())); + std::get(shortcutRemapBuffer[rowIndex].mapping[0]).SetKeyCodes(KeyDropDownControl::GetSelectedCodesFromStackPanel(keyboardRemapControlObjects[rowIndex][0]->shortcutDropDownVariableSizedWrapGrid.as())); // second column is a hybrid column const bool regularShortcut = actionTypeCombo.SelectedIndex() == 0; @@ -348,7 +348,7 @@ ShortcutControl& ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, s if (textSelected) { - shortcutRemapBuffer[rowIndex].first[1] = unicodeTextKeysInput.Text().c_str(); + shortcutRemapBuffer[rowIndex].mapping[1] = unicodeTextKeysInput.Text().c_str(); } else { @@ -359,14 +359,14 @@ ShortcutControl& ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, s // If exactly one key is selected consider it to be a key remap if (selectedKeyCodes.size() == 1) { - shortcutRemapBuffer[rowIndex].first[1] = (DWORD)selectedKeyCodes[0]; + shortcutRemapBuffer[rowIndex].mapping[1] = (DWORD)selectedKeyCodes[0]; } else { Shortcut tempShortcut; tempShortcut.SetKeyCodes(selectedKeyCodes); // Assign instead of setting the value in the buffer since the previous value may not be a Shortcut - shortcutRemapBuffer[rowIndex].first[1] = tempShortcut; + shortcutRemapBuffer[rowIndex].mapping[1] = tempShortcut; } } else if (runProgram) @@ -388,7 +388,7 @@ ShortcutControl& ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, s tempShortcut.alreadyRunningAction = static_cast(runProgramAlreadyRunningAction.SelectedIndex()); // Assign instead of setting the value in the buffer since the previous value may not be a Shortcut - shortcutRemapBuffer[rowIndex].first[1] = tempShortcut; + shortcutRemapBuffer[rowIndex].mapping[1] = tempShortcut; } else if (openUri) { @@ -401,11 +401,11 @@ ShortcutControl& ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, s std::transform(lowercaseDefAppName.begin(), lowercaseDefAppName.end(), lowercaseDefAppName.begin(), towlower); if (newText == lowercaseDefAppName) { - shortcutRemapBuffer[rowIndex].second = L""; + shortcutRemapBuffer[rowIndex].appName = L""; } else { - shortcutRemapBuffer[rowIndex].second = targetAppTextBox.Text().c_str(); + shortcutRemapBuffer[rowIndex].appName = targetAppTextBox.Text().c_str(); } // To set the accessible name of the target app text box when focus is lost @@ -517,7 +517,7 @@ ShortcutControl& ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, s } else if (newKeys.index() == 2) { - shortcutRemapBuffer.back().first[1] = std::get(newKeys); + shortcutRemapBuffer.back().mapping[1] = std::get(newKeys); const auto& remapControl = keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]; actionTypeCombo.SelectedIndex(1); unicodeTextKeysInput.Text(std::get(newKeys)); @@ -571,7 +571,7 @@ StackPanel SetupOpenURIControls(StackPanel& parent, StackPanel& row, Shortcut& s Shortcut tempShortcut; tempShortcut.operationType = Shortcut::OperationType::OpenURI; tempShortcut.uriToOpen = ShortcutControl::RemoveExtraQuotes(uriTextBox.Text().c_str()); - ShortcutControl::shortcutRemapBuffer[rowIndex].first[1] = tempShortcut; + ShortcutControl::shortcutRemapBuffer[rowIndex].mapping[1] = tempShortcut; }); _controlStackPanel.Children().Append(openUriStackPanel); @@ -689,7 +689,7 @@ StackPanel SetupRunProgramControls(StackPanel& parent, StackPanel& row, Shortcut } Shortcut tempShortcut; CreateNewTempShortcut(row, tempShortcut, rowIndex); - ShortcutControl::shortcutRemapBuffer[rowIndex].first[1] = tempShortcut; + ShortcutControl::shortcutRemapBuffer[rowIndex].mapping[1] = tempShortcut; }); runProgramArgsForProgramInput.TextChanged([parent, row](winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::TextChangedEventArgs const& e) mutable { @@ -701,7 +701,7 @@ StackPanel SetupRunProgramControls(StackPanel& parent, StackPanel& row, Shortcut Shortcut tempShortcut; CreateNewTempShortcut(row, tempShortcut, rowIndex); - ShortcutControl::shortcutRemapBuffer[rowIndex].first[1] = tempShortcut; + ShortcutControl::shortcutRemapBuffer[rowIndex].mapping[1] = tempShortcut; }); runProgramStartInDirInput.TextChanged([parent, row](winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::TextChangedEventArgs const& e) mutable { @@ -718,7 +718,7 @@ StackPanel SetupRunProgramControls(StackPanel& parent, StackPanel& row, Shortcut Shortcut tempShortcut; CreateNewTempShortcut(row, tempShortcut, rowIndex); - ShortcutControl::shortcutRemapBuffer[rowIndex].first[1] = tempShortcut; + ShortcutControl::shortcutRemapBuffer[rowIndex].mapping[1] = tempShortcut; }); runProgramAlreadyRunningAction.SelectionChanged([parent, row](winrt::Windows::Foundation::IInspectable const&, SelectionChangedEventArgs const&) { @@ -735,7 +735,7 @@ StackPanel SetupRunProgramControls(StackPanel& parent, StackPanel& row, Shortcut Shortcut tempShortcut; CreateNewTempShortcut(static_cast(row), tempShortcut, rowIndex); - ShortcutControl::shortcutRemapBuffer[rowIndex].first[1] = tempShortcut; + ShortcutControl::shortcutRemapBuffer[rowIndex].mapping[1] = tempShortcut; }); runProgramElevationTypeCombo.SelectionChanged([parent, row](winrt::Windows::Foundation::IInspectable const&, SelectionChangedEventArgs const&) { @@ -751,7 +751,7 @@ StackPanel SetupRunProgramControls(StackPanel& parent, StackPanel& row, Shortcut } Shortcut tempShortcut; CreateNewTempShortcut(static_cast(row), tempShortcut, rowIndex); - ShortcutControl::shortcutRemapBuffer[rowIndex].first[1] = tempShortcut; + ShortcutControl::shortcutRemapBuffer[rowIndex].mapping[1] = tempShortcut; }); runProgramStartWindow.SelectionChanged([parent, row](winrt::Windows::Foundation::IInspectable const&, SelectionChangedEventArgs const&) { @@ -769,7 +769,7 @@ StackPanel SetupRunProgramControls(StackPanel& parent, StackPanel& row, Shortcut Shortcut tempShortcut; CreateNewTempShortcut(static_cast(row), tempShortcut, rowIndex); - ShortcutControl::shortcutRemapBuffer[rowIndex].first[1] = tempShortcut; + ShortcutControl::shortcutRemapBuffer[rowIndex].mapping[1] = tempShortcut; }); pickFileBtn.Click([&, parent, row](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) { @@ -943,17 +943,17 @@ void ShortcutControl::CreateDetectShortcutWindow(winrt::Windows::Foundation::IIn { if (colIndex == 0) { - shortcut = std::get(shortcutRemapBuffer[rowIndex].first[0]); + shortcut = std::get(shortcutRemapBuffer[rowIndex].mapping[0]); } else { - if (shortcutRemapBuffer[rowIndex].first[1].index() != 1) + if (shortcutRemapBuffer[rowIndex].mapping[1].index() != 1) { // not a shortcut, let's fix that. Shortcut newShortcut; - shortcutRemapBuffer[rowIndex].first[1] = newShortcut; + shortcutRemapBuffer[rowIndex].mapping[1] = newShortcut; } - shortcut = std::get(shortcutRemapBuffer[rowIndex].first[1]); + shortcut = std::get(shortcutRemapBuffer[rowIndex].mapping[1]); } if (!shortcut.IsEmpty() && shortcut.HasChord()) @@ -964,7 +964,7 @@ void ShortcutControl::CreateDetectShortcutWindow(winrt::Windows::Foundation::IIn } } - //remapBuffer[rowIndex].first. + //remapBuffer[rowIndex].mapping. // ContentDialog for detecting shortcuts. This is the parent UI element. ContentDialog detectShortcutBox; diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/SingleKeyRemapControl.cpp b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/SingleKeyRemapControl.cpp index 8d7240c0b6..1584dd18e2 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/SingleKeyRemapControl.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/SingleKeyRemapControl.cpp @@ -72,7 +72,7 @@ SingleKeyRemapControl::SingleKeyRemapControl(StackPanel table, StackPanel row, c return; } - singleKeyRemapBuffer[rowIndex].first[1] = text.c_str(); + singleKeyRemapBuffer[rowIndex].mapping[1] = text.c_str(); }); auto typeCombo = ComboBox(); diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorTest/BufferValidationTests.cpp b/src/modules/keyboardmanager/KeyboardManagerEditorTest/BufferValidationTests.cpp index 03aff657a3..fb7265e32b 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorTest/BufferValidationTests.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEditorTest/BufferValidationTests.cpp @@ -69,10 +69,10 @@ namespace RemappingUITests // Assert that the element is validated and buffer is updated Assert::AreEqual(true, error == ShortcutErrorType::NoError); - Assert::AreEqual((DWORD)NULL, std::get(remapBuffer[0].first[0])); - Assert::AreEqual((DWORD)NULL, std::get(remapBuffer[0].first[1])); - Assert::AreEqual((DWORD)NULL, std::get(remapBuffer[1].first[0])); - Assert::AreEqual((DWORD)NULL, std::get(remapBuffer[1].first[1])); + Assert::AreEqual((DWORD)NULL, std::get(remapBuffer[0].mapping[0])); + Assert::AreEqual((DWORD)NULL, std::get(remapBuffer[0].mapping[1])); + Assert::AreEqual((DWORD)NULL, std::get(remapBuffer[1].mapping[0])); + Assert::AreEqual((DWORD)NULL, std::get(remapBuffer[1].mapping[1])); } // Test if the ValidateAndUpdateKeyBufferElement method is successful when setting a key to non-null in a new row @@ -89,8 +89,8 @@ namespace RemappingUITests // Assert that the element is validated and buffer is updated Assert::AreEqual(true, error == ShortcutErrorType::NoError); - Assert::AreEqual((DWORD)0x42, std::get(remapBuffer[0].first[0])); - Assert::AreEqual((DWORD)NULL, std::get(remapBuffer[0].first[1])); + Assert::AreEqual((DWORD)0x42, std::get(remapBuffer[0].mapping[0])); + Assert::AreEqual((DWORD)NULL, std::get(remapBuffer[0].mapping[1])); } // Test if the ValidateAndUpdateKeyBufferElement method is successful when setting a key to non-null in a valid key to key @@ -107,8 +107,8 @@ namespace RemappingUITests // Assert that the element is validated and buffer is updated Assert::AreEqual(true, error == ShortcutErrorType::NoError); - Assert::AreEqual((DWORD)0x42, std::get(remapBuffer[0].first[0])); - Assert::AreEqual((DWORD)0x41, std::get(remapBuffer[0].first[1])); + Assert::AreEqual((DWORD)0x42, std::get(remapBuffer[0].mapping[0])); + Assert::AreEqual((DWORD)0x41, std::get(remapBuffer[0].mapping[1])); } // Test if the ValidateAndUpdateKeyBufferElement method is successful when setting a key to non-null in a valid key to shortcut @@ -125,8 +125,8 @@ namespace RemappingUITests // Assert that the element is validated and buffer is updated Assert::AreEqual(true, error == ShortcutErrorType::NoError); - Assert::AreEqual((DWORD)0x42, std::get(remapBuffer[0].first[0])); - Assert::AreEqual(true, Shortcut(std::vector{ VK_CONTROL, 0x41 }) == std::get(remapBuffer[0].first[1])); + Assert::AreEqual((DWORD)0x42, std::get(remapBuffer[0].mapping[0])); + Assert::AreEqual(true, Shortcut(std::vector{ VK_CONTROL, 0x41 }) == std::get(remapBuffer[0].mapping[1])); } // Test if the ValidateAndUpdateKeyBufferElement method is unsuccessful when setting first column to the same value as the right column @@ -143,8 +143,8 @@ namespace RemappingUITests // Assert that the element is invalid and buffer is not updated Assert::AreEqual(true, error == ShortcutErrorType::MapToSameKey); - Assert::AreEqual((DWORD)NULL, std::get(remapBuffer[0].first[0])); - Assert::AreEqual((DWORD)0x41, std::get(remapBuffer[0].first[1])); + Assert::AreEqual((DWORD)NULL, std::get(remapBuffer[0].mapping[0])); + Assert::AreEqual((DWORD)0x41, std::get(remapBuffer[0].mapping[1])); } // Test if the ValidateAndUpdateKeyBufferElement method is unsuccessful when setting first column of a key to key row to the same value as in another row @@ -162,8 +162,8 @@ namespace RemappingUITests // Assert that the element is invalid and buffer is not updated Assert::AreEqual(true, error == ShortcutErrorType::SameKeyPreviouslyMapped); - Assert::AreEqual((DWORD)NULL, std::get(remapBuffer[1].first[0])); - Assert::AreEqual((DWORD)0x43, std::get(remapBuffer[1].first[1])); + Assert::AreEqual((DWORD)NULL, std::get(remapBuffer[1].mapping[0])); + Assert::AreEqual((DWORD)0x43, std::get(remapBuffer[1].mapping[1])); } // Test if the ValidateAndUpdateKeyBufferElement method is unsuccessful when setting first column of a key to shortcut row to the same value as in another row @@ -181,8 +181,8 @@ namespace RemappingUITests // Assert that the element is invalid and buffer is not updated Assert::AreEqual(true, error == ShortcutErrorType::SameKeyPreviouslyMapped); - Assert::AreEqual((DWORD)NULL, std::get(remapBuffer[1].first[0])); - Assert::AreEqual(true, Shortcut(std::vector{ VK_CONTROL, 0x41 }) == std::get(remapBuffer[1].first[1])); + Assert::AreEqual((DWORD)NULL, std::get(remapBuffer[1].mapping[0])); + Assert::AreEqual(true, Shortcut(std::vector{ VK_CONTROL, 0x41 }) == std::get(remapBuffer[1].mapping[1])); } // Test if the ValidateAndUpdateKeyBufferElement method is unsuccessful when setting first column of a key to key row to a conflicting modifier with another row @@ -200,8 +200,8 @@ namespace RemappingUITests // Assert that the element is invalid and buffer is not updated Assert::AreEqual(true, error == ShortcutErrorType::ConflictingModifierKey); - Assert::AreEqual((DWORD)NULL, std::get(remapBuffer[1].first[0])); - Assert::AreEqual((DWORD)0x43, std::get(remapBuffer[1].first[1])); + Assert::AreEqual((DWORD)NULL, std::get(remapBuffer[1].mapping[0])); + Assert::AreEqual((DWORD)0x43, std::get(remapBuffer[1].mapping[1])); } // Test if the ValidateAndUpdateKeyBufferElement method is unsuccessful when setting first column of a key to shortcut row to a conflicting modifier with another row @@ -219,8 +219,8 @@ namespace RemappingUITests // Assert that the element is invalid and buffer is not updated Assert::AreEqual(true, error == ShortcutErrorType::ConflictingModifierKey); - Assert::AreEqual((DWORD)NULL, std::get(remapBuffer[1].first[0])); - Assert::AreEqual(true, Shortcut(std::vector{ VK_CONTROL, 0x41 }) == std::get(remapBuffer[1].first[1])); + Assert::AreEqual((DWORD)NULL, std::get(remapBuffer[1].mapping[0])); + Assert::AreEqual(true, Shortcut(std::vector{ VK_CONTROL, 0x41 }) == std::get(remapBuffer[1].mapping[1])); } // Test if the ValidateShortcutBufferElement method is successful and no drop down action is required on setting a column to null in a new or valid row diff --git a/src/modules/keyboardmanager/common/Shortcut.h b/src/modules/keyboardmanager/common/Shortcut.h index 225c3eba13..0bbe00bb4f 100644 --- a/src/modules/keyboardmanager/common/Shortcut.h +++ b/src/modules/keyboardmanager/common/Shortcut.h @@ -67,7 +67,7 @@ public: std::wstring runProgramArgs; std::wstring runProgramStartInDir; std::wstring uriToOpen; - + ProgramAlreadyRunningAction alreadyRunningAction = ProgramAlreadyRunningAction::ShowWindow; ElevationLevel elevationLevel = ElevationLevel::NonElevated; OperationType operationType = OperationType::RemapShortcut; @@ -189,5 +189,11 @@ public: using KeyShortcutTextUnion = std::variant; using RemapBufferItem = std::vector; -using RemapBufferRow = std::pair; + +struct RemapBufferRow +{ + RemapBufferItem mapping{}; + std::wstring appName{}; +}; + using RemapBuffer = std::vector;