using Avalonia; using Avalonia.Controls; using Avalonia.Layout; namespace GsaEditor.Helpers; /// /// Provides simple dialog utilities (confirm, message, input) using programmatically-created Avalonia windows. /// No third-party controls or custom themes are used. /// public static class Dialogs { /// /// Shows a confirmation dialog with Yes/No buttons. /// /// The parent window. /// Dialog title. /// Message to display. /// True if the user clicked Yes, false otherwise. public static async Task ConfirmAsync(Window parent, string title, string message) { var result = false; var dialog = new Window { Title = title, Width = 420, Height = 170, WindowStartupLocation = WindowStartupLocation.CenterOwner, CanResize = false, ShowInTaskbar = false }; var messageBlock = new TextBlock { Text = message, TextWrapping = Avalonia.Media.TextWrapping.Wrap, Margin = new Thickness(0, 0, 0, 15) }; var yesButton = new Button { Content = "Yes", Width = 80, HorizontalContentAlignment = HorizontalAlignment.Center }; yesButton.Click += (_, _) => { result = true; dialog.Close(); }; var noButton = new Button { Content = "No", Width = 80, HorizontalContentAlignment = HorizontalAlignment.Center }; noButton.Click += (_, _) => { result = false; dialog.Close(); }; var buttonPanel = new StackPanel { Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Right, Spacing = 10, Children = { yesButton, noButton } }; dialog.Content = new StackPanel { Margin = new Thickness(20), Spacing = 5, Children = { messageBlock, buttonPanel } }; await dialog.ShowDialog(parent); return result; } /// /// Shows a simple message dialog with an OK button. /// /// The parent window. /// Dialog title. /// Message to display. public static async Task ShowMessageAsync(Window parent, string title, string message) { var dialog = new Window { Title = title, Width = 420, Height = 180, WindowStartupLocation = WindowStartupLocation.CenterOwner, CanResize = false, ShowInTaskbar = false }; var messageBlock = new TextBlock { Text = message, TextWrapping = Avalonia.Media.TextWrapping.Wrap, Margin = new Thickness(0, 0, 0, 15) }; var okButton = new Button { Content = "OK", Width = 80, HorizontalAlignment = HorizontalAlignment.Right, HorizontalContentAlignment = HorizontalAlignment.Center }; okButton.Click += (_, _) => dialog.Close(); dialog.Content = new StackPanel { Margin = new Thickness(20), Spacing = 5, Children = { messageBlock, okButton } }; await dialog.ShowDialog(parent); } /// /// Shows an input dialog with a text box, OK and Cancel buttons. /// /// The parent window. /// Dialog title. /// Prompt text shown above the input. /// Default value in the text box. /// The entered string, or null if cancelled. public static async Task InputAsync(Window parent, string title, string prompt, string defaultValue = "") { string? result = null; var dialog = new Window { Title = title, Width = 450, Height = 180, WindowStartupLocation = WindowStartupLocation.CenterOwner, CanResize = false, ShowInTaskbar = false }; var promptBlock = new TextBlock { Text = prompt, Margin = new Thickness(0, 0, 0, 5) }; var textBox = new TextBox { Text = defaultValue, Margin = new Thickness(0, 0, 0, 10) }; var okButton = new Button { Content = "OK", Width = 80, HorizontalContentAlignment = HorizontalAlignment.Center }; okButton.Click += (_, _) => { result = textBox.Text; dialog.Close(); }; var cancelButton = new Button { Content = "Cancel", Width = 80, HorizontalContentAlignment = HorizontalAlignment.Center }; cancelButton.Click += (_, _) => { result = null; dialog.Close(); }; var buttonPanel = new StackPanel { Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Right, Spacing = 10, Children = { okButton, cancelButton } }; dialog.Content = new StackPanel { Margin = new Thickness(20), Spacing = 5, Children = { promptBlock, textBox, buttonPanel } }; await dialog.ShowDialog(parent); return result; } }