Skip to content

Commit

Permalink
Fixed force activation of the main window when an error dialog is shown
Browse files Browse the repository at this point in the history
  • Loading branch information
まいこ committed May 1, 2024
1 parent bd73561 commit 0356417
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion OpenUtau/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ public void OnNext(UCommand cmd, bool isUndo) {
MessageBox.MessageBoxButtons.Ok);
break;
default:
MessageBox.ShowError(this, notif.message, notif.e);
MessageBox.ShowError(this, notif.e, notif.message);
break;
}
} else if (cmd is LoadingNotification loadingNotif && loadingNotif.window == typeof(MainWindow)) {
Expand Down
25 changes: 14 additions & 11 deletions OpenUtau/Views/MessageBox.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Interactivity;
using Avalonia.Threading;
using OpenUtau.Core;
Expand All @@ -27,13 +30,16 @@ public void SetText(string text) {
});
}

public static Task<MessageBoxResult> ShowError(Window parent, Exception? e) {
return ShowError(parent, string.Empty, e);
}

public static Task<MessageBoxResult> ShowError(Window parent, string message, Exception? e) {
public static Task<MessageBoxResult> ShowError(Window parent, Exception? e, string message = "") {
string text = message;
string title = ThemeManager.GetString("errors.caption");
IReadOnlyList<Window> dialogs = ((IClassicDesktopStyleApplicationLifetime)Application.Current!.ApplicationLifetime!).Windows;
foreach (var dialog in dialogs) {
if (dialog.IsActive) {
parent = dialog;
break;
}
}

if (e is MessageCustomizableException mce) {
if (!string.IsNullOrEmpty(mce.TranslatableMessage)) {
Expand All @@ -44,7 +50,7 @@ public static Task<MessageBoxResult> ShowError(Window parent, string message, Ex
}

if (!mce.ShowStackTrace) {
return Show(parent, text, null, title, MessageBoxButtons.Ok);
return Show(parent, text, title, MessageBoxButtons.Ok);
}
}

Expand Down Expand Up @@ -81,13 +87,10 @@ public static Task<MessageBoxResult> ShowError(Window parent, string message, Ex
builder.AppendLine();
builder.AppendLine(System.Reflection.Assembly.GetEntryAssembly()?.GetName().Version?.ToString() ?? "Unknown Version");

return Show(parent, text, builder.ToString(), title, MessageBoxButtons.OkCopy);
return Show(parent, text, title, MessageBoxButtons.OkCopy, builder.ToString());
}

public static Task<MessageBoxResult> Show(Window parent, string text, string title, MessageBoxButtons buttons) {
return Show(parent, text, null, title, buttons);
}
public static Task<MessageBoxResult> Show(Window parent, string text, string? stackTrace, string title, MessageBoxButtons buttons) {
public static Task<MessageBoxResult> Show(Window parent, string text, string title, MessageBoxButtons buttons, string? stackTrace = null) {
var msgbox = new MessageBox() {
Title = title
};
Expand Down

0 comments on commit 0356417

Please sign in to comment.