using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Avalonia.Controls.Platform; namespace Avalonia.Controls { public abstract class FileDialog : FileSystemDialog { public List Filters { get; set; } = new List(); public string InitialFileName { get; set; } } public abstract class FileSystemDialog : SystemDialog { [Obsolete("Use Directory")] public string InitialDirectory { get => Directory; set => Directory = value; } public string Directory { get; set; } } public class SaveFileDialog : FileDialog { public string DefaultExtension { get; set; } public async Task ShowAsync(Window parent) { if(parent == null) throw new ArgumentNullException(nameof(parent)); return ((await AvaloniaLocator.Current.GetService() .ShowFileDialogAsync(this, parent)) ?? Array.Empty()).FirstOrDefault(); } } public class OpenFileDialog : FileDialog { public bool AllowMultiple { get; set; } public Task ShowAsync(Window parent) { if(parent == null) throw new ArgumentNullException(nameof(parent)); return AvaloniaLocator.Current.GetService().ShowFileDialogAsync(this, parent); } } public class OpenFolderDialog : FileSystemDialog { [Obsolete("Use Directory")] public string DefaultDirectory { get => Directory; set => Directory = value; } public Task ShowAsync(Window parent) { if(parent == null) throw new ArgumentNullException(nameof(parent)); return AvaloniaLocator.Current.GetService().ShowFolderDialogAsync(this, parent); } } public abstract class SystemDialog { public string Title { get; set; } } public class FileDialogFilter { public string Name { get; set; } public List Extensions { get; set; } = new List(); } }