Skip to content

Commit

Permalink
[KBM Editor] Catch UpdateLayout exceptions (#13635)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimecbernardo committed Oct 6, 2021
1 parent 805d8d8 commit 68c199a
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (...)
{
}
});
}

Expand All @@ -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 (...)
{
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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());
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 68c199a

Please sign in to comment.