mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
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
This commit is contained in:
@@ -157,6 +157,8 @@ namespace KeyboardManagerHelper
|
||||
return L"Shortcut must contain an action key";
|
||||
case ErrorType::ShortcutNotMoreThanOneActionKey:
|
||||
return L"Shortcut cannot have more than one action key";
|
||||
case ErrorType::ShortcutMaxShortcutSizeOneActionKey:
|
||||
return L"Shortcuts can only have up to 2 modifier keys";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,8 @@ namespace KeyboardManagerHelper
|
||||
ShortcutCannotHaveRepeatedModifier,
|
||||
ShortcutAtleast2Keys,
|
||||
ShortcutOneActionKey,
|
||||
ShortcutNotMoreThanOneActionKey
|
||||
ShortcutNotMoreThanOneActionKey,
|
||||
ShortcutMaxShortcutSizeOneActionKey
|
||||
};
|
||||
|
||||
// Enum type to store possible decision for input in the low level hook
|
||||
|
||||
@@ -50,23 +50,21 @@ namespace KeyboardManagerConstants
|
||||
inline const double DefaultEditShortcutsWindowHeight = 0.55;
|
||||
|
||||
// Key Remap table constants
|
||||
inline const long RemapTableColCount = 5;
|
||||
inline const long RemapTableColCount = 4;
|
||||
inline const long RemapTableHeaderCount = 2;
|
||||
inline const long RemapTableOriginalColIndex = 0;
|
||||
inline const long RemapTableArrowColIndex = 1;
|
||||
inline const long RemapTableNewColIndex = 2;
|
||||
inline const long RemapTableRemoveColIndex = 3;
|
||||
inline const long RemapTableWarningColIndex = 4;
|
||||
inline const long RemapTableDropDownWidth = 110;
|
||||
|
||||
// Shortcut table constants
|
||||
inline const long ShortcutTableColCount = 5;
|
||||
inline const long ShortcutTableColCount = 4;
|
||||
inline const long ShortcutTableHeaderCount = 2;
|
||||
inline const long ShortcutTableOriginalColIndex = 0;
|
||||
inline const long ShortcutTableArrowColIndex = 1;
|
||||
inline const long ShortcutTableNewColIndex = 2;
|
||||
inline const long ShortcutTableRemoveColIndex = 3;
|
||||
inline const long ShortcutTableWarningColIndex = 4;
|
||||
inline const long ShortcutTableDropDownWidth = 110;
|
||||
inline const long ShortcutTableDropDownSpacing = 10;
|
||||
|
||||
|
||||
@@ -131,15 +131,12 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan
|
||||
newColumn.MaxWidth(KeyboardManagerConstants::RemapTableDropDownWidth);
|
||||
ColumnDefinition removeColumn;
|
||||
removeColumn.MinWidth(KeyboardManagerConstants::TableRemoveColWidth);
|
||||
ColumnDefinition warnColumn;
|
||||
warnColumn.MinWidth(KeyboardManagerConstants::TableWarningColWidth);
|
||||
keyRemapTable.Margin({ 10, 10, 10, 20 });
|
||||
keyRemapTable.HorizontalAlignment(HorizontalAlignment::Stretch);
|
||||
keyRemapTable.ColumnDefinitions().Append(originalColumn);
|
||||
keyRemapTable.ColumnDefinitions().Append(arrowColumn);
|
||||
keyRemapTable.ColumnDefinitions().Append(newColumn);
|
||||
keyRemapTable.ColumnDefinitions().Append(removeColumn);
|
||||
keyRemapTable.ColumnDefinitions().Append(warnColumn);
|
||||
keyRemapTable.RowDefinitions().Append(RowDefinition());
|
||||
|
||||
// First header textblock in the header row of the keys remap table
|
||||
@@ -292,14 +289,6 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan
|
||||
else
|
||||
{
|
||||
isSuccess = KeyboardManagerHelper::ErrorType::RemapUnsuccessful;
|
||||
// Show tooltip warning on the problematic row
|
||||
uint32_t warningIndex;
|
||||
// headers at start, colcount in each row, and last element of each row
|
||||
warningIndex = KeyboardManagerConstants::RemapTableHeaderCount + ((i + 1) * KeyboardManagerConstants::RemapTableColCount) - 1;
|
||||
FontIcon warning = keyRemapTable.Children().GetAt(warningIndex).as<FontIcon>();
|
||||
ToolTip t = ToolTipService::GetToolTip(warning).as<ToolTip>();
|
||||
t.Content(box_value(KeyboardManagerHelper::GetErrorMessage(KeyboardManagerHelper::ErrorType::MissingKey)));
|
||||
warning.Visibility(Visibility::Visible);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -133,15 +133,12 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
|
||||
newColumn.MaxWidth(3 * KeyboardManagerConstants::ShortcutTableDropDownWidth + 2 * KeyboardManagerConstants::ShortcutTableDropDownSpacing);
|
||||
ColumnDefinition removeColumn;
|
||||
removeColumn.MinWidth(KeyboardManagerConstants::TableRemoveColWidth);
|
||||
ColumnDefinition warnColumn;
|
||||
warnColumn.MinWidth(KeyboardManagerConstants::TableWarningColWidth);
|
||||
shortcutTable.Margin({ 10, 10, 10, 20 });
|
||||
shortcutTable.HorizontalAlignment(HorizontalAlignment::Stretch);
|
||||
shortcutTable.ColumnDefinitions().Append(originalColumn);
|
||||
shortcutTable.ColumnDefinitions().Append(arrowColumn);
|
||||
shortcutTable.ColumnDefinitions().Append(newColumn);
|
||||
shortcutTable.ColumnDefinitions().Append(removeColumn);
|
||||
shortcutTable.ColumnDefinitions().Append(warnColumn);
|
||||
shortcutTable.RowDefinitions().Append(RowDefinition());
|
||||
|
||||
// First header textblock in the header row of the shortcut table
|
||||
@@ -223,14 +220,6 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
|
||||
else
|
||||
{
|
||||
isSuccess = KeyboardManagerHelper::ErrorType::RemapUnsuccessful;
|
||||
// Show tooltip warning on the problematic row
|
||||
uint32_t warningIndex;
|
||||
// 2 at start, 4 in each row, and last element of each row
|
||||
warningIndex = KeyboardManagerConstants::ShortcutTableHeaderCount + ((i + 1) * KeyboardManagerConstants::ShortcutTableColCount) - 1;
|
||||
FontIcon warning = shortcutTable.Children().GetAt(warningIndex).as<FontIcon>();
|
||||
ToolTip t = ToolTipService::GetToolTip(warning).as<ToolTip>();
|
||||
t.Content(box_value(KeyboardManagerHelper::GetErrorMessage(KeyboardManagerHelper::ErrorType::MissingKey)));
|
||||
warning.Visibility(Visibility::Visible);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,10 @@ void KeyDropDownControl::SetDefaultProperties(bool isShortcut)
|
||||
ComboBox currentDropDown = sender.as<ComboBox>();
|
||||
CheckAndUpdateKeyboardLayout(currentDropDown, isShortcut);
|
||||
});
|
||||
|
||||
// Attach flyout to the drop down
|
||||
warningFlyout.Content(warningMessage);
|
||||
dropDown.ContextFlyout().SetAttachedFlyout((FrameworkElement)dropDown, warningFlyout);
|
||||
}
|
||||
|
||||
// Function to check if the layout has changed and accordingly update the drop down list
|
||||
@@ -47,7 +51,7 @@ void KeyDropDownControl::CheckAndUpdateKeyboardLayout(ComboBox currentDropDown,
|
||||
void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel& singleKeyControl, int colIndex, std::vector<std::vector<DWORD>>& singleKeyRemapBuffer)
|
||||
{
|
||||
// drop down selection handler
|
||||
dropDown.SelectionChanged([&, table, singleKeyControl, colIndex](winrt::Windows::Foundation::IInspectable const& sender, SelectionChangedEventArgs const& args) {
|
||||
auto onSelectionChange = [&, table, singleKeyControl, colIndex](winrt::Windows::Foundation::IInspectable const& sender) {
|
||||
ComboBox currentDropDown = sender.as<ComboBox>();
|
||||
int selectedKeyIndex = currentDropDown.SelectedIndex();
|
||||
// Get row index of the single key control
|
||||
@@ -103,16 +107,20 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel& singleKeyC
|
||||
{
|
||||
SetDropDownError(currentDropDown, KeyboardManagerHelper::GetErrorMessage(errorType));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// If either of the keys are invalid and the tooltip content has been modified after initialization, display the warning
|
||||
if ((singleKeyRemapBuffer[rowIndex][0] == NULL || singleKeyRemapBuffer[rowIndex][1] == NULL) && toolTip.Content().as<winrt::Windows::Foundation::IPropertyValue>().GetString() != KeyboardManagerConstants::ToolTipInitialContent)
|
||||
{
|
||||
warning.Visibility(Visibility::Visible);
|
||||
}
|
||||
else
|
||||
{
|
||||
warning.Visibility(Visibility::Collapsed);
|
||||
}
|
||||
// Rather than on every selection change (which gets triggered on searching as well) we set the handler only when the drop down is closed
|
||||
dropDown.DropDownClosed([onSelectionChange](winrt::Windows::Foundation::IInspectable const& sender, auto const& args) {
|
||||
onSelectionChange(sender);
|
||||
});
|
||||
|
||||
// We check if the selection changed was triggered while the drop down was closed. This is required to handle Type key, initial loading of remaps and if the user just types in the combo box without opening it
|
||||
dropDown.SelectionChanged([onSelectionChange](winrt::Windows::Foundation::IInspectable const& sender, SelectionChangedEventArgs const& args) {
|
||||
ComboBox currentDropDown = sender.as<ComboBox>();
|
||||
if (!currentDropDown.IsDropDownOpen())
|
||||
{
|
||||
onSelectionChange(sender);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -120,8 +128,7 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel& singleKeyC
|
||||
// Function to set selection handler for shortcut drop down. Needs to be called after the constructor since the shortcutControl StackPanel is null if called in the constructor
|
||||
void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel& shortcutControl, StackPanel parent, int colIndex, std::vector<std::vector<Shortcut>>& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects)
|
||||
{
|
||||
// drop down selection handler
|
||||
dropDown.SelectionChanged([&, table, shortcutControl, colIndex, parent](winrt::Windows::Foundation::IInspectable const& sender, SelectionChangedEventArgs const&) {
|
||||
auto onSelectionChange = [&, table, shortcutControl, colIndex, parent](winrt::Windows::Foundation::IInspectable const& sender) {
|
||||
ComboBox currentDropDown = sender.as<ComboBox>();
|
||||
int selectedKeyIndex = currentDropDown.SelectedIndex();
|
||||
uint32_t dropDownIndex = -1;
|
||||
@@ -130,6 +137,7 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel& shortcutCo
|
||||
uint32_t controlIndex;
|
||||
bool controlIindexFound = table.Children().IndexOf(shortcutControl, controlIndex);
|
||||
KeyboardManagerHelper::ErrorType errorType = KeyboardManagerHelper::ErrorType::NoError;
|
||||
bool IsDeleteDropDownRequired = false;
|
||||
|
||||
if (controlIindexFound)
|
||||
{
|
||||
@@ -157,14 +165,14 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel& shortcutCo
|
||||
// If not, add a new drop down
|
||||
else
|
||||
{
|
||||
AddDropDown(table, shortcutControl, parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects, warning, toolTip);
|
||||
AddDropDown(table, shortcutControl, parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects);
|
||||
}
|
||||
}
|
||||
// If last drop down and a modifier is selected but there are already 5 drop downs: warn the user
|
||||
// If last drop down and a modifier is selected but there are already max drop downs: warn the user
|
||||
else if (KeyboardManagerHelper::IsModifierKey(keyCodeList[selectedKeyIndex]) && parent.Children().Size() >= KeyboardManagerConstants::MaxShortcutSize)
|
||||
{
|
||||
// warn and reset the drop down
|
||||
errorType = KeyboardManagerHelper::ErrorType::ShortcutOneActionKey;
|
||||
errorType = KeyboardManagerHelper::ErrorType::ShortcutMaxShortcutSizeOneActionKey;
|
||||
}
|
||||
// If None is selected but it's the last index: warn
|
||||
else if (keyCodeList[selectedKeyIndex] == 0)
|
||||
@@ -190,11 +198,9 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel& shortcutCo
|
||||
// If None is selected and there are more than 2 drop downs
|
||||
else if (keyCodeList[selectedKeyIndex] == 0 && parent.Children().Size() > KeyboardManagerConstants::MinShortcutSize)
|
||||
{
|
||||
// delete drop down
|
||||
parent.Children().RemoveAt(dropDownIndex);
|
||||
// delete drop down control object from the vector so that it can be destructed
|
||||
keyDropDownControlObjects.erase(keyDropDownControlObjects.begin() + dropDownIndex);
|
||||
parent.UpdateLayout();
|
||||
// set delete drop down flag
|
||||
IsDeleteDropDownRequired = true;
|
||||
// do not delete the drop down now since there may be some other error which would cause the drop down to be invalid after removal
|
||||
}
|
||||
else if (keyCodeList[selectedKeyIndex] == 0 && parent.Children().Size() <= KeyboardManagerConstants::MinShortcutSize)
|
||||
{
|
||||
@@ -279,18 +285,17 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel& shortcutCo
|
||||
{
|
||||
SetDropDownError(currentDropDown, KeyboardManagerHelper::GetErrorMessage(errorType));
|
||||
}
|
||||
|
||||
// Handle None case if there are no other errors
|
||||
else if (IsDeleteDropDownRequired)
|
||||
{
|
||||
parent.Children().RemoveAt(dropDownIndex);
|
||||
// delete drop down control object from the vector so that it can be destructed
|
||||
keyDropDownControlObjects.erase(keyDropDownControlObjects.begin() + dropDownIndex);
|
||||
parent.UpdateLayout();
|
||||
}
|
||||
// Reset the buffer based on the new selected drop down items
|
||||
shortcutRemapBuffer[rowIndex][colIndex].SetKeyCodes(GetKeysFromStackPanel(parent));
|
||||
|
||||
// If either of the shortcuts are invalid and the tooltip content has been modified after initialization, display the warning
|
||||
if ((!shortcutRemapBuffer[rowIndex][0].IsValidShortcut() || !shortcutRemapBuffer[rowIndex][1].IsValidShortcut()) && toolTip.Content().as<winrt::Windows::Foundation::IPropertyValue>().GetString() != KeyboardManagerConstants::ToolTipInitialContent)
|
||||
{
|
||||
warning.Visibility(Visibility::Visible);
|
||||
}
|
||||
else
|
||||
{
|
||||
warning.Visibility(Visibility::Collapsed);
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
@@ -304,6 +309,20 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel& shortcutCo
|
||||
keyDropDownControlObjects.erase(keyDropDownControlObjects.begin() + i);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Rather than on every selection change (which gets triggered on searching as well) we set the handler only when the drop down is closed
|
||||
dropDown.DropDownClosed([onSelectionChange](winrt::Windows::Foundation::IInspectable const& sender, auto const& args) {
|
||||
onSelectionChange(sender);
|
||||
});
|
||||
|
||||
// We check if the selection changed was triggered while the drop down was closed. This is required to handle Type key, initial loading of remaps and if the user just types in the combo box without opening it
|
||||
dropDown.SelectionChanged([onSelectionChange](winrt::Windows::Foundation::IInspectable const& sender, SelectionChangedEventArgs const& args) {
|
||||
ComboBox currentDropDown = sender.as<ComboBox>();
|
||||
if (!currentDropDown.IsDropDownOpen())
|
||||
{
|
||||
onSelectionChange(sender);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -320,9 +339,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, std::vector<std::vector<Shortcut>>& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, FontIcon warning, ToolTip toolTip)
|
||||
void KeyDropDownControl::AddDropDown(Grid table, StackPanel shortcutControl, StackPanel parent, const int colIndex, std::vector<std::vector<Shortcut>>& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects)
|
||||
{
|
||||
keyDropDownControlObjects.push_back(std::move(std::unique_ptr<KeyDropDownControl>(new KeyDropDownControl(true, warning, toolTip))));
|
||||
keyDropDownControlObjects.push_back(std::move(std::unique_ptr<KeyDropDownControl>(new KeyDropDownControl(true))));
|
||||
parent.Children().Append(keyDropDownControlObjects[keyDropDownControlObjects.size() - 1]->GetComboBox());
|
||||
keyDropDownControlObjects[keyDropDownControlObjects.size() - 1]->SetSelectionHandler(table, shortcutControl, parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects);
|
||||
parent.UpdateLayout();
|
||||
@@ -377,5 +396,6 @@ bool KeyDropDownControl::CheckRepeatedModifier(StackPanel parent, uint32_t dropD
|
||||
void KeyDropDownControl::SetDropDownError(ComboBox currentDropDown, hstring message)
|
||||
{
|
||||
currentDropDown.SelectedIndex(-1);
|
||||
toolTip.Content(box_value(message));
|
||||
warningMessage.Text(message);
|
||||
currentDropDown.ContextFlyout().ShowAttachedFlyout((FrameworkElement)dropDown);
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@ private:
|
||||
HKL previousLayout = 0;
|
||||
// Stores the key code list
|
||||
std::vector<DWORD> keyCodeList;
|
||||
// Stores the warning control
|
||||
FontIcon warning;
|
||||
// Stores the tooltip for the warning control
|
||||
ToolTip toolTip;
|
||||
// Stores the flyout warning message
|
||||
TextBlock warningMessage;
|
||||
// Stores the flyout attached to the current drop down
|
||||
Flyout warningFlyout;
|
||||
|
||||
// Function to set properties apart from the SelectionChanged event handler
|
||||
void SetDefaultProperties(bool isShortcut);
|
||||
@@ -26,9 +26,8 @@ public:
|
||||
// Pointer to the keyboard manager state
|
||||
static KeyboardManagerState* keyboardManagerState;
|
||||
|
||||
// Constructor
|
||||
KeyDropDownControl(bool isShortcut, FontIcon warning, ToolTip toolTip) :
|
||||
warning(warning), toolTip(toolTip)
|
||||
// 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)
|
||||
{
|
||||
SetDefaultProperties(isShortcut);
|
||||
}
|
||||
@@ -46,7 +45,7 @@ public:
|
||||
ComboBox GetComboBox();
|
||||
|
||||
// Function to add a drop down to the shortcut stack panel
|
||||
static void AddDropDown(Grid table, StackPanel shortcutControl, StackPanel parent, const int colIndex, std::vector<std::vector<Shortcut>>& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, FontIcon warning, ToolTip toolTip);
|
||||
static void AddDropDown(Grid table, StackPanel shortcutControl, StackPanel parent, const int colIndex, std::vector<std::vector<Shortcut>>& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects);
|
||||
|
||||
// Function to get the list of key codes from the shortcut combo box stack panel
|
||||
std::vector<DWORD> GetKeysFromStackPanel(StackPanel parent);
|
||||
|
||||
@@ -11,16 +11,10 @@ std::vector<std::vector<Shortcut>> ShortcutControl::shortcutRemapBuffer;
|
||||
// Function to add a new row to the shortcut table. If the originalKeys and newKeys args are provided, then the displayed shortcuts are set to those values.
|
||||
void ShortcutControl::AddNewShortcutControlRow(Grid& parent, std::vector<std::vector<std::unique_ptr<ShortcutControl>>>& keyboardRemapControlObjects, Shortcut originalKeys, Shortcut newKeys)
|
||||
{
|
||||
// Warning icon for the row
|
||||
ToolTip warningMessage;
|
||||
FontIcon warningIcon;
|
||||
warningIcon.Visibility(Visibility::Collapsed);
|
||||
warningMessage.Content(box_value(KeyboardManagerConstants::ToolTipInitialContent));
|
||||
|
||||
// Create new ShortcutControl objects dynamically so that we does not get destructed
|
||||
std::vector<std::unique_ptr<ShortcutControl>> newrow;
|
||||
newrow.push_back(std::move(std::unique_ptr<ShortcutControl>(new ShortcutControl(parent, 0, warningIcon, warningMessage))));
|
||||
newrow.push_back(std::move(std::unique_ptr<ShortcutControl>(new ShortcutControl(parent, 1, warningIcon, warningMessage))));
|
||||
newrow.push_back(std::move(std::unique_ptr<ShortcutControl>(new ShortcutControl(parent, 0))));
|
||||
newrow.push_back(std::move(std::unique_ptr<ShortcutControl>(new ShortcutControl(parent, 1))));
|
||||
keyboardRemapControlObjects.push_back(std::move(newrow));
|
||||
|
||||
// Add to grid
|
||||
@@ -84,22 +78,14 @@ void ShortcutControl::AddNewShortcutControlRow(Grid& parent, std::vector<std::ve
|
||||
parent.SetColumn(deleteShortcut, KeyboardManagerConstants::ShortcutTableRemoveColIndex);
|
||||
parent.SetRow(deleteShortcut, parent.RowDefinitions().Size() - 1);
|
||||
parent.Children().Append(deleteShortcut);
|
||||
|
||||
warningIcon.FontFamily(Xaml::Media::FontFamily(L"Segoe MDL2 Assets"));
|
||||
warningIcon.Glyph(L"\xE783");
|
||||
warningIcon.HorizontalAlignment(HorizontalAlignment::Center);
|
||||
ToolTipService::SetToolTip(warningIcon, warningMessage);
|
||||
parent.SetColumn(warningIcon, KeyboardManagerConstants::ShortcutTableWarningColIndex);
|
||||
parent.SetRow(warningIcon, parent.RowDefinitions().Size() - 1);
|
||||
parent.Children().Append(warningIcon);
|
||||
parent.UpdateLayout();
|
||||
|
||||
// Set the shortcut text if the two vectors are not empty (i.e. default args)
|
||||
if (originalKeys.IsValidShortcut() && newKeys.IsValidShortcut())
|
||||
{
|
||||
shortcutRemapBuffer.push_back(std::vector<Shortcut>{ Shortcut(), Shortcut() });
|
||||
keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][0]->AddShortcutToControl(originalKeys, parent, keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][0]->shortcutDropDownStackPanel, *keyboardManagerState, 0, warningIcon, warningMessage);
|
||||
keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->AddShortcutToControl(newKeys, parent, keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->shortcutDropDownStackPanel, *keyboardManagerState, 1, warningIcon, warningMessage);
|
||||
keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][0]->AddShortcutToControl(originalKeys, parent, keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][0]->shortcutDropDownStackPanel, *keyboardManagerState, 0);
|
||||
keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->AddShortcutToControl(newKeys, parent, keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->shortcutDropDownStackPanel, *keyboardManagerState, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -109,7 +95,7 @@ void ShortcutControl::AddNewShortcutControlRow(Grid& parent, std::vector<std::ve
|
||||
}
|
||||
|
||||
// Function to add a shortcut to the shortcut control as combo boxes
|
||||
void ShortcutControl::AddShortcutToControl(Shortcut& shortcut, Grid table, StackPanel parent, KeyboardManagerState& keyboardManagerState, const int colIndex, FontIcon warning, ToolTip toolTip)
|
||||
void ShortcutControl::AddShortcutToControl(Shortcut& shortcut, Grid table, StackPanel parent, KeyboardManagerState& keyboardManagerState, const int colIndex)
|
||||
{
|
||||
// Delete the existing drop down menus
|
||||
parent.Children().Clear();
|
||||
@@ -120,7 +106,7 @@ void ShortcutControl::AddShortcutToControl(Shortcut& shortcut, Grid table, Stack
|
||||
std::vector<DWORD> keyCodeList = keyboardManagerState.keyboardMap.GetKeyCodeList(true);
|
||||
if (shortcutKeyCodes.size() != 0)
|
||||
{
|
||||
KeyDropDownControl::AddDropDown(table, shortcutControlLayout, parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects, warning, toolTip);
|
||||
KeyDropDownControl::AddDropDown(table, shortcutControlLayout, parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects);
|
||||
for (int i = 0; i < shortcutKeyCodes.size(); i++)
|
||||
{
|
||||
// New drop down gets added automatically when the SelectedIndex is set
|
||||
@@ -145,7 +131,7 @@ StackPanel ShortcutControl::getShortcutControl()
|
||||
}
|
||||
|
||||
// Function to create the detect shortcut UI window
|
||||
void ShortcutControl::createDetectShortcutWindow(winrt::Windows::Foundation::IInspectable const& sender, XamlRoot xamlRoot, std::vector<std::vector<Shortcut>>& shortcutRemapBuffer, KeyboardManagerState& keyboardManagerState, const int colIndex, Grid table, FontIcon warning, ToolTip toolTip)
|
||||
void ShortcutControl::createDetectShortcutWindow(winrt::Windows::Foundation::IInspectable const& sender, XamlRoot xamlRoot, std::vector<std::vector<Shortcut>>& shortcutRemapBuffer, KeyboardManagerState& keyboardManagerState, const int colIndex, Grid table)
|
||||
{
|
||||
// ContentDialog for detecting shortcuts. This is the parent UI element.
|
||||
ContentDialog detectShortcutBox;
|
||||
@@ -178,16 +164,14 @@ void ShortcutControl::createDetectShortcutWindow(winrt::Windows::Foundation::IIn
|
||||
&shortcutRemapBuffer,
|
||||
unregisterKeys,
|
||||
colIndex,
|
||||
table,
|
||||
warning,
|
||||
toolTip] {
|
||||
table] {
|
||||
// Save the detected shortcut in the linked text block
|
||||
Shortcut detectedShortcutKeys = keyboardManagerState.GetDetectedShortcut();
|
||||
|
||||
if (!detectedShortcutKeys.IsEmpty())
|
||||
{
|
||||
// The shortcut buffer gets set in this function
|
||||
AddShortcutToControl(detectedShortcutKeys, table, linkedShortcutStackPanel, keyboardManagerState, colIndex, warning, toolTip);
|
||||
AddShortcutToControl(detectedShortcutKeys, table, linkedShortcutStackPanel, keyboardManagerState, colIndex);
|
||||
}
|
||||
|
||||
// Reset the keyboard manager UI state
|
||||
@@ -313,4 +297,4 @@ void ShortcutControl::createDetectShortcutWindow(winrt::Windows::Foundation::IIn
|
||||
|
||||
// Show the dialog
|
||||
detectShortcutBox.ShowAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,17 +29,17 @@ public:
|
||||
// Vector to store dynamically allocated KeyDropDownControl objects to avoid early destruction
|
||||
std::vector<std::unique_ptr<KeyDropDownControl>> keyDropDownControlObjects;
|
||||
|
||||
ShortcutControl(Grid table, const int colIndex, FontIcon warning, ToolTip toolTip)
|
||||
ShortcutControl(Grid table, const int colIndex)
|
||||
{
|
||||
shortcutDropDownStackPanel.Spacing(10);
|
||||
shortcutDropDownStackPanel.Orientation(Windows::UI::Xaml::Controls::Orientation::Horizontal);
|
||||
|
||||
typeShortcut.Content(winrt::box_value(L"Type Shortcut"));
|
||||
typeShortcut.Width(KeyboardManagerConstants::ShortcutTableDropDownWidth);
|
||||
typeShortcut.Click([&, table, colIndex, warning, toolTip](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) {
|
||||
typeShortcut.Click([&, table, colIndex](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) {
|
||||
keyboardManagerState->SetUIState(KeyboardManagerUIState::DetectShortcutWindowActivated, EditShortcutsWindowHandle);
|
||||
// Using the XamlRoot of the typeShortcut to get the root of the XAML host
|
||||
createDetectShortcutWindow(sender, sender.as<Button>().XamlRoot(), shortcutRemapBuffer, *keyboardManagerState, colIndex, table, warning, toolTip);
|
||||
createDetectShortcutWindow(sender, sender.as<Button>().XamlRoot(), shortcutRemapBuffer, *keyboardManagerState, colIndex, table);
|
||||
});
|
||||
|
||||
shortcutControlLayout.Margin({ 0, 0, 0, 10 });
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
|
||||
shortcutControlLayout.Children().Append(typeShortcut);
|
||||
shortcutControlLayout.Children().Append(shortcutDropDownStackPanel);
|
||||
KeyDropDownControl::AddDropDown(table, shortcutControlLayout, shortcutDropDownStackPanel, colIndex, shortcutRemapBuffer, keyDropDownControlObjects, warning, toolTip);
|
||||
KeyDropDownControl::AddDropDown(table, shortcutControlLayout, shortcutDropDownStackPanel, colIndex, shortcutRemapBuffer, keyDropDownControlObjects);
|
||||
shortcutControlLayout.UpdateLayout();
|
||||
}
|
||||
|
||||
@@ -55,11 +55,11 @@ public:
|
||||
static void AddNewShortcutControlRow(Grid& parent, std::vector<std::vector<std::unique_ptr<ShortcutControl>>>& keyboardRemapControlObjects, Shortcut originalKeys = Shortcut(), Shortcut newKeys = Shortcut());
|
||||
|
||||
// Function to add a shortcut to the shortcut control as combo boxes
|
||||
void AddShortcutToControl(Shortcut& shortcut, Grid table, StackPanel parent, KeyboardManagerState& keyboardManagerState, const int colIndex, FontIcon warning, ToolTip toolTip);
|
||||
void AddShortcutToControl(Shortcut& shortcut, Grid table, StackPanel parent, KeyboardManagerState& keyboardManagerState, const int colIndex);
|
||||
|
||||
// Function to return the stack panel element of the ShortcutControl. This is the externally visible UI element which can be used to add it to other layouts
|
||||
StackPanel getShortcutControl();
|
||||
|
||||
// Function to create the detect shortcut UI window
|
||||
void createDetectShortcutWindow(winrt::Windows::Foundation::IInspectable const& sender, XamlRoot xamlRoot, std::vector<std::vector<Shortcut>>& shortcutRemapBuffer, KeyboardManagerState& keyboardManagerState, const int colIndex, Grid table, FontIcon warning, ToolTip toolTip);
|
||||
void createDetectShortcutWindow(winrt::Windows::Foundation::IInspectable const& sender, XamlRoot xamlRoot, std::vector<std::vector<Shortcut>>& shortcutRemapBuffer, KeyboardManagerState& keyboardManagerState, const int colIndex, Grid table);
|
||||
};
|
||||
|
||||
@@ -11,16 +11,10 @@ std::vector<std::vector<DWORD>> SingleKeyRemapControl::singleKeyRemapBuffer;
|
||||
// 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.
|
||||
void SingleKeyRemapControl::AddNewControlKeyRemapRow(Grid& parent, std::vector<std::vector<std::unique_ptr<SingleKeyRemapControl>>>& keyboardRemapControlObjects, const DWORD originalKey, const DWORD newKey)
|
||||
{
|
||||
// Warning icon for the row
|
||||
ToolTip warningMessage;
|
||||
FontIcon warningIcon;
|
||||
warningIcon.Visibility(Visibility::Collapsed);
|
||||
warningMessage.Content(box_value(KeyboardManagerConstants::ToolTipInitialContent));
|
||||
|
||||
// Create new SingleKeyRemapControl objects dynamically so that we does not get destructed
|
||||
std::vector<std::unique_ptr<SingleKeyRemapControl>> newrow;
|
||||
newrow.push_back(std::move(std::unique_ptr<SingleKeyRemapControl>(new SingleKeyRemapControl(parent, 0, warningIcon, warningMessage))));
|
||||
newrow.push_back(std::move(std::unique_ptr<SingleKeyRemapControl>(new SingleKeyRemapControl(parent, 1, warningIcon, warningMessage))));
|
||||
newrow.push_back(std::move(std::unique_ptr<SingleKeyRemapControl>(new SingleKeyRemapControl(parent, 0))));
|
||||
newrow.push_back(std::move(std::unique_ptr<SingleKeyRemapControl>(new SingleKeyRemapControl(parent, 1))));
|
||||
keyboardRemapControlObjects.push_back(std::move(newrow));
|
||||
|
||||
// Add to grid
|
||||
@@ -106,14 +100,6 @@ void SingleKeyRemapControl::AddNewControlKeyRemapRow(Grid& parent, std::vector<s
|
||||
parent.SetColumn(deleteRemapKeys, KeyboardManagerConstants::RemapTableRemoveColIndex);
|
||||
parent.SetRow(deleteRemapKeys, parent.RowDefinitions().Size() - 1);
|
||||
parent.Children().Append(deleteRemapKeys);
|
||||
|
||||
warningIcon.FontFamily(Xaml::Media::FontFamily(L"Segoe MDL2 Assets"));
|
||||
warningIcon.Glyph(L"\xE783");
|
||||
warningIcon.HorizontalAlignment(HorizontalAlignment::Center);
|
||||
ToolTipService::SetToolTip(warningIcon, warningMessage);
|
||||
parent.SetColumn(warningIcon, KeyboardManagerConstants::RemapTableWarningColIndex);
|
||||
parent.SetRow(warningIcon, parent.RowDefinitions().Size() - 1);
|
||||
parent.Children().Append(warningIcon);
|
||||
parent.UpdateLayout();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ public:
|
||||
// Stores the current list of remappings
|
||||
static std::vector<std::vector<DWORD>> singleKeyRemapBuffer;
|
||||
|
||||
SingleKeyRemapControl(Grid table, const int colIndex, FontIcon warning, ToolTip toolTip) :
|
||||
singleKeyRemapDropDown(false, warning, toolTip)
|
||||
SingleKeyRemapControl(Grid table, const int colIndex) :
|
||||
singleKeyRemapDropDown(false)
|
||||
{
|
||||
typeKey.Content(winrt::box_value(L"Type Key"));
|
||||
typeKey.Width(KeyboardManagerConstants::RemapTableDropDownWidth);
|
||||
|
||||
Reference in New Issue
Block a user