[KBM Editor] Catch UpdateLayout exceptions (#13635)

This commit is contained in:
Jaime Bernardo 2021-10-06 15:54:15 +01:00 committed by GitHub
parent 805d8d81c5
commit 68c199aa64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 88 additions and 11 deletions

View File

@ -354,7 +354,14 @@ inline void CreateEditKeyboardWindowImpl(HINSTANCE hInst, KBMEditor::KeyboardMan
xamlContainer.Children().Append(header);
xamlContainer.Children().Append(helperText);
xamlContainer.Children().Append(scrollViewer);
xamlContainer.UpdateLayout();
try
{
// If a layout update has been triggered by other methods (e.g.: adapting to zoom level), this may throw an exception.
xamlContainer.UpdateLayout();
}
catch (...)
{
}
desktopSource.Content(xamlContainer);
////End XAML Island section

View File

@ -325,7 +325,14 @@ inline void CreateEditShortcutsWindowImpl(HINSTANCE hInst, KBMEditor::KeyboardMa
xamlContainer.Children().Append(header);
xamlContainer.Children().Append(helperText);
xamlContainer.Children().Append(scrollViewer);
xamlContainer.UpdateLayout();
try
{
// If a layout update has been triggered by other methods (e.g.: adapting to zoom level), this may throw an exception.
xamlContainer.UpdateLayout();
}
catch (...)
{
}
desktopSource.Content(xamlContainer);

View File

@ -171,8 +171,22 @@ void KeyboardManagerState::UpdateDetectShortcutUI()
AddKeyToLayout(currentShortcutUI2.as<StackPanel>(), shortcut[i]);
}
}
currentShortcutUI1.as<StackPanel>().UpdateLayout();
currentShortcutUI2.as<StackPanel>().UpdateLayout();
try
{
// If a layout update has been triggered by other methods (e.g.: adapting to zoom level), this may throw an exception.
currentShortcutUI1.as<StackPanel>().UpdateLayout();
}
catch (...)
{
}
try
{
// If a layout update has been triggered by other methods (e.g.: adapting to zoom level), this may throw an exception.
currentShortcutUI2.as<StackPanel>().UpdateLayout();
}
catch (...)
{
}
});
}
@ -189,7 +203,14 @@ void KeyboardManagerState::UpdateDetectSingleKeyRemapUI()
currentSingleKeyUI.as<StackPanel>().Children().Clear();
hstring key = winrt::to_hstring(keyboardMap.GetKeyName(detectedRemapKey).c_str());
AddKeyToLayout(currentSingleKeyUI.as<StackPanel>(), key);
currentSingleKeyUI.as<StackPanel>().UpdateLayout();
try
{
// If a layout update has been triggered by other methods (e.g.: adapting to zoom level), this may throw an exception.
currentSingleKeyUI.as<StackPanel>().UpdateLayout();
}
catch (...)
{
}
});
}

View File

@ -42,7 +42,14 @@ ShortcutControl::ShortcutControl(StackPanel table, StackPanel row, const int col
shortcutControlLayout.as<StackPanel>().Children().Append(typeShortcut.as<Button>());
shortcutControlLayout.as<StackPanel>().Children().Append(shortcutDropDownStackPanel.as<StackPanel>());
KeyDropDownControl::AddDropDown(table, row, shortcutDropDownStackPanel.as<StackPanel>(), colIndex, shortcutRemapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, false);
shortcutControlLayout.as<StackPanel>().UpdateLayout();
try
{
// If a layout update has been triggered by other methods (e.g.: adapting to zoom level), this may throw an exception.
shortcutControlLayout.as<StackPanel>().UpdateLayout();
}
catch (...)
{
}
}
// Function to set the accessible name of the target App text box
@ -480,7 +487,14 @@ void ShortcutControl::CreateDetectShortcutWindow(winrt::Windows::Foundation::IIn
buttonPanel.Children().Append(cancelButton);
stackPanel.Children().Append(buttonPanel);
stackPanel.UpdateLayout();
try
{
// If a layout update has been triggered by other methods (e.g.: adapting to zoom level), this may throw an exception.
stackPanel.UpdateLayout();
}
catch (...)
{
}
// Configure the keyboardManagerState to store the UI information.
keyboardManagerState.ConfigureDetectShortcutUI(keyStackPanel1, keyStackPanel2);

View File

@ -56,7 +56,14 @@ SingleKeyRemapControl::SingleKeyRemapControl(StackPanel table, StackPanel row, c
}
});
singleKeyRemapControlLayout.as<StackPanel>().UpdateLayout();
try
{
// If a layout update has been triggered by other methods (e.g.: adapting to zoom level), this may throw an exception.
singleKeyRemapControlLayout.as<StackPanel>().UpdateLayout();
}
catch (...)
{
}
}
// Function to set the accessible names for all the controls in a row
@ -168,7 +175,14 @@ void SingleKeyRemapControl::AddNewControlKeyRemapRow(StackPanel& parent, std::ve
}
children.RemoveAt(rowIndex);
parent.UpdateLayout();
try
{
// If a layout update has been triggered by other methods (e.g.: adapting to zoom level), this may throw an exception.
parent.UpdateLayout();
}
catch (...)
{
}
singleKeyRemapBuffer.erase(singleKeyRemapBuffer.begin() + rowIndex);
// delete the SingleKeyRemapControl objects so that they get destructed
@ -183,7 +197,14 @@ void SingleKeyRemapControl::AddNewControlKeyRemapRow(StackPanel& parent, std::ve
deleteRemapKeystoolTip.Content(box_value(GET_RESOURCE_STRING(IDS_DELETE_REMAPPING_BUTTON)));
ToolTipService::SetToolTip(deleteRemapKeys, deleteRemapKeystoolTip);
row.Children().Append(deleteRemapKeys);
parent.UpdateLayout();
try
{
// If a layout update has been triggered by other methods (e.g.: adapting to zoom level), this may throw an exception.
parent.UpdateLayout();
}
catch (...)
{
}
// Set accessible names
UpdateAccessibleNames(keyboardRemapControlObjects.back()[0]->getSingleKeyRemapControl(), keyboardRemapControlObjects.back()[1]->getSingleKeyRemapControl(), deleteRemapKeys, (int)keyboardRemapControlObjects.size());
@ -362,7 +383,14 @@ void SingleKeyRemapControl::createDetectKeyWindow(winrt::Windows::Foundation::II
buttonPanel.Children().Append(cancelButton);
stackPanel.Children().Append(buttonPanel);
stackPanel.UpdateLayout();
try
{
// If a layout update has been triggered by other methods (e.g.: adapting to zoom level), this may throw an exception.
stackPanel.UpdateLayout();
}
catch (...)
{
}
// Configure the keyboardManagerState to store the UI information.
keyboardManagerState.ConfigureDetectSingleKeyRemapUI(keyStackPanel);