PowerToys/src/modules/keyboardmanager/ui/Dialog.h
Tomas Agustin Raies 8c04421387
[Keyboard Manager] Confirmation Dialog for orphaned keys and partial remappings. (#2811)
* WIP Confirmation dialog for orphaned keys

* Confirmation Dialog for orphaned keys

* White OK button, Anyways capitalizef

* Change Apply to Ok for shortcuts

* Validate that mappings can be made before changing keyboardManagerState

* Set fixed MinWidth for OK button

* Fix typo

* Partial remappings confirmation dialog

Both for Shortcuts and SingleKey

* Remove warning icon callback in OnClickAccept

* Add text wrapping for OrphanKeys dialog
2020-05-11 12:45:55 -07:00

42 lines
1.3 KiB
C++

#pragma once
#include <vector>
#include <functional>
#include <keyboardmanager/common/Helpers.h>
#include <set>
#include <winrt/Windows.UI.Xaml.h>
using namespace winrt::Windows::Foundation;
namespace Dialog
{
template<typename T>
KeyboardManagerHelper::ErrorType CheckIfRemappingsAreValid(
const std::vector<std::vector<T>>& remappings,
std::function<bool(T)> isValid)
{
KeyboardManagerHelper::ErrorType isSuccess = KeyboardManagerHelper::ErrorType::NoError;
std::set<T> ogKeys;
for (int i = 0; i < remappings.size(); i++)
{
T ogKey = remappings[i][0];
T newKey = remappings[i][1];
if (isValid(ogKey) && isValid(newKey) && ogKeys.find(ogKey) == ogKeys.end())
{
ogKeys.insert(ogKey);
}
else if (isValid(ogKey) && isValid(newKey) && ogKeys.find(ogKey) != ogKeys.end())
{
isSuccess = KeyboardManagerHelper::ErrorType::RemapUnsuccessful;
}
else
{
isSuccess = KeyboardManagerHelper::ErrorType::RemapUnsuccessful;
}
}
return isSuccess;
}
IAsyncOperation<bool> PartialRemappingConfirmationDialog(winrt::Windows::UI::Xaml::XamlRoot root);
};