[Keyboard Manager] Fix crash in Keyboard Manager by ignoring MapToSameKey warnings on loading (#6714)

* Add extra argument to ignore MapToSameKey error for Key To Shortcut mapping

* added comment
This commit is contained in:
Arjun Balgovind 2020-09-22 13:54:53 -07:00 committed by GitHub
parent c1e9f2de6a
commit 1ef4c43382
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 5 deletions

View File

@ -148,6 +148,13 @@ std::pair<KeyboardManagerHelper::ErrorType, int> KeyDropDownControl::ValidateSho
parent.UpdateLayout();
}
// If ignore key to shortcut warning flag is true and it is a hybrid control in SingleKeyRemapControl, then skip MapToSameKey error
if (isHybridControl && isSingleKeyWindow && ignoreKeyToShortcutWarning && (validationResult.first == KeyboardManagerHelper::ErrorType::MapToSameKey))
{
validationResult.first = KeyboardManagerHelper::ErrorType::NoError;
}
// If the remapping is invalid display an error message
if (validationResult.first != KeyboardManagerHelper::ErrorType::NoError)
{
SetDropDownError(currentDropDown, KeyboardManagerHelper::GetErrorMessage(validationResult.first));
@ -170,6 +177,12 @@ std::pair<KeyboardManagerHelper::ErrorType, int> KeyDropDownControl::ValidateSho
}
}
// Reset ignoreKeyToShortcutWarning
if (ignoreKeyToShortcutWarning)
{
ignoreKeyToShortcutWarning = false;
}
return std::make_pair(validationResult.first, rowIndex);
}
@ -268,9 +281,9 @@ ComboBox KeyDropDownControl::GetComboBox()
}
// Function to add a drop down to the shortcut stack panel
void KeyDropDownControl::AddDropDown(Grid table, StackPanel shortcutControl, StackPanel parent, const int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow)
void KeyDropDownControl::AddDropDown(Grid table, StackPanel shortcutControl, StackPanel parent, const int colIndex, RemapBuffer& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, TextBox targetApp, bool isHybridControl, bool isSingleKeyWindow, bool ignoreWarning)
{
keyDropDownControlObjects.push_back(std::move(std::unique_ptr<KeyDropDownControl>(new KeyDropDownControl(true))));
keyDropDownControlObjects.push_back(std::move(std::unique_ptr<KeyDropDownControl>(new KeyDropDownControl(true, ignoreWarning))));
parent.Children().Append(keyDropDownControlObjects[keyDropDownControlObjects.size() - 1]->GetComboBox());
keyDropDownControlObjects[keyDropDownControlObjects.size() - 1]->SetSelectionHandler(table, shortcutControl, parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, isSingleKeyWindow);
parent.UpdateLayout();
@ -342,7 +355,16 @@ void KeyDropDownControl::AddShortcutToControl(Shortcut shortcut, Grid table, Sta
std::vector<DWORD> keyCodeList = keyboardManagerState.keyboardMap.GetKeyCodeList(true);
if (shortcutKeyCodes.size() != 0)
{
KeyDropDownControl::AddDropDown(table, controlLayout, parent, colIndex, remapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, isSingleKeyWindow);
bool ignoreWarning = false;
// If more than one key is to be added, ignore a shortcut to key warning on partially entering the remapping
if (shortcutKeyCodes.size() > 1)
{
ignoreWarning = true;
}
KeyDropDownControl::AddDropDown(table, controlLayout, parent, colIndex, remapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, isSingleKeyWindow, ignoreWarning);
for (int i = 0; i < shortcutKeyCodes.size(); i++)
{
// New drop down gets added automatically when the SelectedIndex is set

View File

@ -38,6 +38,8 @@ private:
winrt::Windows::Foundation::IInspectable warningMessage;
// Stores the flyout attached to the current drop down
winrt::Windows::Foundation::IInspectable warningFlyout;
// Stores whether a key to shortcut warning has to be ignored
bool ignoreKeyToShortcutWarning;
// Function to set properties apart from the SelectionChanged event handler
void SetDefaultProperties(bool isShortcut);
@ -53,7 +55,8 @@ public:
static KeyboardManagerState* keyboardManagerState;
// Constructor - the last default parameter should be passed as false only if it originates from Type shortcut or when an old shortcut is reloaded
KeyDropDownControl(bool isShortcut)
KeyDropDownControl(bool isShortcut, bool fromAddShortcutToControl = false) :
ignoreKeyToShortcutWarning(fromAddShortcutToControl)
{
SetDefaultProperties(isShortcut);
}
@ -74,7 +77,7 @@ public:
ComboBox GetComboBox();
// Function to add a drop down to the shortcut stack panel
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);
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
static std::vector<int32_t> GetSelectedIndicesFromStackPanel(StackPanel parent);