[Keyboard Manager] Add JSON support for App Specific shortcuts (#4840)

* Enable app specific shortcut remapping

* Fixed lowercase function call

* Add test file

* Moved GetForegroundProcess to II and added tests

* Fixed runtime error while testing due to heap allocation across dll boundary

* Renamed function

* Changed shortcutBuffer type

* Linked App specific UI to backend

* Added shortcut validation logic on TextBox LostFocus handler

* Moved Validate function and changed default text

* Changed to case insensitive warning check

* Changed to case insensitive warning check at OnClickAccept

* Fixed alignment and spacing issues

* Added app-specific JSON support in backend

* Updated landing page

* Make listview horizontally scrollable

* Added tests

* Consider all case variants of All Apps in textbox to be global shortcuts
This commit is contained in:
Arjun Balgovind
2020-07-10 17:07:28 -07:00
committed by GitHub
parent 653ae777d5
commit bb2049411b
13 changed files with 404 additions and 34 deletions

View File

@@ -254,6 +254,12 @@ std::pair<KeyboardManagerHelper::ErrorType, int> KeyDropDownControl::ValidateSho
std::wstring appName = targetApp.Text().c_str();
// Convert app name to lower case
std::transform(appName.begin(), appName.end(), appName.begin(), towlower);
std::wstring lowercaseDefAppName = KeyboardManagerConstants::DefaultAppName;
std::transform(lowercaseDefAppName.begin(), lowercaseDefAppName.end(), lowercaseDefAppName.begin(), towlower);
if (appName == lowercaseDefAppName)
{
appName = L"";
}
// Check if the value being set is the same as the other column
if (shortcutRemapBuffer[rowIndex].first[std::abs(int(colIndex) - 1)] == tempShortcut && shortcutRemapBuffer[rowIndex].first[std::abs(int(colIndex) - 1)].IsValidShortcut() && tempShortcut.IsValidShortcut())
@@ -323,7 +329,18 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel& shortcutCo
// Reset the buffer based on the new selected drop down items
shortcutRemapBuffer[validationResult.second].first[colIndex].SetKeyCodes(GetKeysFromStackPanel(parent));
shortcutRemapBuffer[validationResult.second].second = targetApp.Text().c_str();
std::wstring newText = targetApp.Text().c_str();
std::wstring lowercaseDefAppName = KeyboardManagerConstants::DefaultAppName;
std::transform(newText.begin(), newText.end(), newText.begin(), towlower);
std::transform(lowercaseDefAppName.begin(), lowercaseDefAppName.end(), lowercaseDefAppName.begin(), towlower);
if (newText == lowercaseDefAppName)
{
shortcutRemapBuffer[validationResult.second].second = L"";
}
else
{
shortcutRemapBuffer[validationResult.second].second = targetApp.Text().c_str();
}
}
// If the user searches for a key the selection handler gets invoked however if they click away it reverts back to the previous state. This can result in dangling references to added drop downs which were then reset.

View File

@@ -66,7 +66,18 @@ void ShortcutControl::AddNewShortcutControlRow(Grid& parent, std::vector<std::ve
// Reset the buffer based on the selected drop down items
shortcutRemapBuffer[rowIndex].first[0].SetKeyCodes(KeyDropDownControl::GetKeysFromStackPanel(keyboardRemapControlObjects[rowIndex][0]->shortcutDropDownStackPanel));
shortcutRemapBuffer[rowIndex].first[1].SetKeyCodes(KeyDropDownControl::GetKeysFromStackPanel(keyboardRemapControlObjects[rowIndex][1]->shortcutDropDownStackPanel));
shortcutRemapBuffer[rowIndex].second = targetAppTextBox.Text().c_str();
std::wstring newText = targetAppTextBox.Text().c_str();
std::wstring lowercaseDefAppName = KeyboardManagerConstants::DefaultAppName;
std::transform(newText.begin(), newText.end(), newText.begin(), towlower);
std::transform(lowercaseDefAppName.begin(), lowercaseDefAppName.end(), lowercaseDefAppName.begin(), towlower);
if (newText == lowercaseDefAppName)
{
shortcutRemapBuffer[rowIndex].second = L"";
}
else
{
shortcutRemapBuffer[rowIndex].second = targetAppTextBox.Text().c_str();
}
});
parent.SetColumn(targetAppTextBox, KeyboardManagerConstants::ShortcutTableTargetAppColIndex);