using System; using System.Threading.Tasks; using Avalonia.Controls; namespace Artemis.UI.Shared.Services.Builders { /// /// Represents a builder that can create a . /// public class OpenFileDialogBuilder { private readonly OpenFileDialog _openFileDialog; private readonly Window _parent; /// /// Creates a new instance of the class. /// /// The parent window that will host the dialog. public OpenFileDialogBuilder(Window parent) { _parent = parent; _openFileDialog = new OpenFileDialog(); } /// /// Indicate that the user can select multiple files. /// public OpenFileDialogBuilder WithAllowMultiple() { _openFileDialog.AllowMultiple = true; return this; } /// /// Set the title of the dialog /// public OpenFileDialogBuilder WithTitle(string? title) { _openFileDialog.Title = title; return this; } /// /// Set the initial directory of the dialog /// public OpenFileDialogBuilder WithDirectory(string? directory) { _openFileDialog.Directory = directory; return this; } /// /// Set the initial file name of the dialog /// public OpenFileDialogBuilder WithInitialFileName(string? initialFileName) { _openFileDialog.InitialFileName = initialFileName; return this; } /// /// Add a filter to the dialog /// public OpenFileDialogBuilder HavingFilter(Action configure) { FileDialogFilterBuilder builder = new(); configure(builder); _openFileDialog.Filters.Add(builder.Build()); return this; } /// /// Asynchronously shows the file dialog. /// /// /// A task that on completion returns an array containing the full path to the selected /// files, or null if the dialog was canceled. /// public async Task ShowAsync() { return await _openFileDialog.ShowAsync(_parent); } } }