mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 12:18:50 +02:00
Get rid of indexes in dropdowns (#7278)
This commit is contained in:
@@ -27,7 +27,7 @@ std::vector<DWORD> LayoutMap::GetKeyCodeList(const bool isShortcut)
|
|||||||
return impl->GetKeyCodeList(isShortcut);
|
return impl->GetKeyCodeList(isShortcut);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::wstring> LayoutMap::GetKeyNameList(const bool isShortcut)
|
std::vector<std::pair<DWORD, std::wstring>> LayoutMap::GetKeyNameList(const bool isShortcut)
|
||||||
{
|
{
|
||||||
return impl->GetKeyNameList(isShortcut);
|
return impl->GetKeyNameList(isShortcut);
|
||||||
}
|
}
|
||||||
@@ -305,25 +305,25 @@ std::vector<DWORD> LayoutMap::LayoutMapImpl::GetKeyCodeList(const bool isShortcu
|
|||||||
return keyCodes;
|
return keyCodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::wstring> LayoutMap::LayoutMapImpl::GetKeyNameList(const bool isShortcut)
|
std::vector<std::pair<DWORD, std::wstring>> LayoutMap::LayoutMapImpl::GetKeyNameList(const bool isShortcut)
|
||||||
{
|
{
|
||||||
std::vector<std::wstring> keyNames;
|
std::vector<std::pair<DWORD, std::wstring>> keyNames;
|
||||||
std::vector<DWORD> keyCodes = GetKeyCodeList(isShortcut);
|
std::vector<DWORD> keyCodes = GetKeyCodeList(isShortcut);
|
||||||
std::lock_guard<std::mutex> lock(keyboardLayoutMap_mutex);
|
std::lock_guard<std::mutex> lock(keyboardLayoutMap_mutex);
|
||||||
// If it is a key list for the shortcut control then we add a "None" key at the start
|
// If it is a key list for the shortcut control then we add a "None" key at the start
|
||||||
if (isShortcut)
|
if (isShortcut)
|
||||||
{
|
{
|
||||||
keyNames.push_back(L"None");
|
keyNames.push_back({ 0, L"None" });
|
||||||
for (int i = 1; i < keyCodes.size(); i++)
|
for (int i = 1; i < keyCodes.size(); i++)
|
||||||
{
|
{
|
||||||
keyNames.push_back(keyboardLayoutMap[keyCodes[i]]);
|
keyNames.push_back({ keyCodes[i], keyboardLayoutMap[keyCodes[i]] });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (int i = 0; i < keyCodes.size(); i++)
|
for (int i = 0; i < keyCodes.size(); i++)
|
||||||
{
|
{
|
||||||
keyNames.push_back(keyboardLayoutMap[keyCodes[i]]);
|
keyNames.push_back({ keyCodes[i], keyboardLayoutMap[keyCodes[i]] });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public:
|
|||||||
void UpdateLayout();
|
void UpdateLayout();
|
||||||
std::wstring GetKeyName(DWORD key);
|
std::wstring GetKeyName(DWORD key);
|
||||||
std::vector<DWORD> GetKeyCodeList(const bool isShortcut = false);
|
std::vector<DWORD> GetKeyCodeList(const bool isShortcut = false);
|
||||||
std::vector<std::wstring> GetKeyNameList(const bool isShortcut = false);
|
std::vector<std::pair<DWORD, std::wstring>> GetKeyNameList(const bool isShortcut = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class LayoutMapImpl;
|
class LayoutMapImpl;
|
||||||
|
|||||||
@@ -46,6 +46,6 @@ public:
|
|||||||
// Function to return the list of key codes in the order for the drop down. It creates it if it doesn't exist
|
// Function to return the list of key codes in the order for the drop down. It creates it if it doesn't exist
|
||||||
std::vector<DWORD> GetKeyCodeList(const bool isShortcut);
|
std::vector<DWORD> GetKeyCodeList(const bool isShortcut);
|
||||||
|
|
||||||
// Function to return the list of key name in the order for the drop down based on the key codes
|
// Function to return the list of key name pairs in the order for the drop down based on the key codes
|
||||||
std::vector<std::wstring> GetKeyNameList(const bool isShortcut);
|
std::vector<std::pair<DWORD, std::wstring>> GetKeyNameList(const bool isShortcut);
|
||||||
};
|
};
|
||||||
@@ -97,12 +97,15 @@ namespace KeyboardManagerHelper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections::IVector<IInspectable> ToBoxValue(const std::vector<std::wstring>& list)
|
Collections::IVector<IInspectable> ToBoxValue(const std::vector<std::pair<DWORD, std::wstring>>& list)
|
||||||
{
|
{
|
||||||
Collections::IVector<IInspectable> boxList = single_threaded_vector<IInspectable>();
|
Collections::IVector<IInspectable> boxList = single_threaded_vector<IInspectable>();
|
||||||
for (auto& val : list)
|
for (auto& val : list)
|
||||||
{
|
{
|
||||||
boxList.Append(winrt::box_value(val));
|
auto comboBox = ComboBoxItem();
|
||||||
|
comboBox.DataContext(winrt::box_value(std::to_wstring(val.first)));
|
||||||
|
comboBox.Content(winrt::box_value(val.second));
|
||||||
|
boxList.Append(winrt::box_value(comboBox));
|
||||||
}
|
}
|
||||||
|
|
||||||
return boxList;
|
return boxList;
|
||||||
@@ -324,7 +327,7 @@ namespace KeyboardManagerHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Function to filter the key codes for artificial key codes
|
// Function to filter the key codes for artificial key codes
|
||||||
DWORD FilterArtificialKeys(const DWORD& key)
|
int32_t FilterArtificialKeys(const int32_t& key)
|
||||||
{
|
{
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
@@ -345,57 +348,16 @@ namespace KeyboardManagerHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Function to check if a modifier has been repeated in the previous drop downs
|
// Function to check if a modifier has been repeated in the previous drop downs
|
||||||
bool CheckRepeatedModifier(std::vector<DWORD>& currentKeys, int selectedKeyIndex, const std::vector<DWORD>& keyCodeList)
|
bool CheckRepeatedModifier(const std::vector<int32_t>& currentKeys, int selectedKeyCode)
|
||||||
{
|
{
|
||||||
// check if modifier has already been added before in a previous drop down
|
// Count the number of keys that are equal to 'selectedKeyCode'
|
||||||
int currentDropDownIndex = -1;
|
int numberOfSameType = 0;
|
||||||
|
|
||||||
// Find the key index of the current drop down selection so that we skip that index while searching for repeated modifiers
|
|
||||||
for (int i = 0; i < currentKeys.size(); i++)
|
for (int i = 0; i < currentKeys.size(); i++)
|
||||||
{
|
{
|
||||||
if (currentKeys[i] == keyCodeList[selectedKeyIndex])
|
numberOfSameType += KeyboardManagerHelper::GetKeyType(selectedKeyCode) == KeyboardManagerHelper::GetKeyType(currentKeys[i]);
|
||||||
{
|
|
||||||
currentDropDownIndex = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool matchPreviousModifier = false;
|
// If we have at least two keys equal to 'selectedKeyCode' than modifier was repeated
|
||||||
for (int i = 0; i < currentKeys.size(); i++)
|
return numberOfSameType > 1;
|
||||||
{
|
|
||||||
// Skip the current drop down
|
|
||||||
if (i != currentDropDownIndex)
|
|
||||||
{
|
|
||||||
// If the key type for the newly added key matches any of the existing keys in the shortcut
|
|
||||||
if (KeyboardManagerHelper::GetKeyType(keyCodeList[selectedKeyIndex]) == KeyboardManagerHelper::GetKeyType(currentKeys[i]))
|
|
||||||
{
|
|
||||||
matchPreviousModifier = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return matchPreviousModifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Function to get the selected key codes from the list of selected indices
|
|
||||||
std::vector<DWORD> GetKeyCodesFromSelectedIndices(const std::vector<int32_t>& selectedIndices, const std::vector<DWORD>& keyCodeList)
|
|
||||||
{
|
|
||||||
std::vector<DWORD> keys;
|
|
||||||
|
|
||||||
for (int i = 0; i < selectedIndices.size(); i++)
|
|
||||||
{
|
|
||||||
int selectedKeyIndex = selectedIndices[i];
|
|
||||||
if (selectedKeyIndex != -1 && keyCodeList.size() > selectedKeyIndex)
|
|
||||||
{
|
|
||||||
// If None is not the selected key
|
|
||||||
if (keyCodeList[selectedKeyIndex] != 0)
|
|
||||||
{
|
|
||||||
keys.push_back(keyCodeList[selectedKeyIndex]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return keys;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ namespace KeyboardManagerHelper
|
|||||||
winrt::hstring GetErrorMessage(ErrorType errorType);
|
winrt::hstring GetErrorMessage(ErrorType errorType);
|
||||||
|
|
||||||
// Function to return the list of key name in the order for the drop down based on the key codes
|
// Function to return the list of key name in the order for the drop down based on the key codes
|
||||||
winrt::Windows::Foundation::Collections::IVector<winrt::Windows::Foundation::IInspectable> ToBoxValue(const std::vector<std::wstring>& list);
|
winrt::Windows::Foundation::Collections::IVector<winrt::Windows::Foundation::IInspectable> ToBoxValue(const std::vector<std::pair<DWORD,std::wstring>>& list);
|
||||||
|
|
||||||
// Function to set the value of a key event based on the arguments
|
// Function to set the value of a key event based on the arguments
|
||||||
void SetKeyEvent(LPINPUT keyEventArray, int index, DWORD inputType, WORD keyCode, DWORD flags, ULONG_PTR extraInfo);
|
void SetKeyEvent(LPINPUT keyEventArray, int index, DWORD inputType, WORD keyCode, DWORD flags, ULONG_PTR extraInfo);
|
||||||
@@ -100,14 +100,11 @@ namespace KeyboardManagerHelper
|
|||||||
void SetModifierKeyEvents(const Shortcut& shortcutToBeSent, const ModifierKey& winKeyInvoked, LPINPUT keyEventArray, int& index, bool isKeyDown, ULONG_PTR extraInfoFlag, const Shortcut& shortcutToCompare = Shortcut(), const DWORD& keyToBeReleased = NULL);
|
void SetModifierKeyEvents(const Shortcut& shortcutToBeSent, const ModifierKey& winKeyInvoked, LPINPUT keyEventArray, int& index, bool isKeyDown, ULONG_PTR extraInfoFlag, const Shortcut& shortcutToCompare = Shortcut(), const DWORD& keyToBeReleased = NULL);
|
||||||
|
|
||||||
// Function to filter the key codes for artificial key codes
|
// Function to filter the key codes for artificial key codes
|
||||||
DWORD FilterArtificialKeys(const DWORD& key);
|
int32_t FilterArtificialKeys(const int32_t& key);
|
||||||
|
|
||||||
// Function to sort a vector of shortcuts based on it's size
|
// Function to sort a vector of shortcuts based on it's size
|
||||||
void SortShortcutVectorBasedOnSize(std::vector<Shortcut>& shortcutVector);
|
void SortShortcutVectorBasedOnSize(std::vector<Shortcut>& shortcutVector);
|
||||||
|
|
||||||
// Function to check if a modifier has been repeated in the previous drop downs
|
// Function to check if a modifier has been repeated in the previous drop downs
|
||||||
bool CheckRepeatedModifier(std::vector<DWORD>& currentKeys, int selectedKeyIndex, const std::vector<DWORD>& keyCodeList);
|
bool CheckRepeatedModifier(const std::vector<int32_t>& currentKeys, int selectedKeyCodes);
|
||||||
|
|
||||||
// Function to get the selected key codes from the list of selected indices
|
|
||||||
std::vector<DWORD> GetKeyCodesFromSelectedIndices(const std::vector<int32_t>& selectedIndices, const std::vector<DWORD>& keyCodeList);
|
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ Shortcut::Shortcut(const std::wstring& shortcutVK) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Constructor to initialize shortcut from a list of keys
|
// Constructor to initialize shortcut from a list of keys
|
||||||
Shortcut::Shortcut(const std::vector<DWORD>& keys)
|
Shortcut::Shortcut(const std::vector<int32_t>& keys)
|
||||||
{
|
{
|
||||||
SetKeyCodes(keys);
|
SetKeyCodes(keys);
|
||||||
}
|
}
|
||||||
@@ -505,12 +505,15 @@ std::vector<DWORD> Shortcut::GetKeyCodes()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Function to set a shortcut from a vector of key codes
|
// Function to set a shortcut from a vector of key codes
|
||||||
void Shortcut::SetKeyCodes(const std::vector<DWORD>& keys)
|
void Shortcut::SetKeyCodes(const std::vector<int32_t>& keys)
|
||||||
{
|
{
|
||||||
Reset();
|
Reset();
|
||||||
for (int i = 0; i < keys.size(); i++)
|
for (int i = 0; i < keys.size(); i++)
|
||||||
{
|
{
|
||||||
SetKey(keys[i]);
|
if (keys[i] != -1 && keys[i] != 0)
|
||||||
|
{
|
||||||
|
SetKey(keys[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public:
|
|||||||
Shortcut(const std::wstring& shortcutVK);
|
Shortcut(const std::wstring& shortcutVK);
|
||||||
|
|
||||||
// Constructor to initialize shortcut from a list of keys
|
// Constructor to initialize shortcut from a list of keys
|
||||||
Shortcut(const std::vector<DWORD>& keys);
|
Shortcut(const std::vector<int32_t>& keys);
|
||||||
|
|
||||||
// == operator
|
// == operator
|
||||||
inline bool operator==(const Shortcut& sc) const
|
inline bool operator==(const Shortcut& sc) const
|
||||||
@@ -153,7 +153,7 @@ public:
|
|||||||
std::vector<DWORD> GetKeyCodes();
|
std::vector<DWORD> GetKeyCodes();
|
||||||
|
|
||||||
// Function to set a shortcut from a vector of key codes
|
// Function to set a shortcut from a vector of key codes
|
||||||
void SetKeyCodes(const std::vector<DWORD>& keys);
|
void SetKeyCodes(const std::vector<int32_t>& keys);
|
||||||
|
|
||||||
// Function to check if all the modifiers in the shortcut have been pressed down
|
// Function to check if all the modifiers in the shortcut have been pressed down
|
||||||
bool CheckModifiersKeyboardState(InputInterface& ii) const;
|
bool CheckModifiersKeyboardState(InputInterface& ii) const;
|
||||||
|
|||||||
@@ -481,7 +481,7 @@ namespace KeyboardEventHandlers
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Check if the keyboard state is clear apart from the target remap key (by creating a temp Shortcut object with the target key)
|
// Check if the keyboard state is clear apart from the target remap key (by creating a temp Shortcut object with the target key)
|
||||||
bool isKeyboardStateClear = Shortcut(std::vector<DWORD>({ KeyboardManagerHelper::FilterArtificialKeys(std::get<DWORD>(it->second.targetShortcut)) })).IsKeyboardStateClearExceptShortcut(ii);
|
bool isKeyboardStateClear = Shortcut(std::vector<int32_t>({ KeyboardManagerHelper::FilterArtificialKeys(std::get<DWORD>(it->second.targetShortcut)) })).IsKeyboardStateClearExceptShortcut(ii);
|
||||||
// If the keyboard state is clear, we release the target key but do not reset the remap state
|
// If the keyboard state is clear, we release the target key but do not reset the remap state
|
||||||
if (isKeyboardStateClear)
|
if (isKeyboardStateClear)
|
||||||
{
|
{
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -104,11 +104,10 @@ namespace KeyboardManagerCommonTests
|
|||||||
TEST_METHOD (CheckRepeatedModifier_ShouldReturnTrue_OnPassingSameModifierRepeated)
|
TEST_METHOD (CheckRepeatedModifier_ShouldReturnTrue_OnPassingSameModifierRepeated)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
std::vector<DWORD> keyList = LayoutMap().GetKeyCodeList(true);
|
std::vector<int32_t> keys = { VK_CONTROL, VK_CONTROL, 0x41 };
|
||||||
std::vector<DWORD> keys = { VK_CONTROL, VK_CONTROL, 0x41 };
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
bool result = KeyboardManagerHelper::CheckRepeatedModifier(keys, TestHelpers::GetDropDownIndexFromDropDownList(VK_CONTROL, keyList), keyList);
|
bool result = KeyboardManagerHelper::CheckRepeatedModifier(keys, VK_CONTROL);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert::IsTrue(result);
|
Assert::IsTrue(result);
|
||||||
@@ -118,11 +117,10 @@ namespace KeyboardManagerCommonTests
|
|||||||
TEST_METHOD (CheckRepeatedModifier_ShouldReturnTrue_OnPassingConflictingModifierRepeated)
|
TEST_METHOD (CheckRepeatedModifier_ShouldReturnTrue_OnPassingConflictingModifierRepeated)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
std::vector<DWORD> keyList = LayoutMap().GetKeyCodeList(true);
|
std::vector<int32_t> keys = { VK_CONTROL, VK_LCONTROL, 0x41 };
|
||||||
std::vector<DWORD> keys = { VK_CONTROL, VK_LCONTROL, 0x41 };
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
bool result = KeyboardManagerHelper::CheckRepeatedModifier(keys, TestHelpers::GetDropDownIndexFromDropDownList(VK_LCONTROL, keyList), keyList);
|
bool result = KeyboardManagerHelper::CheckRepeatedModifier(keys, VK_LCONTROL);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert::IsTrue(result);
|
Assert::IsTrue(result);
|
||||||
@@ -132,42 +130,13 @@ namespace KeyboardManagerCommonTests
|
|||||||
TEST_METHOD (CheckRepeatedModifier_ShouldReturnFalse_OnPassingDifferentModifiers)
|
TEST_METHOD (CheckRepeatedModifier_ShouldReturnFalse_OnPassingDifferentModifiers)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
std::vector<DWORD> keyList = LayoutMap().GetKeyCodeList(true);
|
std::vector<int32_t> keys = { VK_CONTROL, VK_SHIFT, 0x41 };
|
||||||
std::vector<DWORD> keys = { VK_CONTROL, VK_SHIFT, 0x41 };
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
bool result = KeyboardManagerHelper::CheckRepeatedModifier(keys, TestHelpers::GetDropDownIndexFromDropDownList(VK_SHIFT, keyList), keyList);
|
bool result = KeyboardManagerHelper::CheckRepeatedModifier(keys, VK_SHIFT);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert::IsFalse(result);
|
Assert::IsFalse(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test if the GetKeyCodesFromSelectedIndices method ignores -1 and 0 from argument in return value
|
|
||||||
TEST_METHOD (GetKeyCodesFromSelectedIndices_ShouldIgnoreMinus1And0_OnPassingArgumentWithMinus1Or0)
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
std::vector<DWORD> keyList = LayoutMap().GetKeyCodeList(true);
|
|
||||||
std::vector<int32_t> indices = { -1, 0, -1, 0 };
|
|
||||||
|
|
||||||
// Act
|
|
||||||
auto result = KeyboardManagerHelper::GetKeyCodesFromSelectedIndices(indices, keyList);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert::IsTrue(result.empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test if the GetKeyCodesFromSelectedIndices method returns vector with key codes from vector with indices as per key code list
|
|
||||||
TEST_METHOD (GetKeyCodesFromSelectedIndices_ShouldReturnVectorWithKeyCodes_OnPassingVectorWithIndicesAsPerKeyCodeList)
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
std::vector<DWORD> keyList = LayoutMap().GetKeyCodeList(true);
|
|
||||||
std::vector<int32_t> indices = { TestHelpers::GetDropDownIndexFromDropDownList(0x41, keyList), TestHelpers::GetDropDownIndexFromDropDownList(0x42, keyList) };
|
|
||||||
|
|
||||||
// Act
|
|
||||||
auto result = KeyboardManagerHelper::GetKeyCodesFromSelectedIndices(indices, keyList);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert::IsTrue(result == std::vector<DWORD>{ 0x41, 0x42 });
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,8 +79,8 @@ namespace KeyboardManagerCommonTests
|
|||||||
TEST_METHOD (DoKeysOverlap_ShouldReturnNoError_OnPassingInvalidShortcutForOneOfTheArguments)
|
TEST_METHOD (DoKeysOverlap_ShouldReturnNoError_OnPassingInvalidShortcutForOneOfTheArguments)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Shortcut s1(std::vector<DWORD>{ NULL });
|
Shortcut s1(std::vector<int32_t>{ NULL });
|
||||||
Shortcut s2(std::vector<DWORD>{ VK_CONTROL, 0x41 });
|
Shortcut s2(std::vector<int32_t>{ VK_CONTROL, 0x41 });
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
auto result = Shortcut::DoKeysOverlap(s1, s2);
|
auto result = Shortcut::DoKeysOverlap(s1, s2);
|
||||||
@@ -93,7 +93,7 @@ namespace KeyboardManagerCommonTests
|
|||||||
TEST_METHOD (DoKeysOverlap_ShouldReturnSameShortcutPreviouslyMapped_OnPassingSameShortcutForBothArguments)
|
TEST_METHOD (DoKeysOverlap_ShouldReturnSameShortcutPreviouslyMapped_OnPassingSameShortcutForBothArguments)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Shortcut s1(std::vector<DWORD>{ VK_CONTROL, 0x41 });
|
Shortcut s1(std::vector<int32_t>{ VK_CONTROL, 0x41 });
|
||||||
Shortcut s2 = s1;
|
Shortcut s2 = s1;
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -107,8 +107,8 @@ namespace KeyboardManagerCommonTests
|
|||||||
TEST_METHOD (DoKeysOverlap_ShouldReturnNoError_OnPassingShortcutsWithDifferentActionKeys)
|
TEST_METHOD (DoKeysOverlap_ShouldReturnNoError_OnPassingShortcutsWithDifferentActionKeys)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Shortcut s1(std::vector<DWORD>{ VK_CONTROL, 0x42 });
|
Shortcut s1(std::vector<int32_t>{ VK_CONTROL, 0x42 });
|
||||||
Shortcut s2(std::vector<DWORD>{ VK_CONTROL, 0x41 });
|
Shortcut s2(std::vector<int32_t>{ VK_CONTROL, 0x41 });
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
auto result = Shortcut::DoKeysOverlap(s1, s2);
|
auto result = Shortcut::DoKeysOverlap(s1, s2);
|
||||||
@@ -121,8 +121,8 @@ namespace KeyboardManagerCommonTests
|
|||||||
TEST_METHOD (DoKeysOverlap_ShouldReturnNoError_OnPassingShortcutsWithDifferentModifiers)
|
TEST_METHOD (DoKeysOverlap_ShouldReturnNoError_OnPassingShortcutsWithDifferentModifiers)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Shortcut s1(std::vector<DWORD>{ VK_CONTROL, 0x42 });
|
Shortcut s1(std::vector<int32_t>{ VK_CONTROL, 0x42 });
|
||||||
Shortcut s2(std::vector<DWORD>{ VK_SHIFT, 0x42 });
|
Shortcut s2(std::vector<int32_t>{ VK_SHIFT, 0x42 });
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
auto result = Shortcut::DoKeysOverlap(s1, s2);
|
auto result = Shortcut::DoKeysOverlap(s1, s2);
|
||||||
@@ -135,8 +135,8 @@ namespace KeyboardManagerCommonTests
|
|||||||
TEST_METHOD (DoKeysOverlap_ShouldReturnConflictingModifierShortcut_OnPassingShortcutsWithLeftModifierAndCommonModifierOfSameType)
|
TEST_METHOD (DoKeysOverlap_ShouldReturnConflictingModifierShortcut_OnPassingShortcutsWithLeftModifierAndCommonModifierOfSameType)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Shortcut s1(std::vector<DWORD>{ VK_LCONTROL, 0x42 });
|
Shortcut s1(std::vector<int32_t>{ VK_LCONTROL, 0x42 });
|
||||||
Shortcut s2(std::vector<DWORD>{ VK_CONTROL, 0x42 });
|
Shortcut s2(std::vector<int32_t>{ VK_CONTROL, 0x42 });
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
auto result = Shortcut::DoKeysOverlap(s1, s2);
|
auto result = Shortcut::DoKeysOverlap(s1, s2);
|
||||||
@@ -149,8 +149,8 @@ namespace KeyboardManagerCommonTests
|
|||||||
TEST_METHOD (DoKeysOverlap_ShouldReturnConflictingModifierShortcut_OnPassingShortcutsWithRightModifierAndCommonModifierOfSameType)
|
TEST_METHOD (DoKeysOverlap_ShouldReturnConflictingModifierShortcut_OnPassingShortcutsWithRightModifierAndCommonModifierOfSameType)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Shortcut s1(std::vector<DWORD>{ VK_RCONTROL, 0x42 });
|
Shortcut s1(std::vector<int32_t>{ VK_RCONTROL, 0x42 });
|
||||||
Shortcut s2(std::vector<DWORD>{ VK_CONTROL, 0x42 });
|
Shortcut s2(std::vector<int32_t>{ VK_CONTROL, 0x42 });
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
auto result = Shortcut::DoKeysOverlap(s1, s2);
|
auto result = Shortcut::DoKeysOverlap(s1, s2);
|
||||||
@@ -163,8 +163,8 @@ namespace KeyboardManagerCommonTests
|
|||||||
TEST_METHOD (DoKeysOverlap_ShouldReturnConflictingModifierShortcut_OnPassingShortcutsWithLeftModifierAndRightModifierOfSameType)
|
TEST_METHOD (DoKeysOverlap_ShouldReturnConflictingModifierShortcut_OnPassingShortcutsWithLeftModifierAndRightModifierOfSameType)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Shortcut s1(std::vector<DWORD>{ VK_LCONTROL, 0x42 });
|
Shortcut s1(std::vector<int32_t>{ VK_LCONTROL, 0x42 });
|
||||||
Shortcut s2(std::vector<DWORD>{ VK_RCONTROL, 0x42 });
|
Shortcut s2(std::vector<int32_t>{ VK_RCONTROL, 0x42 });
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
auto result = Shortcut::DoKeysOverlap(s1, s2);
|
auto result = Shortcut::DoKeysOverlap(s1, s2);
|
||||||
|
|||||||
@@ -22,10 +22,4 @@ namespace TestHelpers
|
|||||||
state.SetActivatedApp(maxLengthString);
|
state.SetActivatedApp(maxLengthString);
|
||||||
state.SetActivatedApp(KeyboardManagerConstants::NoActivatedApp);
|
state.SetActivatedApp(KeyboardManagerConstants::NoActivatedApp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to return the index of the given key code from the drop down key list
|
|
||||||
int GetDropDownIndexFromDropDownList(DWORD key, const std::vector<DWORD>& keyList)
|
|
||||||
{
|
|
||||||
return (int)std::distance(keyList.begin(), std::find(keyList.begin(), keyList.end(), key));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,21 +2,22 @@
|
|||||||
#include "BufferValidationHelpers.h"
|
#include "BufferValidationHelpers.h"
|
||||||
#include <keyboardmanager/common/KeyboardManagerConstants.h>
|
#include <keyboardmanager/common/KeyboardManagerConstants.h>
|
||||||
#include <common\shared_constants.h>
|
#include <common\shared_constants.h>
|
||||||
|
#include <modules\keyboardmanager\ui\KeyDropDownControl.h>
|
||||||
|
|
||||||
namespace BufferValidationHelpers
|
namespace BufferValidationHelpers
|
||||||
{
|
{
|
||||||
// Function to validate and update an element of the key remap buffer when the selection has changed
|
// Function to validate and update an element of the key remap buffer when the selection has changed
|
||||||
KeyboardManagerHelper::ErrorType ValidateAndUpdateKeyBufferElement(int rowIndex, int colIndex, int selectedKeyIndex, const std::vector<DWORD>& keyCodeList, RemapBuffer& remapBuffer)
|
KeyboardManagerHelper::ErrorType ValidateAndUpdateKeyBufferElement(int rowIndex, int colIndex, int selectedKeyCode, RemapBuffer& remapBuffer)
|
||||||
{
|
{
|
||||||
KeyboardManagerHelper::ErrorType errorType = KeyboardManagerHelper::ErrorType::NoError;
|
KeyboardManagerHelper::ErrorType errorType = KeyboardManagerHelper::ErrorType::NoError;
|
||||||
|
|
||||||
// Check if the element was not found or the index exceeds the known keys
|
// Check if the element was not found or the index exceeds the known keys
|
||||||
if (selectedKeyIndex != -1 && keyCodeList.size() > selectedKeyIndex)
|
if (selectedKeyCode != -1)
|
||||||
{
|
{
|
||||||
// Check if the value being set is the same as the other column
|
// Check if the value being set is the same as the other column
|
||||||
if (remapBuffer[rowIndex].first[std::abs(int(colIndex) - 1)].index() == 0)
|
if (remapBuffer[rowIndex].first[std::abs(int(colIndex) - 1)].index() == 0)
|
||||||
{
|
{
|
||||||
if (std::get<DWORD>(remapBuffer[rowIndex].first[std::abs(int(colIndex) - 1)]) == keyCodeList[selectedKeyIndex])
|
if (std::get<DWORD>(remapBuffer[rowIndex].first[std::abs(int(colIndex) - 1)]) == selectedKeyCode)
|
||||||
{
|
{
|
||||||
errorType = KeyboardManagerHelper::ErrorType::MapToSameKey;
|
errorType = KeyboardManagerHelper::ErrorType::MapToSameKey;
|
||||||
}
|
}
|
||||||
@@ -33,7 +34,7 @@ namespace BufferValidationHelpers
|
|||||||
{
|
{
|
||||||
if (remapBuffer[i].first[colIndex].index() == 0)
|
if (remapBuffer[i].first[colIndex].index() == 0)
|
||||||
{
|
{
|
||||||
KeyboardManagerHelper::ErrorType result = KeyboardManagerHelper::DoKeysOverlap(std::get<DWORD>(remapBuffer[i].first[colIndex]), keyCodeList[selectedKeyIndex]);
|
KeyboardManagerHelper::ErrorType result = KeyboardManagerHelper::DoKeysOverlap(std::get<DWORD>(remapBuffer[i].first[colIndex]), selectedKeyCode);
|
||||||
if (result != KeyboardManagerHelper::ErrorType::NoError)
|
if (result != KeyboardManagerHelper::ErrorType::NoError)
|
||||||
{
|
{
|
||||||
errorType = result;
|
errorType = result;
|
||||||
@@ -49,7 +50,7 @@ namespace BufferValidationHelpers
|
|||||||
// If there is no error, set the buffer
|
// If there is no error, set the buffer
|
||||||
if (errorType == KeyboardManagerHelper::ErrorType::NoError)
|
if (errorType == KeyboardManagerHelper::ErrorType::NoError)
|
||||||
{
|
{
|
||||||
remapBuffer[rowIndex].first[colIndex] = keyCodeList[selectedKeyIndex];
|
remapBuffer[rowIndex].first[colIndex] = selectedKeyCode;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -66,18 +67,17 @@ namespace BufferValidationHelpers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Function to validate an element of the shortcut remap buffer when the selection has changed
|
// Function to validate an element of the shortcut remap buffer when the selection has changed
|
||||||
std::pair<KeyboardManagerHelper::ErrorType, DropDownAction> ValidateShortcutBufferElement(int rowIndex, int colIndex, uint32_t dropDownIndex, const std::vector<int32_t>& selectedIndices, std::wstring appName, bool isHybridControl, const std::vector<DWORD>& keyCodeList, const RemapBuffer& remapBuffer, bool dropDownFound)
|
std::pair<KeyboardManagerHelper::ErrorType, DropDownAction> ValidateShortcutBufferElement(int rowIndex, int colIndex, uint32_t dropDownIndex, const std::vector<int32_t>& selectedCodes, std::wstring appName, bool isHybridControl, const RemapBuffer& remapBuffer, bool dropDownFound)
|
||||||
{
|
{
|
||||||
BufferValidationHelpers::DropDownAction dropDownAction = BufferValidationHelpers::DropDownAction::NoAction;
|
BufferValidationHelpers::DropDownAction dropDownAction = BufferValidationHelpers::DropDownAction::NoAction;
|
||||||
KeyboardManagerHelper::ErrorType errorType = KeyboardManagerHelper::ErrorType::NoError;
|
KeyboardManagerHelper::ErrorType errorType = KeyboardManagerHelper::ErrorType::NoError;
|
||||||
size_t dropDownCount = selectedIndices.size();
|
size_t dropDownCount = selectedCodes.size();
|
||||||
std::vector<DWORD> selectedKeyCodes = KeyboardManagerHelper::GetKeyCodesFromSelectedIndices(selectedIndices, keyCodeList);
|
DWORD selectedKeyCode = dropDownFound ? selectedCodes[dropDownIndex] : -1;
|
||||||
int selectedKeyIndex = dropDownFound ? selectedIndices[dropDownIndex] : -1;
|
|
||||||
|
|
||||||
if (selectedKeyIndex != -1 && keyCodeList.size() > selectedKeyIndex && dropDownFound)
|
if (selectedKeyCode != -1 && dropDownFound)
|
||||||
{
|
{
|
||||||
// If only 1 drop down and action key is chosen: Warn that a modifier must be chosen (if the drop down is not for a hybrid scenario)
|
// If only 1 drop down and action key is chosen: Warn that a modifier must be chosen (if the drop down is not for a hybrid scenario)
|
||||||
if (dropDownCount == 1 && !KeyboardManagerHelper::IsModifierKey(keyCodeList[selectedKeyIndex]) && !isHybridControl)
|
if (dropDownCount == 1 && !KeyboardManagerHelper::IsModifierKey(selectedKeyCode) && !isHybridControl)
|
||||||
{
|
{
|
||||||
// warn and reset the drop down
|
// warn and reset the drop down
|
||||||
errorType = KeyboardManagerHelper::ErrorType::ShortcutStartWithModifier;
|
errorType = KeyboardManagerHelper::ErrorType::ShortcutStartWithModifier;
|
||||||
@@ -86,10 +86,10 @@ namespace BufferValidationHelpers
|
|||||||
else if (dropDownIndex == dropDownCount - 1)
|
else if (dropDownIndex == dropDownCount - 1)
|
||||||
{
|
{
|
||||||
// If last drop down and a modifier is selected: add a new drop down (max drop down count should be enforced)
|
// If last drop down and a modifier is selected: add a new drop down (max drop down count should be enforced)
|
||||||
if (KeyboardManagerHelper::IsModifierKey(keyCodeList[selectedKeyIndex]) && dropDownCount < KeyboardManagerConstants::MaxShortcutSize)
|
if (KeyboardManagerHelper::IsModifierKey(selectedKeyCode) && dropDownCount < KeyboardManagerConstants::MaxShortcutSize)
|
||||||
{
|
{
|
||||||
// If it matched any of the previous modifiers then reset that drop down
|
// If it matched any of the previous modifiers then reset that drop down
|
||||||
if (KeyboardManagerHelper::CheckRepeatedModifier(selectedKeyCodes, selectedKeyIndex, keyCodeList))
|
if (KeyboardManagerHelper::CheckRepeatedModifier(selectedCodes, selectedKeyCode))
|
||||||
{
|
{
|
||||||
// warn and reset the drop down
|
// warn and reset the drop down
|
||||||
errorType = KeyboardManagerHelper::ErrorType::ShortcutCannotHaveRepeatedModifier;
|
errorType = KeyboardManagerHelper::ErrorType::ShortcutCannotHaveRepeatedModifier;
|
||||||
@@ -101,13 +101,13 @@ namespace BufferValidationHelpers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If last drop down and a modifier is selected but there are already max drop downs: warn the user
|
// If last drop down and a modifier is selected but there are already max drop downs: warn the user
|
||||||
else if (KeyboardManagerHelper::IsModifierKey(keyCodeList[selectedKeyIndex]) && dropDownCount >= KeyboardManagerConstants::MaxShortcutSize)
|
else if (KeyboardManagerHelper::IsModifierKey(selectedKeyCode) && dropDownCount >= KeyboardManagerConstants::MaxShortcutSize)
|
||||||
{
|
{
|
||||||
// warn and reset the drop down
|
// warn and reset the drop down
|
||||||
errorType = KeyboardManagerHelper::ErrorType::ShortcutMaxShortcutSizeOneActionKey;
|
errorType = KeyboardManagerHelper::ErrorType::ShortcutMaxShortcutSizeOneActionKey;
|
||||||
}
|
}
|
||||||
// If None is selected but it's the last index: warn
|
// If None is selected but it's the last index: warn
|
||||||
else if (keyCodeList[selectedKeyIndex] == 0)
|
else if (selectedKeyCode == 0)
|
||||||
{
|
{
|
||||||
// If it is a hybrid control and there are 2 drop downs then deletion is allowed
|
// If it is a hybrid control and there are 2 drop downs then deletion is allowed
|
||||||
if (isHybridControl && dropDownCount == KeyboardManagerConstants::MinShortcutSize)
|
if (isHybridControl && dropDownCount == KeyboardManagerConstants::MinShortcutSize)
|
||||||
@@ -123,7 +123,7 @@ namespace BufferValidationHelpers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Disable can not be selected if one modifier key has already been selected
|
// Disable can not be selected if one modifier key has already been selected
|
||||||
else if (keyCodeList[selectedKeyIndex] == CommonSharedConstants::VK_DISABLED && dropDownIndex)
|
else if (selectedKeyCode == CommonSharedConstants::VK_DISABLED && dropDownIndex)
|
||||||
{
|
{
|
||||||
errorType = KeyboardManagerHelper::ErrorType::ShortcutDisableAsActionKey;
|
errorType = KeyboardManagerHelper::ErrorType::ShortcutDisableAsActionKey;
|
||||||
}
|
}
|
||||||
@@ -132,10 +132,10 @@ namespace BufferValidationHelpers
|
|||||||
// If it is not the last drop down
|
// If it is not the last drop down
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (KeyboardManagerHelper::IsModifierKey(keyCodeList[selectedKeyIndex]))
|
if (KeyboardManagerHelper::IsModifierKey(selectedKeyCode))
|
||||||
{
|
{
|
||||||
// If it matched any of the previous modifiers then reset that drop down
|
// If it matched any of the previous modifiers then reset that drop down
|
||||||
if (KeyboardManagerHelper::CheckRepeatedModifier(selectedKeyCodes, selectedKeyIndex, keyCodeList))
|
if (KeyboardManagerHelper::CheckRepeatedModifier(selectedCodes, selectedKeyCode))
|
||||||
{
|
{
|
||||||
// warn and reset the drop down
|
// warn and reset the drop down
|
||||||
errorType = KeyboardManagerHelper::ErrorType::ShortcutCannotHaveRepeatedModifier;
|
errorType = KeyboardManagerHelper::ErrorType::ShortcutCannotHaveRepeatedModifier;
|
||||||
@@ -143,13 +143,13 @@ namespace BufferValidationHelpers
|
|||||||
// If not, the modifier key will be set
|
// If not, the modifier key will be set
|
||||||
}
|
}
|
||||||
// If None is selected and there are more than 2 drop downs
|
// If None is selected and there are more than 2 drop downs
|
||||||
else if (keyCodeList[selectedKeyIndex] == 0 && dropDownCount > KeyboardManagerConstants::MinShortcutSize)
|
else if (selectedKeyCode == 0 && dropDownCount > KeyboardManagerConstants::MinShortcutSize)
|
||||||
{
|
{
|
||||||
// set delete drop down flag
|
// set delete drop down flag
|
||||||
dropDownAction = BufferValidationHelpers::DropDownAction::DeleteDropDown;
|
dropDownAction = BufferValidationHelpers::DropDownAction::DeleteDropDown;
|
||||||
// do not delete the drop down now since there may be some other error which would cause the drop down to be invalid after removal
|
// do not delete the drop down now since there may be some other error which would cause the drop down to be invalid after removal
|
||||||
}
|
}
|
||||||
else if (keyCodeList[selectedKeyIndex] == 0 && dropDownCount <= KeyboardManagerConstants::MinShortcutSize)
|
else if (selectedKeyCode == 0 && dropDownCount <= KeyboardManagerConstants::MinShortcutSize)
|
||||||
{
|
{
|
||||||
// If it is a hybrid control and there are 2 drop downs then deletion is allowed
|
// If it is a hybrid control and there are 2 drop downs then deletion is allowed
|
||||||
if (isHybridControl && dropDownCount == KeyboardManagerConstants::MinShortcutSize)
|
if (isHybridControl && dropDownCount == KeyboardManagerConstants::MinShortcutSize)
|
||||||
@@ -165,7 +165,7 @@ namespace BufferValidationHelpers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Allow selection of VK_DISABLE only in first dropdown
|
// Allow selection of VK_DISABLE only in first dropdown
|
||||||
else if (keyCodeList[selectedKeyIndex] == CommonSharedConstants::VK_DISABLED && dropDownIndex)
|
else if (selectedKeyCode == CommonSharedConstants::VK_DISABLED && dropDownIndex)
|
||||||
{
|
{
|
||||||
errorType = KeyboardManagerHelper::ErrorType::ShortcutDisableAsActionKey;
|
errorType = KeyboardManagerHelper::ErrorType::ShortcutDisableAsActionKey;
|
||||||
}
|
}
|
||||||
@@ -175,7 +175,7 @@ namespace BufferValidationHelpers
|
|||||||
bool isClear = true;
|
bool isClear = true;
|
||||||
for (int i = dropDownIndex + 1; i < (int)dropDownCount; i++)
|
for (int i = dropDownIndex + 1; i < (int)dropDownCount; i++)
|
||||||
{
|
{
|
||||||
if (selectedIndices[i] != -1)
|
if (selectedCodes[i] != -1)
|
||||||
{
|
{
|
||||||
isClear = false;
|
isClear = false;
|
||||||
break;
|
break;
|
||||||
@@ -205,14 +205,14 @@ namespace BufferValidationHelpers
|
|||||||
if (errorType == KeyboardManagerHelper::ErrorType::NoError)
|
if (errorType == KeyboardManagerHelper::ErrorType::NoError)
|
||||||
{
|
{
|
||||||
KeyShortcutUnion tempShortcut;
|
KeyShortcutUnion tempShortcut;
|
||||||
if (isHybridControl && selectedKeyCodes.size() == 1)
|
if (isHybridControl && KeyDropDownControl::GetNumberOfSelectedKeys(selectedCodes) == 1)
|
||||||
{
|
{
|
||||||
tempShortcut = selectedKeyCodes[0];
|
tempShortcut = *std::find_if(selectedCodes.begin(), selectedCodes.end(), [](int32_t a) { return a != -1 && a != 0; });
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tempShortcut = Shortcut();
|
tempShortcut = Shortcut();
|
||||||
std::get<Shortcut>(tempShortcut).SetKeyCodes(selectedKeyCodes);
|
std::get<Shortcut>(tempShortcut).SetKeyCodes(selectedCodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert app name to lower case
|
// Convert app name to lower case
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ namespace BufferValidationHelpers
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Function to validate and update an element of the key remap buffer when the selection has changed
|
// Function to validate and update an element of the key remap buffer when the selection has changed
|
||||||
KeyboardManagerHelper::ErrorType ValidateAndUpdateKeyBufferElement(int rowIndex, int colIndex, int selectedKeyIndex, const std::vector<DWORD>& keyCodeList, RemapBuffer& remapBuffer);
|
KeyboardManagerHelper::ErrorType ValidateAndUpdateKeyBufferElement(int rowIndex, int colIndex, int selectedKeyCode, RemapBuffer& remapBuffer);
|
||||||
|
|
||||||
// Function to validate an element of the shortcut remap buffer when the selection has changed
|
// Function to validate an element of the shortcut remap buffer when the selection has changed
|
||||||
std::pair<KeyboardManagerHelper::ErrorType, DropDownAction> ValidateShortcutBufferElement(int rowIndex, int colIndex, uint32_t dropDownIndex, const std::vector<int32_t>& selectedIndices, std::wstring appName, bool isHybridControl, const std::vector<DWORD>& keyCodeList, const RemapBuffer& remapBuffer, bool dropDownFound);
|
std::pair<KeyboardManagerHelper::ErrorType, DropDownAction> ValidateShortcutBufferElement(int rowIndex, int colIndex, uint32_t dropDownIndex, const std::vector<int32_t>& selectedCodes, std::wstring appName, bool isHybridControl, const RemapBuffer& remapBuffer, bool dropDownFound);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,29 +5,34 @@
|
|||||||
#include "BufferValidationHelpers.h"
|
#include "BufferValidationHelpers.h"
|
||||||
#include <common\shared_constants.h>
|
#include <common\shared_constants.h>
|
||||||
#include <common\keyboard_layout_impl.h>
|
#include <common\keyboard_layout_impl.h>
|
||||||
|
#include <modules\keyboardmanager\common\Helpers.h>
|
||||||
|
|
||||||
// Initialized to null
|
// Initialized to null
|
||||||
KeyboardManagerState* KeyDropDownControl::keyboardManagerState = nullptr;
|
KeyboardManagerState* KeyDropDownControl::keyboardManagerState = nullptr;
|
||||||
|
|
||||||
// Get keys code list depending if Disable is in dropdown
|
// Get selected value of dropdown or -1 if nothing is selected
|
||||||
std::vector<DWORD> KeyDropDownControl::GetKeyCodeList(bool isShortcut, bool renderDisable)
|
DWORD KeyDropDownControl::GetSelectedValue(ComboBox comboBox)
|
||||||
{
|
{
|
||||||
auto list = keyboardManagerState->keyboardMap.GetKeyCodeList(isShortcut);
|
auto dataContext = comboBox.SelectedValue();
|
||||||
if (renderDisable)
|
if (!dataContext)
|
||||||
{
|
return -1;
|
||||||
list.insert(list.begin(), CommonSharedConstants::VK_DISABLED);
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
auto value = winrt::unbox_value<hstring>(dataContext);
|
||||||
|
return stoi(std::wstring(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
void KeyDropDownControl::SetSelectedValue(std::wstring value)
|
||||||
|
{
|
||||||
|
this->dropDown.as<ComboBox>().SelectedValue(winrt::box_value(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get keys name list depending if Disable is in dropdown
|
// Get keys name list depending if Disable is in dropdown
|
||||||
std::vector<std::wstring> KeyDropDownControl::GetKeyNameList(bool isShortcut, bool renderDisable)
|
std::vector<std::pair<DWORD, std::wstring>> KeyDropDownControl::GetKeyList(bool isShortcut, bool renderDisable)
|
||||||
{
|
{
|
||||||
auto list = keyboardManagerState->keyboardMap.GetKeyNameList(isShortcut);
|
auto list = keyboardManagerState->keyboardMap.GetKeyNameList(isShortcut);
|
||||||
if (renderDisable)
|
if (renderDisable)
|
||||||
{
|
{
|
||||||
list.insert(list.begin(), keyboardManagerState->keyboardMap.GetKeyName(CommonSharedConstants::VK_DISABLED));
|
list.insert(list.begin(), { CommonSharedConstants::VK_DISABLED, keyboardManagerState->keyboardMap.GetKeyName(CommonSharedConstants::VK_DISABLED) });
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
@@ -51,8 +56,9 @@ void KeyDropDownControl::SetDefaultProperties(bool isShortcut, bool renderDisabl
|
|||||||
dropDown.as<ComboBox>().MaxDropDownHeight(KeyboardManagerConstants::TableDropDownHeight);
|
dropDown.as<ComboBox>().MaxDropDownHeight(KeyboardManagerConstants::TableDropDownHeight);
|
||||||
// Initialise layout attribute
|
// Initialise layout attribute
|
||||||
previousLayout = GetKeyboardLayout(0);
|
previousLayout = GetKeyboardLayout(0);
|
||||||
keyCodeList = GetKeyCodeList(isShortcut, renderDisable);
|
dropDown.as<ComboBox>().SelectedValuePath(L"DataContext");
|
||||||
dropDown.as<ComboBox>().ItemsSource(KeyboardManagerHelper::ToBoxValue(GetKeyNameList(isShortcut, renderDisable)));
|
dropDown.as<ComboBox>().ItemsSource(KeyboardManagerHelper::ToBoxValue(GetKeyList(isShortcut, renderDisable)));
|
||||||
|
|
||||||
// drop down open handler - to reload the items with the latest layout
|
// drop down open handler - to reload the items with the latest layout
|
||||||
dropDown.as<ComboBox>().DropDownOpened([&, isShortcut](winrt::Windows::Foundation::IInspectable const& sender, auto args) {
|
dropDown.as<ComboBox>().DropDownOpened([&, isShortcut](winrt::Windows::Foundation::IInspectable const& sender, auto args) {
|
||||||
ComboBox currentDropDown = sender.as<ComboBox>();
|
ComboBox currentDropDown = sender.as<ComboBox>();
|
||||||
@@ -82,8 +88,7 @@ void KeyDropDownControl::CheckAndUpdateKeyboardLayout(ComboBox currentDropDown,
|
|||||||
// Check if the layout has changed
|
// Check if the layout has changed
|
||||||
if (previousLayout != layout)
|
if (previousLayout != layout)
|
||||||
{
|
{
|
||||||
keyCodeList = GetKeyCodeList(isShortcut, renderDisable);
|
currentDropDown.ItemsSource(KeyboardManagerHelper::ToBoxValue(GetKeyList(isShortcut, renderDisable)));
|
||||||
currentDropDown.ItemsSource(KeyboardManagerHelper::ToBoxValue(GetKeyNameList(isShortcut, renderDisable)));
|
|
||||||
previousLayout = layout;
|
previousLayout = layout;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,7 +99,8 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel singleKeyCo
|
|||||||
// drop down selection handler
|
// drop down selection handler
|
||||||
auto onSelectionChange = [&, table, singleKeyControl, colIndex](winrt::Windows::Foundation::IInspectable const& sender) {
|
auto onSelectionChange = [&, table, singleKeyControl, colIndex](winrt::Windows::Foundation::IInspectable const& sender) {
|
||||||
ComboBox currentDropDown = sender.as<ComboBox>();
|
ComboBox currentDropDown = sender.as<ComboBox>();
|
||||||
int selectedKeyIndex = currentDropDown.SelectedIndex();
|
int selectedKeyCode = GetSelectedValue(currentDropDown);
|
||||||
|
|
||||||
// Get row index of the single key control
|
// Get row index of the single key control
|
||||||
uint32_t controlIndex;
|
uint32_t controlIndex;
|
||||||
bool indexFound = table.Children().IndexOf(singleKeyControl, controlIndex);
|
bool indexFound = table.Children().IndexOf(singleKeyControl, controlIndex);
|
||||||
@@ -104,7 +110,7 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel singleKeyCo
|
|||||||
int rowIndex = table.GetRow(singleKeyControl) - 1;
|
int rowIndex = table.GetRow(singleKeyControl) - 1;
|
||||||
|
|
||||||
// Validate current remap selection
|
// Validate current remap selection
|
||||||
KeyboardManagerHelper::ErrorType errorType = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(rowIndex, colIndex, selectedKeyIndex, keyCodeList, singleKeyRemapBuffer);
|
KeyboardManagerHelper::ErrorType errorType = BufferValidationHelpers::ValidateAndUpdateKeyBufferElement(rowIndex, colIndex, selectedKeyCode, singleKeyRemapBuffer);
|
||||||
|
|
||||||
// If there is an error set the warning flyout
|
// If there is an error set the warning flyout
|
||||||
if (errorType != KeyboardManagerHelper::ErrorType::NoError)
|
if (errorType != KeyboardManagerHelper::ErrorType::NoError)
|
||||||
@@ -132,7 +138,6 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel singleKeyCo
|
|||||||
std::pair<KeyboardManagerHelper::ErrorType, int> KeyDropDownControl::ValidateShortcutSelection(Grid table, StackPanel shortcutControl, StackPanel parent, int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow)
|
std::pair<KeyboardManagerHelper::ErrorType, int> KeyDropDownControl::ValidateShortcutSelection(Grid table, StackPanel shortcutControl, StackPanel parent, int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow)
|
||||||
{
|
{
|
||||||
ComboBox currentDropDown = dropDown.as<ComboBox>();
|
ComboBox currentDropDown = dropDown.as<ComboBox>();
|
||||||
int selectedKeyIndex = currentDropDown.SelectedIndex();
|
|
||||||
uint32_t dropDownIndex = -1;
|
uint32_t dropDownIndex = -1;
|
||||||
bool dropDownFound = parent.Children().IndexOf(currentDropDown, dropDownIndex);
|
bool dropDownFound = parent.Children().IndexOf(currentDropDown, dropDownIndex);
|
||||||
// Get row index of the single key control
|
// Get row index of the single key control
|
||||||
@@ -146,7 +151,7 @@ std::pair<KeyboardManagerHelper::ErrorType, int> KeyDropDownControl::ValidateSho
|
|||||||
// GetRow will give the row index including the table header
|
// GetRow will give the row index including the table header
|
||||||
rowIndex = table.GetRow(shortcutControl) - 1;
|
rowIndex = table.GetRow(shortcutControl) - 1;
|
||||||
|
|
||||||
std::vector<int32_t> selectedIndices = GetSelectedIndicesFromStackPanel(parent);
|
std::vector<int32_t> selectedCodes = GetSelectedCodesFromStackPanel(parent);
|
||||||
|
|
||||||
std::wstring appName;
|
std::wstring appName;
|
||||||
if (targetApp != nullptr)
|
if (targetApp != nullptr)
|
||||||
@@ -155,7 +160,7 @@ std::pair<KeyboardManagerHelper::ErrorType, int> KeyDropDownControl::ValidateSho
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validate shortcut element
|
// Validate shortcut element
|
||||||
validationResult = BufferValidationHelpers::ValidateShortcutBufferElement(rowIndex, colIndex, dropDownIndex, selectedIndices, appName, isHybridControl, keyCodeList, shortcutRemapBuffer, dropDownFound);
|
validationResult = BufferValidationHelpers::ValidateShortcutBufferElement(rowIndex, colIndex, dropDownIndex, selectedCodes, appName, isHybridControl, shortcutRemapBuffer, dropDownFound);
|
||||||
|
|
||||||
// Add or clear unused drop downs
|
// Add or clear unused drop downs
|
||||||
if (validationResult.second == BufferValidationHelpers::DropDownAction::AddDropDown)
|
if (validationResult.second == BufferValidationHelpers::DropDownAction::AddDropDown)
|
||||||
@@ -229,7 +234,7 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel shortcutCon
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reset the buffer based on the new selected drop down items. Use static key code list since the KeyDropDownControl object might be deleted
|
// Reset the buffer based on the new selected drop down items. Use static key code list since the KeyDropDownControl object might be deleted
|
||||||
std::vector selectedKeyCodes = KeyboardManagerHelper::GetKeyCodesFromSelectedIndices(GetSelectedIndicesFromStackPanel(parent), GetKeyCodeList(true, colIndex == 1));
|
std::vector<int32_t> selectedKeyCodes = GetSelectedCodesFromStackPanel(parent);
|
||||||
if (!isHybridControl)
|
if (!isHybridControl)
|
||||||
{
|
{
|
||||||
std::get<Shortcut>(shortcutRemapBuffer[validationResult.second].first[colIndex]).SetKeyCodes(selectedKeyCodes);
|
std::get<Shortcut>(shortcutRemapBuffer[validationResult.second].first[colIndex]).SetKeyCodes(selectedKeyCodes);
|
||||||
@@ -237,7 +242,7 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel shortcutCon
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// If exactly one key is selected consider it to be a key remap
|
// If exactly one key is selected consider it to be a key remap
|
||||||
if (selectedKeyCodes.size() == 1)
|
if (GetNumberOfSelectedKeys(selectedKeyCodes) == 1)
|
||||||
{
|
{
|
||||||
shortcutRemapBuffer[validationResult.second].first[colIndex] = selectedKeyCodes[0];
|
shortcutRemapBuffer[validationResult.second].first[colIndex] = selectedKeyCodes[0];
|
||||||
}
|
}
|
||||||
@@ -294,12 +299,6 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel shortcutCon
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to set the selected index of the drop down
|
|
||||||
void KeyDropDownControl::SetSelectedIndex(int32_t index)
|
|
||||||
{
|
|
||||||
dropDown.as<ComboBox>().SelectedIndex(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Function to return the combo box element of the drop down
|
// Function to return the combo box element of the drop down
|
||||||
ComboBox KeyDropDownControl::GetComboBox()
|
ComboBox KeyDropDownControl::GetComboBox()
|
||||||
{
|
{
|
||||||
@@ -319,18 +318,18 @@ void KeyDropDownControl::AddDropDown(Grid table, StackPanel shortcutControl, Sta
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Function to get the list of key codes from the shortcut combo box stack panel
|
// Function to get the list of key codes from the shortcut combo box stack panel
|
||||||
std::vector<int32_t> KeyDropDownControl::GetSelectedIndicesFromStackPanel(StackPanel parent)
|
std::vector<int32_t> KeyDropDownControl::GetSelectedCodesFromStackPanel(StackPanel parent)
|
||||||
{
|
{
|
||||||
std::vector<int32_t> selectedIndices;
|
std::vector<int32_t> selectedKeyCodes;
|
||||||
|
|
||||||
// Get selected indices for each drop down
|
// Get selected indices for each drop down
|
||||||
for (int i = 0; i < (int)parent.Children().Size(); i++)
|
for (int i = 0; i < (int)parent.Children().Size(); i++)
|
||||||
{
|
{
|
||||||
ComboBox ItDropDown = parent.Children().GetAt(i).as<ComboBox>();
|
ComboBox ItDropDown = parent.Children().GetAt(i).as<ComboBox>();
|
||||||
selectedIndices.push_back(ItDropDown.SelectedIndex());
|
selectedKeyCodes.push_back(GetSelectedValue(ItDropDown));
|
||||||
}
|
}
|
||||||
|
|
||||||
return selectedIndices;
|
return selectedKeyCodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function for validating the selection of shortcuts for all the associated drop downs
|
// Function for validating the selection of shortcuts for all the associated drop downs
|
||||||
@@ -340,9 +339,9 @@ void KeyDropDownControl::ValidateShortcutFromDropDownList(Grid table, StackPanel
|
|||||||
for (int i = 0; i < keyDropDownControlObjects.size(); i++)
|
for (int i = 0; i < keyDropDownControlObjects.size(); i++)
|
||||||
{
|
{
|
||||||
// Check for errors only if the current selection is a valid shortcut
|
// Check for errors only if the current selection is a valid shortcut
|
||||||
std::vector<DWORD> selectedKeyCodes = KeyboardManagerHelper::GetKeyCodesFromSelectedIndices(keyDropDownControlObjects[i]->GetSelectedIndicesFromStackPanel(parent), GetKeyCodeList(true, colIndex == 1));
|
std::vector<int32_t> selectedKeyCodes = GetSelectedCodesFromStackPanel(parent);
|
||||||
KeyShortcutUnion currentShortcut;
|
KeyShortcutUnion currentShortcut;
|
||||||
if (selectedKeyCodes.size() == 1 && isHybridControl)
|
if (GetNumberOfSelectedKeys(selectedKeyCodes) == 1 && isHybridControl)
|
||||||
{
|
{
|
||||||
currentShortcut = selectedKeyCodes[0];
|
currentShortcut = selectedKeyCodes[0];
|
||||||
}
|
}
|
||||||
@@ -354,7 +353,7 @@ void KeyDropDownControl::ValidateShortcutFromDropDownList(Grid table, StackPanel
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the key/shortcut is valid and that drop down is not empty
|
// If the key/shortcut is valid and that drop down is not empty
|
||||||
if (((currentShortcut.index() == 0 && std::get<DWORD>(currentShortcut) != NULL) || (currentShortcut.index() == 1 && std::get<Shortcut>(currentShortcut).IsValidShortcut())) && keyDropDownControlObjects[i]->GetComboBox().SelectedIndex() != -1)
|
if (((currentShortcut.index() == 0 && std::get<DWORD>(currentShortcut) != NULL) || (currentShortcut.index() == 1 && std::get<Shortcut>(currentShortcut).IsValidShortcut())) && GetSelectedValue(keyDropDownControlObjects[i]->GetComboBox()) != -1)
|
||||||
{
|
{
|
||||||
keyDropDownControlObjects[i]->ValidateShortcutSelection(table, shortcutControl, parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, isSingleKeyWindow);
|
keyDropDownControlObjects[i]->ValidateShortcutSelection(table, shortcutControl, parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, isSingleKeyWindow);
|
||||||
}
|
}
|
||||||
@@ -376,9 +375,7 @@ void KeyDropDownControl::AddShortcutToControl(Shortcut shortcut, Grid table, Sta
|
|||||||
parent.Children().Clear();
|
parent.Children().Clear();
|
||||||
// Remove references to the old drop down objects to destroy them
|
// Remove references to the old drop down objects to destroy them
|
||||||
keyDropDownControlObjects.clear();
|
keyDropDownControlObjects.clear();
|
||||||
|
|
||||||
std::vector<DWORD> shortcutKeyCodes = shortcut.GetKeyCodes();
|
std::vector<DWORD> shortcutKeyCodes = shortcut.GetKeyCodes();
|
||||||
std::vector<DWORD> keyCodeList = GetKeyCodeList(true, colIndex == 1);
|
|
||||||
if (shortcutKeyCodes.size() != 0)
|
if (shortcutKeyCodes.size() != 0)
|
||||||
{
|
{
|
||||||
bool ignoreWarning = false;
|
bool ignoreWarning = false;
|
||||||
@@ -393,17 +390,19 @@ void KeyDropDownControl::AddShortcutToControl(Shortcut shortcut, Grid table, Sta
|
|||||||
|
|
||||||
for (int i = 0; i < shortcutKeyCodes.size(); i++)
|
for (int i = 0; i < shortcutKeyCodes.size(); i++)
|
||||||
{
|
{
|
||||||
// New drop down gets added automatically when the SelectedIndex is set
|
// New drop down gets added automatically when the SelectedValue(key code) is set
|
||||||
if (i < (int)parent.Children().Size())
|
if (i < (int)parent.Children().Size())
|
||||||
{
|
{
|
||||||
ComboBox currentDropDown = parent.Children().GetAt(i).as<ComboBox>();
|
ComboBox currentDropDown = parent.Children().GetAt(i).as<ComboBox>();
|
||||||
auto it = std::find(keyCodeList.begin(), keyCodeList.end(), shortcutKeyCodes[i]);
|
currentDropDown.SelectedValue(winrt::box_value(std::to_wstring(shortcutKeyCodes[i])));
|
||||||
if (it != keyCodeList.end())
|
|
||||||
{
|
|
||||||
currentDropDown.SelectedIndex((int32_t)std::distance(keyCodeList.begin(), it));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
parent.UpdateLayout();
|
parent.UpdateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get number of selected keys. Do not count -1 and 0 values as they stand for Not selected and None
|
||||||
|
int KeyDropDownControl::GetNumberOfSelectedKeys(std::vector<int32_t> keyCodes)
|
||||||
|
{
|
||||||
|
return (int)std::count_if(keyCodes.begin(), keyCodes.end(), [](int32_t a) { return a != -1 && a != 0; });
|
||||||
|
}
|
||||||
@@ -33,8 +33,6 @@ private:
|
|||||||
winrt::Windows::Foundation::IInspectable dropDown;
|
winrt::Windows::Foundation::IInspectable dropDown;
|
||||||
// Stores the previous layout
|
// Stores the previous layout
|
||||||
HKL previousLayout = 0;
|
HKL previousLayout = 0;
|
||||||
// Stores the key code list
|
|
||||||
std::vector<DWORD> keyCodeList;
|
|
||||||
// Stores the flyout warning message
|
// Stores the flyout warning message
|
||||||
winrt::Windows::Foundation::IInspectable warningMessage;
|
winrt::Windows::Foundation::IInspectable warningMessage;
|
||||||
// Stores the flyout attached to the current drop down
|
// Stores the flyout attached to the current drop down
|
||||||
@@ -48,6 +46,9 @@ private:
|
|||||||
// Function to check if the layout has changed and accordingly update the drop down list
|
// Function to check if the layout has changed and accordingly update the drop down list
|
||||||
void CheckAndUpdateKeyboardLayout(ComboBox currentDropDown, bool isShortcut, bool renderDisable);
|
void CheckAndUpdateKeyboardLayout(ComboBox currentDropDown, bool isShortcut, bool renderDisable);
|
||||||
|
|
||||||
|
// Get selected value of dropdown or -1 if nothing is selected
|
||||||
|
static DWORD GetSelectedValue(ComboBox comboBox);
|
||||||
|
|
||||||
// Function to set accessible name for combobox
|
// Function to set accessible name for combobox
|
||||||
static void SetAccessibleNameForComboBox(ComboBox dropDown, int index);
|
static void SetAccessibleNameForComboBox(ComboBox dropDown, int index);
|
||||||
public:
|
public:
|
||||||
@@ -70,9 +71,6 @@ public:
|
|||||||
// Function to set selection handler for shortcut drop down. Needs to be called after the constructor since the shortcutControl StackPanel is null if called in the constructor
|
// Function to set selection handler for shortcut drop down. Needs to be called after the constructor since the shortcutControl StackPanel is null if called in the constructor
|
||||||
void SetSelectionHandler(winrt::Windows::UI::Xaml::Controls::Grid& table, winrt::Windows::UI::Xaml::Controls::StackPanel shortcutControl, winrt::Windows::UI::Xaml::Controls::StackPanel parent, int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, winrt::Windows::UI::Xaml::Controls::TextBox& targetApp, bool isHybridControl, bool isSingleKeyWindow);
|
void SetSelectionHandler(winrt::Windows::UI::Xaml::Controls::Grid& table, winrt::Windows::UI::Xaml::Controls::StackPanel shortcutControl, winrt::Windows::UI::Xaml::Controls::StackPanel parent, int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, winrt::Windows::UI::Xaml::Controls::TextBox& targetApp, bool isHybridControl, bool isSingleKeyWindow);
|
||||||
|
|
||||||
// Function to set the selected index of the drop down
|
|
||||||
void SetSelectedIndex(int32_t index);
|
|
||||||
|
|
||||||
// Function to return the combo box element of the drop down
|
// Function to return the combo box element of the drop down
|
||||||
ComboBox GetComboBox();
|
ComboBox GetComboBox();
|
||||||
|
|
||||||
@@ -80,7 +78,7 @@ public:
|
|||||||
static void AddDropDown(winrt::Windows::UI::Xaml::Controls::Grid table, winrt::Windows::UI::Xaml::Controls::StackPanel shortcutControl, winrt::Windows::UI::Xaml::Controls::StackPanel parent, const int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, winrt::Windows::UI::Xaml::Controls::TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow, bool ignoreWarning = false);
|
static void AddDropDown(winrt::Windows::UI::Xaml::Controls::Grid table, winrt::Windows::UI::Xaml::Controls::StackPanel shortcutControl, winrt::Windows::UI::Xaml::Controls::StackPanel parent, const int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, winrt::Windows::UI::Xaml::Controls::TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow, bool ignoreWarning = false);
|
||||||
|
|
||||||
// Function to get the list of key codes from the shortcut combo box stack panel
|
// Function to get the list of key codes from the shortcut combo box stack panel
|
||||||
static std::vector<int32_t> GetSelectedIndicesFromStackPanel(StackPanel parent);
|
static std::vector<int32_t> GetSelectedCodesFromStackPanel(StackPanel parent);
|
||||||
|
|
||||||
// Function for validating the selection of shortcuts for all the associated drop downs
|
// Function for validating the selection of shortcuts for all the associated drop downs
|
||||||
static void ValidateShortcutFromDropDownList(Grid table, StackPanel shortcutControl, StackPanel parent, int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow);
|
static void ValidateShortcutFromDropDownList(Grid table, StackPanel shortcutControl, StackPanel parent, int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow);
|
||||||
@@ -88,12 +86,15 @@ public:
|
|||||||
// Function to set the warning message
|
// Function to set the warning message
|
||||||
void SetDropDownError(winrt::Windows::UI::Xaml::Controls::ComboBox currentDropDown, winrt::hstring message);
|
void SetDropDownError(winrt::Windows::UI::Xaml::Controls::ComboBox currentDropDown, winrt::hstring message);
|
||||||
|
|
||||||
|
// Set selected Value
|
||||||
|
void SetSelectedValue(std::wstring value);
|
||||||
|
|
||||||
// Function to add a shortcut to the UI control as combo boxes
|
// Function to add a shortcut to the UI control as combo boxes
|
||||||
static void AddShortcutToControl(Shortcut shortcut, Grid table, StackPanel parent, KeyboardManagerState& keyboardManagerState, const int colIndex, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, RemapBuffer& remapBuffer, StackPanel controlLayout, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow);
|
static void AddShortcutToControl(Shortcut shortcut, Grid table, StackPanel parent, KeyboardManagerState& keyboardManagerState, const int colIndex, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, RemapBuffer& remapBuffer, StackPanel controlLayout, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow);
|
||||||
|
|
||||||
// Get keys code list depending if Disable is in dropdown
|
|
||||||
static std::vector<DWORD> GetKeyCodeList(bool isShortcut, bool renderDisable);
|
|
||||||
|
|
||||||
// Get keys name list depending if Disable is in dropdown
|
// Get keys name list depending if Disable is in dropdown
|
||||||
static std::vector<std::wstring> GetKeyNameList(bool isShortcut, bool renderDisable);
|
static std::vector<std::pair<DWORD,std::wstring>> GetKeyList(bool isShortcut, bool renderDisable);
|
||||||
|
|
||||||
|
// Get number of selected keys. Do not count -1 and 0 values as they stand for Not selected and None
|
||||||
|
static int GetNumberOfSelectedKeys(std::vector<int32_t> keys);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -133,9 +133,10 @@ void ShortcutControl::AddNewShortcutControlRow(Grid& parent, std::vector<std::ve
|
|||||||
KeyDropDownControl::ValidateShortcutFromDropDownList(parent, keyboardRemapControlObjects[rowIndex][1]->getShortcutControl(), keyboardRemapControlObjects[rowIndex][1]->shortcutDropDownStackPanel.as<StackPanel>(), 1, ShortcutControl::shortcutRemapBuffer, keyboardRemapControlObjects[rowIndex][1]->keyDropDownControlObjects, targetAppTextBox, true, false);
|
KeyDropDownControl::ValidateShortcutFromDropDownList(parent, keyboardRemapControlObjects[rowIndex][1]->getShortcutControl(), keyboardRemapControlObjects[rowIndex][1]->shortcutDropDownStackPanel.as<StackPanel>(), 1, ShortcutControl::shortcutRemapBuffer, keyboardRemapControlObjects[rowIndex][1]->keyDropDownControlObjects, targetAppTextBox, true, false);
|
||||||
|
|
||||||
// Reset the buffer based on the selected drop down items
|
// Reset the buffer based on the selected drop down items
|
||||||
std::get<Shortcut>(shortcutRemapBuffer[rowIndex].first[0]).SetKeyCodes(KeyboardManagerHelper::GetKeyCodesFromSelectedIndices(KeyDropDownControl::GetSelectedIndicesFromStackPanel(keyboardRemapControlObjects[rowIndex][0]->shortcutDropDownStackPanel.as<StackPanel>()), KeyDropDownControl::GetKeyCodeList(true, false)));
|
std::get<Shortcut>(shortcutRemapBuffer[rowIndex].first[0]).SetKeyCodes(KeyDropDownControl::GetSelectedCodesFromStackPanel(keyboardRemapControlObjects[rowIndex][0]->shortcutDropDownStackPanel.as<StackPanel>()));
|
||||||
// second column is a hybrid column
|
// second column is a hybrid column
|
||||||
std::vector<DWORD> selectedKeyCodes = KeyboardManagerHelper::GetKeyCodesFromSelectedIndices(KeyDropDownControl::GetSelectedIndicesFromStackPanel(keyboardRemapControlObjects[rowIndex][1]->shortcutDropDownStackPanel.as<StackPanel>()), KeyDropDownControl::GetKeyCodeList(true, true));
|
|
||||||
|
std::vector<int32_t> selectedKeyCodes = KeyDropDownControl::GetSelectedCodesFromStackPanel(keyboardRemapControlObjects[rowIndex][1]->shortcutDropDownStackPanel.as<StackPanel>());
|
||||||
|
|
||||||
// If exactly one key is selected consider it to be a key remap
|
// If exactly one key is selected consider it to be a key remap
|
||||||
if (selectedKeyCodes.size() == 1)
|
if (selectedKeyCodes.size() == 1)
|
||||||
@@ -244,12 +245,7 @@ void ShortcutControl::AddNewShortcutControlRow(Grid& parent, std::vector<std::ve
|
|||||||
|
|
||||||
if (newKeys.index() == 0)
|
if (newKeys.index() == 0)
|
||||||
{
|
{
|
||||||
std::vector<DWORD> shortcutListKeyCodes = KeyDropDownControl::GetKeyCodeList(true, true);
|
keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->keyDropDownControlObjects[0]->SetSelectedValue(std::to_wstring(std::get<DWORD>(newKeys)));
|
||||||
auto it = std::find(shortcutListKeyCodes.begin(), shortcutListKeyCodes.end(), std::get<DWORD>(newKeys));
|
|
||||||
if (it != shortcutListKeyCodes.end())
|
|
||||||
{
|
|
||||||
keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->keyDropDownControlObjects[0]->SetSelectedIndex((int32_t)std::distance(shortcutListKeyCodes.begin(), it));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -106,20 +106,10 @@ void SingleKeyRemapControl::AddNewControlKeyRemapRow(Grid& parent, std::vector<s
|
|||||||
if (originalKey != NULL && !(newKey.index() == 0 && std::get<DWORD>(newKey) == NULL) && !(newKey.index() == 1 && !std::get<Shortcut>(newKey).IsValidShortcut()))
|
if (originalKey != NULL && !(newKey.index() == 0 && std::get<DWORD>(newKey) == NULL) && !(newKey.index() == 1 && !std::get<Shortcut>(newKey).IsValidShortcut()))
|
||||||
{
|
{
|
||||||
singleKeyRemapBuffer.push_back(std::make_pair<RemapBufferItem, std::wstring>(RemapBufferItem{ originalKey, newKey }, L""));
|
singleKeyRemapBuffer.push_back(std::make_pair<RemapBufferItem, std::wstring>(RemapBufferItem{ originalKey, newKey }, L""));
|
||||||
std::vector<DWORD> keyCodes = keyboardManagerState->keyboardMap.GetKeyCodeList();
|
keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][0]->keyDropDownControlObjects[0]->SetSelectedValue(std::to_wstring(originalKey));
|
||||||
std::vector<DWORD> shortcutListKeyCodes = KeyDropDownControl::GetKeyCodeList(true, true);
|
|
||||||
auto it = std::find(keyCodes.begin(), keyCodes.end(), originalKey);
|
|
||||||
if (it != keyCodes.end())
|
|
||||||
{
|
|
||||||
keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][0]->keyDropDownControlObjects[0]->SetSelectedIndex((int32_t)std::distance(keyCodes.begin(), it));
|
|
||||||
}
|
|
||||||
if (newKey.index() == 0)
|
if (newKey.index() == 0)
|
||||||
{
|
{
|
||||||
it = std::find(shortcutListKeyCodes.begin(), shortcutListKeyCodes.end(), std::get<DWORD>(newKey));
|
keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->keyDropDownControlObjects[0]->SetSelectedValue(std::to_wstring(std::get<DWORD>(newKey)));
|
||||||
if (it != shortcutListKeyCodes.end())
|
|
||||||
{
|
|
||||||
keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->keyDropDownControlObjects[0]->SetSelectedIndex((int32_t)std::distance(shortcutListKeyCodes.begin(), it));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -234,11 +224,7 @@ void SingleKeyRemapControl::createDetectKeyWindow(winrt::Windows::Foundation::II
|
|||||||
std::vector<DWORD> keyCodeList = keyboardManagerState.keyboardMap.GetKeyCodeList();
|
std::vector<DWORD> keyCodeList = keyboardManagerState.keyboardMap.GetKeyCodeList();
|
||||||
// Update the drop down list with the new language to ensure that the correct key is displayed
|
// Update the drop down list with the new language to ensure that the correct key is displayed
|
||||||
linkedRemapDropDown.ItemsSource(KeyboardManagerHelper::ToBoxValue(keyboardManagerState.keyboardMap.GetKeyNameList()));
|
linkedRemapDropDown.ItemsSource(KeyboardManagerHelper::ToBoxValue(keyboardManagerState.keyboardMap.GetKeyNameList()));
|
||||||
auto it = std::find(keyCodeList.begin(), keyCodeList.end(), detectedKey);
|
linkedRemapDropDown.SelectedValue(winrt::box_value(std::to_wstring(detectedKey)));
|
||||||
if (it != keyCodeList.end())
|
|
||||||
{
|
|
||||||
linkedRemapDropDown.SelectedIndex((int32_t)std::distance(keyCodeList.begin(), it));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Hide the type key UI
|
// Hide the type key UI
|
||||||
detectRemapKeyBox.Hide();
|
detectRemapKeyBox.Hide();
|
||||||
|
|||||||
Reference in New Issue
Block a user