using System; using System.Buffers; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Threading.Tasks; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Presenters; using Avalonia.Dialogs; using Avalonia.Layout; using Avalonia.Markup.Xaml; using Avalonia.Platform.Storage; using Avalonia.Platform.Storage.FileIO; #pragma warning disable CS0618 // Type or member is obsolete #nullable enable namespace ControlCatalog.Pages { public class DialogsPage : UserControl { public DialogsPage() { this.InitializeComponent(); IStorageFolder? lastSelectedDirectory = null; bool ignoreTextChanged = false; var results = this.Get("PickerLastResults"); var resultsVisible = this.Get("PickerLastResultsVisible"); var bookmarkContainer = this.Get("BookmarkContainer"); var openedFileContent = this.Get("OpenedFileContent"); var openMultiple = this.Get("OpenMultiple"); var currentFolderBox = this.Get("CurrentFolderBox"); currentFolderBox.TextChanged += async (sender, args) => { if (ignoreTextChanged) return; if (Enum.TryParse(currentFolderBox.Text, true, out var folderEnum)) { lastSelectedDirectory = await GetStorageProvider().TryGetWellKnownFolderAsync(folderEnum); } else { if (!Uri.TryCreate(currentFolderBox.Text, UriKind.Absolute, out var folderLink)) { Uri.TryCreate("file://" + currentFolderBox.Text, UriKind.Absolute, out folderLink); } if (folderLink is not null) { lastSelectedDirectory = await GetStorageProvider().TryGetFolderFromPathAsync(folderLink); } } }; List GetFilters() { if (this.Get("UseFilters").IsChecked != true) return new List(); return new List { new FileDialogFilter { Name = "Text files (.txt)", Extensions = new List {"txt"} }, new FileDialogFilter { Name = "All files", Extensions = new List {"*"} } }; } List? GetFileTypes() { if (this.Get("UseFilters").IsChecked != true) return null; return new List { FilePickerFileTypes.All, FilePickerFileTypes.TextPlain, new("Binary Log") { Patterns = new[] { "*.binlog", "*.buildlog" }, MimeTypes = new[] { "application/binlog", "application/buildlog" }, AppleUniformTypeIdentifiers = new []{ "public.data" } } }; } this.Get