mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
Get rid of indexes in dropdowns (#7278)
This commit is contained in:
@@ -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>();
|
||||
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;
|
||||
@@ -324,7 +327,7 @@ namespace KeyboardManagerHelper
|
||||
}
|
||||
|
||||
// Function to filter the key codes for artificial key codes
|
||||
DWORD FilterArtificialKeys(const DWORD& key)
|
||||
int32_t FilterArtificialKeys(const int32_t& key)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
@@ -345,57 +348,16 @@ namespace KeyboardManagerHelper
|
||||
}
|
||||
|
||||
// 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
|
||||
int currentDropDownIndex = -1;
|
||||
|
||||
// Find the key index of the current drop down selection so that we skip that index while searching for repeated modifiers
|
||||
// Count the number of keys that are equal to 'selectedKeyCode'
|
||||
int numberOfSameType = 0;
|
||||
for (int i = 0; i < currentKeys.size(); i++)
|
||||
{
|
||||
if (currentKeys[i] == keyCodeList[selectedKeyIndex])
|
||||
{
|
||||
currentDropDownIndex = i;
|
||||
break;
|
||||
}
|
||||
numberOfSameType += KeyboardManagerHelper::GetKeyType(selectedKeyCode) == KeyboardManagerHelper::GetKeyType(currentKeys[i]);
|
||||
}
|
||||
|
||||
bool matchPreviousModifier = false;
|
||||
for (int i = 0; i < currentKeys.size(); i++)
|
||||
{
|
||||
// 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;
|
||||
// If we have at least two keys equal to 'selectedKeyCode' than modifier was repeated
|
||||
return numberOfSameType > 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace KeyboardManagerHelper
|
||||
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
|
||||
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
|
||||
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);
|
||||
|
||||
// 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
|
||||
void SortShortcutVectorBasedOnSize(std::vector<Shortcut>& shortcutVector);
|
||||
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
bool CheckRepeatedModifier(const std::vector<int32_t>& currentKeys, int selectedKeyCodes);
|
||||
}
|
||||
@@ -18,7 +18,7 @@ Shortcut::Shortcut(const std::wstring& shortcutVK) :
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
@@ -505,12 +505,15 @@ std::vector<DWORD> Shortcut::GetKeyCodes()
|
||||
}
|
||||
|
||||
// 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();
|
||||
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);
|
||||
|
||||
// Constructor to initialize shortcut from a list of keys
|
||||
Shortcut(const std::vector<DWORD>& keys);
|
||||
Shortcut(const std::vector<int32_t>& keys);
|
||||
|
||||
// == operator
|
||||
inline bool operator==(const Shortcut& sc) const
|
||||
@@ -153,7 +153,7 @@ public:
|
||||
std::vector<DWORD> GetKeyCodes();
|
||||
|
||||
// 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
|
||||
bool CheckModifiersKeyboardState(InputInterface& ii) const;
|
||||
|
||||
Reference in New Issue
Block a user