diff --git a/OpenNest.Avalonia/ConfirmDialog.cs b/OpenNest.Avalonia/ConfirmDialog.cs
index dfb612b9..d8a4f5c6 100644
--- a/OpenNest.Avalonia/ConfirmDialog.cs
+++ b/OpenNest.Avalonia/ConfirmDialog.cs
@@ -7,11 +7,13 @@ using Avalonia.Media;
namespace OpenNest.Avalonia
{
///
- /// A two-button question. Cancel is the default and Esc, so a stray Enter never discards work.
+ /// A message with a row of buttons ending in Cancel (OK for a plain message). That last
+ /// button is the default and Esc, so a stray Enter never discards work, and closing the
+ /// dialog counts as it.
///
internal sealed class ConfirmDialog : Window
{
- private ConfirmDialog(string title, string message, string confirmText)
+ private ConfirmDialog(string title, string message, string[] choices, string cancelText)
{
Title = title;
Width = 460;
@@ -19,30 +21,52 @@ namespace OpenNest.Avalonia
CanResize = false;
WindowStartupLocation = WindowStartupLocation.CenterOwner;
- var confirm = new Button { Content = confirmText };
- var cancel = new Button { Content = "Cancel", IsDefault = true, IsCancel = true };
- confirm.Click += (_, _) => Close(true);
- cancel.Click += (_, _) => Close(false);
-
var buttons = new StackPanel
{
Orientation = Orientation.Horizontal,
HorizontalAlignment = HorizontalAlignment.Right,
Spacing = 8,
};
- buttons.Children.Add(confirm);
+ for (var i = 0; i < choices.Length; i++)
+ {
+ var index = i;
+ var choice = new Button { Content = choices[i] };
+ choice.Click += (_, _) => Close(index);
+ buttons.Children.Add(choice);
+ }
+ var cancel = new Button { Content = cancelText, IsDefault = true, IsCancel = true };
+ cancel.Click += (_, _) => Close(null);
buttons.Children.Add(cancel);
var panel = new StackPanel { Margin = new Thickness(18), Spacing = 18 };
- panel.Children.Add(new TextBlock { Text = message, TextWrapping = TextWrapping.Wrap });
+ // A long message (many load warnings) scrolls rather than pushing the buttons away.
+ panel.Children.Add(new ScrollViewer
+ {
+ MaxHeight = 420,
+ Content = new TextBlock { Text = message, TextWrapping = TextWrapping.Wrap },
+ });
panel.Children.Add(buttons);
Content = panel;
Opened += (_, _) => cancel.Focus();
}
/// True when the user chose .
- public static Task AskAsync(
+ public static async Task AskAsync(
Window owner, string title, string message, string confirmText) =>
- new ConfirmDialog(title, message, confirmText).ShowDialog(owner);
+ await ChooseAsync(owner, title, message, confirmText) == 0;
+
+ ///
+ /// The index of the choice the user clicked, or -1 for Cancel (also Esc, Enter and
+ /// closing the dialog).
+ ///
+ public static async Task ChooseAsync(
+ Window owner, string title, string message, params string[] choices) =>
+ await new ConfirmDialog(title, message, choices, "Cancel")
+ .ShowDialog(owner) ?? -1;
+
+ /// A message with only an OK button.
+ public static Task ShowAsync(Window owner, string title, string message) =>
+ new ConfirmDialog(title, message, System.Array.Empty(), "OK")
+ .ShowDialog(owner);
}
}
diff --git a/OpenNest.Avalonia/MainWindow.axaml b/OpenNest.Avalonia/MainWindow.axaml
index b9d9bbda..07879def 100644
--- a/OpenNest.Avalonia/MainWindow.axaml
+++ b/OpenNest.Avalonia/MainWindow.axaml
@@ -7,6 +7,11 @@