Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DYN-6993 Add crash protection for window Owner setting #15238

Merged
merged 2 commits into from
May 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions src/DynamoCoreWpf/UI/Prompts/DynamoMessageBox.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,7 @@ public static MessageBoxResult Show(Window owner, string messageBoxText, string
MessageBoxButton = button,
MessageBoxImage = icon
};
if (owner != null && owner.IsLoaded)
{
dynamoMessageBox.Owner = owner;
}

SetOwnerWindow(owner, dynamoMessageBox);
if (showRichTextBox)
{
dynamoMessageBox.BodyTextBlock.Visibility = Visibility.Collapsed;
Expand Down Expand Up @@ -233,12 +229,7 @@ public static MessageBoxResult Show(Window owner,string messageBoxText, string c
MessageBoxButton = button,
MessageBoxImage = icon
};

if (owner != null && owner.IsLoaded)
{
dynamoMessageBox.Owner = owner;
}

SetOwnerWindow(owner, dynamoMessageBox);
dynamoMessageBox.ConfigureButtons(button);
dynamoMessageBox.ShowDialog();
return dynamoMessageBox.CustomDialogResult;
Expand All @@ -264,11 +255,7 @@ public static MessageBoxResult Show(Window owner, string messageBoxText, string
MessageBoxButton = button,
MessageBoxImage = icon
};
if (owner != null && owner.IsLoaded)
{
dynamoMessageBox.Owner = owner;
}

SetOwnerWindow(owner, dynamoMessageBox);
if (flags.TryGetValue(DialogFlags.Scrollable, out bool scrollable) && scrollable)
{
dynamoMessageBox.BodyTextBlock.Visibility = Visibility.Collapsed;
Expand Down Expand Up @@ -361,15 +348,30 @@ internal static MessageBoxResult Show(Window owner, string messageBoxText, strin
MessageBoxButton = button,
MessageBoxImage = icon
};
SetOwnerWindow(owner, dynamoMessageBox);
dynamoMessageBox.ConfigureButtons(button, buttonNames);
dynamoMessageBox.ShowDialog();
return dynamoMessageBox.CustomDialogResult;
}

/// <summary>
/// Set the owner window of the message box and prevent any exceptions that may occur
/// </summary>
/// <param name="owner">Owner Window</param>
/// <param name="dynamoMessageBox">New message box</param>
internal static void SetOwnerWindow(Window owner, DynamoMessageBox dynamoMessageBox)
{
if (owner != null && owner.IsLoaded)
{
dynamoMessageBox.Owner = owner;
try
{
dynamoMessageBox.Owner = owner;
}
catch (Exception)
{
// In this case, we will not set the owner window
}
}

dynamoMessageBox.ConfigureButtons(button, buttonNames);
dynamoMessageBox.ShowDialog();
return dynamoMessageBox.CustomDialogResult;
}

public event PropertyChangedEventHandler PropertyChanged;
Expand Down
Loading