PowerToys/src/modules/keyboardmanager/ui/SingleKeyRemapControl.h
Arjun Balgovind 592c55c524
Change warnings from icon to flyouts but it no longer interrupts searching (#2816)
* Fixed foreground issue and added arrow

* Tweaked Remap Keyboard UI

* Fix errors in warning handling and update UI layout

* Tweaked sizes and centered to screen

* Fixed flyouts appearing on search for Single key remaps

* Fixed flyouts appearing on search for Shortcut remaps

* Remove warning exclamation icon and tooltip

* Fixed a bug where setting None on a drop down which would create a shortcut with a conflict would cause a crash

* Remove IsTypeKey logic

* Changed warning text

* Resolve comments
2020-05-11 10:10:36 -07:00

55 lines
2.7 KiB
C++

#pragma once
#include <keyboardmanager/common/KeyboardManagerState.h>
#include "KeyDropDownControl.h"
class SingleKeyRemapControl
{
private:
// Drop down to display the selected remap key
KeyDropDownControl singleKeyRemapDropDown;
// Button to type the remap key
Button typeKey;
// StackPanel to parent the above controls
StackPanel singleKeyRemapControlLayout;
public:
// Handle to the current Edit Keyboard Window
static HWND EditKeyboardWindowHandle;
// Pointer to the keyboard manager state
static KeyboardManagerState* keyboardManagerState;
// Stores the current list of remappings
static std::vector<std::vector<DWORD>> singleKeyRemapBuffer;
SingleKeyRemapControl(Grid table, const int colIndex) :
singleKeyRemapDropDown(false)
{
typeKey.Content(winrt::box_value(L"Type Key"));
typeKey.Width(KeyboardManagerConstants::RemapTableDropDownWidth);
typeKey.Click([&](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) {
keyboardManagerState->SetUIState(KeyboardManagerUIState::DetectSingleKeyRemapWindowActivated, EditKeyboardWindowHandle);
// Using the XamlRoot of the typeKey to get the root of the XAML host
createDetectKeyWindow(sender, sender.as<Button>().XamlRoot(), singleKeyRemapBuffer, *keyboardManagerState);
});
singleKeyRemapControlLayout.Margin({ 0, 0, 0, 10 });
singleKeyRemapControlLayout.Spacing(10);
singleKeyRemapControlLayout.Children().Append(typeKey);
singleKeyRemapControlLayout.Children().Append(singleKeyRemapDropDown.GetComboBox());
// Set selection handler for the drop down
singleKeyRemapDropDown.SetSelectionHandler(table, singleKeyRemapControlLayout, colIndex, singleKeyRemapBuffer);
singleKeyRemapControlLayout.UpdateLayout();
}
// Function to add a new row to the remap keys table. If the originalKey and newKey args are provided, then the displayed remap keys are set to those values.
static void AddNewControlKeyRemapRow(Grid& parent, std::vector<std::vector<std::unique_ptr<SingleKeyRemapControl>>>& keyboardRemapControlObjects, const DWORD originalKey = NULL, const DWORD newKey = NULL);
// Function to return the stack panel element of the SingleKeyRemapControl. This is the externally visible UI element which can be used to add it to other layouts
StackPanel getSingleKeyRemapControl();
// Function to create the detect remap keys UI window
void createDetectKeyWindow(winrt::Windows::Foundation::IInspectable const& sender, XamlRoot xamlRoot, std::vector<std::vector<DWORD>>& singleKeyRemapBuffer, KeyboardManagerState& keyboardManagerState);
};