| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="MessageBoxBuilder.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System.Threading; |
| | | 8 | | using System.Threading.Tasks; |
| | | 9 | | |
| | | 10 | | namespace MyNet.UI.Dialogs.MessageBox; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Builder for constructing and displaying message boxes with customizable options. |
| | | 14 | | /// </summary> |
| | | 15 | | /// <param name="service">The message box service used to display the message box.</param> |
| | | 16 | | public sealed class MessageBoxBuilder(IMessageBoxService service) : IMessageBoxBuilder |
| | | 17 | | { |
| | 0 | 18 | | private readonly MessageBoxOptions _options = new(); |
| | | 19 | | |
| | | 20 | | /// <inheritdoc /> |
| | | 21 | | public IMessageBoxBuilder WithMessage(string message) |
| | | 22 | | { |
| | 0 | 23 | | _options.Message = message; |
| | 0 | 24 | | return this; |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <inheritdoc /> |
| | | 28 | | public IMessageBoxBuilder WithTitle(string title) |
| | | 29 | | { |
| | 0 | 30 | | _options.Title = title; |
| | 0 | 31 | | return this; |
| | | 32 | | } |
| | | 33 | | |
| | | 34 | | /// <inheritdoc /> |
| | | 35 | | public IMessageBoxBuilder WithSeverity(MessageSeverity severity) |
| | | 36 | | { |
| | 0 | 37 | | _options.Severity = severity; |
| | 0 | 38 | | return this; |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | /// <inheritdoc /> |
| | | 42 | | public IMessageBoxBuilder WithButtons(MessageBoxResultOption buttons) |
| | | 43 | | { |
| | 0 | 44 | | _options.Buttons = buttons; |
| | 0 | 45 | | return this; |
| | | 46 | | } |
| | | 47 | | |
| | | 48 | | /// <inheritdoc /> |
| | | 49 | | public IMessageBoxBuilder WithDefaultResult(MessageBoxResult result) |
| | | 50 | | { |
| | 0 | 51 | | _options.DefaultResult = result; |
| | 0 | 52 | | return this; |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | /// <inheritdoc /> |
| | 0 | 56 | | public Task<MessageBoxResult> ShowAsync(CancellationToken cancellationToken = default) => service.ShowAsync(_options |
| | | 57 | | } |
| | | 58 | | |