| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="FileDialogBuilderBase.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.FileDialogs; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Base implementation for fluent file dialog builders. |
| | | 14 | | /// </summary> |
| | | 15 | | /// <typeparam name="TBuilder">The concrete builder type.</typeparam> |
| | | 16 | | /// <typeparam name="TSettings">The dialog settings type.</typeparam> |
| | | 17 | | public abstract class FileDialogBuilderBase<TBuilder, TSettings> : IFileDialogBuilder<TBuilder, TSettings> |
| | | 18 | | where TBuilder : FileDialogBuilderBase<TBuilder, TSettings> |
| | | 19 | | where TSettings : FileDialogSettings, new() |
| | | 20 | | { |
| | | 21 | | /// <summary> |
| | | 22 | | /// Gets the settings being configured. |
| | | 23 | | /// </summary> |
| | 9 | 24 | | protected TSettings Settings { get; } = new(); |
| | | 25 | | |
| | | 26 | | /// <inheritdoc /> |
| | | 27 | | public TBuilder WithFileName(string fileName) |
| | | 28 | | { |
| | 6 | 29 | | Settings.FileName = fileName; |
| | 6 | 30 | | return (TBuilder)this; |
| | | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <inheritdoc /> |
| | | 34 | | public TBuilder WithInitialDirectory(string initialDirectory) |
| | | 35 | | { |
| | 3 | 36 | | Settings.InitialDirectory = initialDirectory; |
| | 3 | 37 | | return (TBuilder)this; |
| | | 38 | | } |
| | | 39 | | |
| | | 40 | | /// <inheritdoc /> |
| | | 41 | | public TBuilder WithFilters(string? filters) |
| | | 42 | | { |
| | 3 | 43 | | Settings.Filters = filters; |
| | 3 | 44 | | return (TBuilder)this; |
| | | 45 | | } |
| | | 46 | | |
| | | 47 | | /// <inheritdoc /> |
| | | 48 | | public TBuilder WithDefaultExtension(string defaultExtension) |
| | | 49 | | { |
| | 3 | 50 | | Settings.DefaultExtension = defaultExtension; |
| | 3 | 51 | | return (TBuilder)this; |
| | | 52 | | } |
| | | 53 | | |
| | | 54 | | /// <inheritdoc /> |
| | | 55 | | public TBuilder WithTitle(string title) |
| | | 56 | | { |
| | 0 | 57 | | Settings.Title = title; |
| | 0 | 58 | | return (TBuilder)this; |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | /// <inheritdoc /> |
| | 6 | 62 | | public TSettings Build() => Settings; |
| | | 63 | | |
| | | 64 | | /// <inheritdoc /> |
| | | 65 | | public abstract Task<FileDialogResult> PickAsync(CancellationToken cancellationToken = default); |
| | | 66 | | } |
| | | 67 | | |