Skip to content

Commit

Permalink
Use struct for RemapBufferRow
Browse files Browse the repository at this point in the history
  • Loading branch information
masaru-iritani committed Apr 20, 2024
1 parent 6bd083f commit 6bd9a9f
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<DWORD>(remapBuffer[rowIndex].first[std::abs(colIndex - 1)]);
DWORD otherColumnKeyCode = std::get<DWORD>(remapBuffer[rowIndex].mapping[std::abs(colIndex - 1)]);
if (otherColumnKeyCode == selectedKeyCode || IsKeyRemappingToItsCombinedKey(selectedKeyCode, otherColumnKeyCode))
{
errorType = ShortcutErrorType::MapToSameKey;
Expand All @@ -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<DWORD>(remapBuffer[i].first[colIndex]), selectedKeyCode);
ShortcutErrorType result = EditorHelpers::DoKeysOverlap(std::get<DWORD>(remapBuffer[i].mapping[colIndex]), selectedKeyCode);
if (result != ShortcutErrorType::NoError)
{
errorType = result;
Expand All @@ -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;
Expand Down Expand Up @@ -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<Shortcut>(remapBuffer[rowIndex].first[std::abs(colIndex - 1)]);
auto& shortcut = std::get<Shortcut>(remapBuffer[rowIndex].mapping[std::abs(colIndex - 1)]);
if (shortcut == std::get<Shortcut>(tempShortcut) && EditorHelpers::IsValidShortcut(shortcut) && EditorHelpers::IsValidShortcut(std::get<Shortcut>(tempShortcut)))
{
errorType = ShortcutErrorType::MapToSameShortcut;
Expand All @@ -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<DWORD>(remapBuffer[rowIndex].first[std::abs(colIndex - 1)]);
DWORD otherColumnKeyCode = std::get<DWORD>(remapBuffer[rowIndex].mapping[std::abs(colIndex - 1)]);
DWORD shortcutKeyCode = std::get<DWORD>(tempShortcut);
if ((otherColumnKeyCode == shortcutKeyCode || IsKeyRemappingToItsCombinedKey(otherColumnKeyCode, shortcutKeyCode)) && otherColumnKeyCode != NULL && shortcutKeyCode != NULL)
{
Expand All @@ -277,31 +277,31 @@ 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)
{
ShortcutErrorType result = ShortcutErrorType::NoError;
if (!isHybridControl)
{
result = EditorHelpers::DoShortcutsOverlap(std::get<Shortcut>(remapBuffer[i].first[colIndex]), std::get<Shortcut>(tempShortcut));
result = EditorHelpers::DoShortcutsOverlap(std::get<Shortcut>(remapBuffer[i].mapping[colIndex]), std::get<Shortcut>(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<DWORD>(tempShortcut) != NULL && std::get<DWORD>(remapBuffer[i].first[colIndex]) != NULL)
if (std::get<DWORD>(tempShortcut) != NULL && std::get<DWORD>(remapBuffer[i].mapping[colIndex]) != NULL)
{
result = EditorHelpers::DoKeysOverlap(std::get<DWORD>(remapBuffer[i].first[colIndex]), std::get<DWORD>(tempShortcut));
result = EditorHelpers::DoKeysOverlap(std::get<DWORD>(remapBuffer[i].mapping[colIndex]), std::get<DWORD>(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<Shortcut>(remapBuffer[i].first[colIndex]);
auto& shortcut = std::get<Shortcut>(remapBuffer[i].mapping[colIndex]);
if (EditorHelpers::IsValidShortcut(std::get<Shortcut>(tempShortcut)) && EditorHelpers::IsValidShortcut(shortcut))
{
result = EditorHelpers::DoShortcutsOverlap(std::get<Shortcut>(remapBuffer[i].first[colIndex]), std::get<Shortcut>(tempShortcut));
result = EditorHelpers::DoShortcutsOverlap(std::get<Shortcut>(remapBuffer[i].mapping[colIndex]), std::get<Shortcut>(tempShortcut));
}
}
// Other scenarios not possible since key to shortcut is with key to key, and shortcut to key is with shortcut to shortcut
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Shortcut>(ShortcutControl::shortcutRemapBuffer[i].first[0]);
auto tempShortcut = std::get<Shortcut>(ShortcutControl::shortcutRemapBuffer[i].mapping[0]);
if (tempShortcut.ToHstringVK() == keysForShortcutToEdit)
{
indexToDelete = i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,19 +281,19 @@ void KeyDropDownControl::SetSelectionHandler(StackPanel& table, StackPanel row,
std::vector<int32_t> selectedKeyCodes = GetSelectedCodesFromStackPanel(parent);
if (!isHybridControl)
{
std::get<Shortcut>(shortcutRemapBuffer[validationResult.second].first[colIndex]).SetKeyCodes(selectedKeyCodes);
std::get<Shortcut>(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);
}
}

Expand All @@ -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();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ namespace LoadingAndSavingRemappingHelper
std::map<std::wstring, std::set<KeyShortcutTextUnion>> 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<DWORD>(ogKey) != NULL) || (ogKey.index() == 1 && EditorHelpers::IsValidShortcut(std::get<Shortcut>(ogKey)));
const bool newKeyValidity = (newKey.index() == 0 && std::get<DWORD>(newKey) != NULL) || (newKey.index() == 1 && EditorHelpers::IsValidShortcut(std::get<Shortcut>(newKey))) || (newKey.index() == 2 && !std::get<std::wstring>(newKey).empty());
Expand Down Expand Up @@ -58,8 +58,8 @@ namespace LoadingAndSavingRemappingHelper

for (int i = 0; i < remappings.size(); i++)
{
DWORD ogKey = std::get<DWORD>(remappings[i].first[0]);
KeyShortcutTextUnion newKey = remappings[i].first[1];
DWORD ogKey = std::get<DWORD>(remappings[i].mapping[0]);
KeyShortcutTextUnion newKey = remappings[i].mapping[1];

const bool hasValidKeyRemapping = newKey.index() == 0 && std::get<DWORD>(newKey) != 0;
const bool hasValidShortcutRemapping = newKey.index() == 1 && EditorHelpers::IsValidShortcut(std::get<Shortcut>(newKey));
Expand All @@ -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<DWORD>(newKey));
}
Expand Down Expand Up @@ -125,8 +125,8 @@ namespace LoadingAndSavingRemappingHelper
DWORD successfulKeyToTextRemapCount = 0;
for (int i = 0; i < remappings.size(); i++)
{
const DWORD originalKey = std::get<DWORD>(remappings[i].first[0]);
KeyShortcutTextUnion newKey = remappings[i].first[1];
const DWORD originalKey = std::get<DWORD>(remappings[i].mapping[0]);
KeyShortcutTextUnion newKey = remappings[i].mapping[1];

if (originalKey != NULL && !(newKey.index() == 0 && std::get<DWORD>(newKey) == NULL) && !(newKey.index() == 1 && !EditorHelpers::IsValidShortcut(std::get<Shortcut>(newKey))) && !(newKey.index() == 2 && std::get<std::wstring>(newKey).empty()))
{
Expand Down Expand Up @@ -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<Shortcut>(remappings[i].first[0]);
KeyShortcutTextUnion newShortcut = remappings[i].first[1];
Shortcut originalShortcut = std::get<Shortcut>(remappings[i].mapping[0]);
KeyShortcutTextUnion newShortcut = remappings[i].mapping[1];

if (EditorHelpers::IsValidShortcut(originalShortcut) && ((newShortcut.index() == 0 && std::get<DWORD>(newShortcut) != NULL) || (newShortcut.index() == 1 && EditorHelpers::IsValidShortcut(std::get<Shortcut>(newShortcut))) || (newShortcut.index() == 2 && !std::get<std::wstring>(newShortcut).empty())))
{
if (remappings[i].second == L"")
if (remappings[i].appName == L"")
{
bool result = mappingConfiguration.AddOSLevelShortcut(originalShortcut, newShortcut);
if (result)
Expand All @@ -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)
Expand Down

0 comments on commit 6bd9a9f

Please sign in to comment.