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() { return GetFileTypes()?.Select(f => new FileDialogFilter { Name = f.Name, Extensions = f.Patterns!.ToList() }).ToList() ?? new List(); } List? GetFileTypes() { var selectedItem = (this.Get("FilterSelector").SelectedItem as ComboBoxItem)?.Content ?? "None"; var binLogType = new FilePickerFileType("Binary Log") { Patterns = new[] { "*.binlog", "*.buildlog" }, MimeTypes = new[] { "application/binlog", "application/buildlog" }, AppleUniformTypeIdentifiers = new[] { "public.data" } }; return selectedItem switch { "All + TXT + BinLog" => new List { FilePickerFileTypes.All, FilePickerFileTypes.TextPlain, binLogType }, "Binlog" => new List { binLogType }, "TXT extension only" => new List { new("TXT") { Patterns = FilePickerFileTypes.TextPlain.Patterns } }, "TXT mime only" => new List { new("TXT") { MimeTypes = FilePickerFileTypes.TextPlain.MimeTypes } }, "TXT apple type id only" => new List { new("TXT") { AppleUniformTypeIdentifiers = FilePickerFileTypes.TextPlain.AppleUniformTypeIdentifiers } }, _ => null }; } this.Get