mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 02:06:36 +02:00
Improve warnings for KBM (dev/build-features) (#2386)
* Handled invalid input for single key remaps * Added some functions * Added better error message functions and finished warnings for edit keyboard * Updated dropdown order of keys * Added new warning template for shortcuts * Added show warning on Apply code * Removed old flyout code * Fixed issue where tooltips were replaced on Apply * Simplified == operator
This commit is contained in:
@@ -102,12 +102,16 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
|
||||
ColumnDefinition firstColumn;
|
||||
ColumnDefinition secondColumn;
|
||||
ColumnDefinition thirdColumn;
|
||||
thirdColumn.MaxWidth(100);
|
||||
ColumnDefinition fourthColumn;
|
||||
fourthColumn.MaxWidth(100);
|
||||
shortcutTable.Margin({ 10, 10, 10, 20 });
|
||||
shortcutTable.HorizontalAlignment(HorizontalAlignment::Stretch);
|
||||
shortcutTable.ColumnSpacing(10);
|
||||
shortcutTable.ColumnDefinitions().Append(firstColumn);
|
||||
shortcutTable.ColumnDefinitions().Append(secondColumn);
|
||||
shortcutTable.ColumnDefinitions().Append(thirdColumn);
|
||||
shortcutTable.ColumnDefinitions().Append(fourthColumn);
|
||||
shortcutTable.RowDefinitions().Append(RowDefinition());
|
||||
|
||||
// First header textblock in the header row of the shortcut table
|
||||
@@ -123,8 +127,8 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
|
||||
newShortcutHeader.Margin({ 0, 0, 0, 10 });
|
||||
|
||||
shortcutTable.SetColumn(originalShortcutHeader, 0);
|
||||
shortcutTable.SetRow(newShortcutHeader, 0);
|
||||
shortcutTable.SetColumn(originalShortcutHeader, 1);
|
||||
shortcutTable.SetRow(originalShortcutHeader, 0);
|
||||
shortcutTable.SetColumn(newShortcutHeader, 1);
|
||||
shortcutTable.SetRow(newShortcutHeader, 0);
|
||||
|
||||
shortcutTable.Children().Append(originalShortcutHeader);
|
||||
@@ -160,7 +164,7 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
|
||||
header.SetLeftOf(cancelButton, applyButton);
|
||||
applyButton.Flyout(applyFlyout);
|
||||
applyButton.Click([&](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) {
|
||||
bool isSuccess = true;
|
||||
KeyboardManagerHelper::ErrorType isSuccess = KeyboardManagerHelper::ErrorType::NoError;
|
||||
// Clear existing shortcuts
|
||||
keyboardManagerState.ClearOSLevelShortcuts();
|
||||
|
||||
@@ -175,30 +179,31 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
|
||||
bool result = keyboardManagerState.AddOSLevelShortcut(originalShortcut, newShortcut);
|
||||
if (!result)
|
||||
{
|
||||
isSuccess = false;
|
||||
isSuccess = KeyboardManagerHelper::ErrorType::RemapUnsuccessful;
|
||||
// Tooltip is already shown for this row
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
isSuccess = false;
|
||||
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 = 1 + (i + 1) * 4;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// Save the updated key remaps to file.
|
||||
auto saveResult = keyboardManagerState.SaveConfigToFile();
|
||||
|
||||
if (isSuccess && saveResult)
|
||||
bool saveResult = keyboardManagerState.SaveConfigToFile();
|
||||
if (!saveResult)
|
||||
{
|
||||
settingsMessage.Text(L"Remapping successful!");
|
||||
}
|
||||
else if (!isSuccess && saveResult)
|
||||
{
|
||||
settingsMessage.Text(L"All remappings were not successfully applied.");
|
||||
}
|
||||
else
|
||||
{
|
||||
settingsMessage.Text(L"Failed to save the remappings.");
|
||||
isSuccess = KeyboardManagerHelper::ErrorType::SaveFailed;
|
||||
}
|
||||
settingsMessage.Text(KeyboardManagerHelper::GetErrorMessage(isSuccess));
|
||||
});
|
||||
|
||||
header.Children().Append(headerText);
|
||||
|
||||
Reference in New Issue
Block a user