diff --git a/src/Artemis.UI.Shared/Services/Builders/FileDialogFilterBuilder.cs b/src/Artemis.UI.Shared/Services/Builders/FileDialogFilterBuilder.cs index a53d6dec5..e3c946804 100644 --- a/src/Artemis.UI.Shared/Services/Builders/FileDialogFilterBuilder.cs +++ b/src/Artemis.UI.Shared/Services/Builders/FileDialogFilterBuilder.cs @@ -1,4 +1,7 @@ -using Avalonia.Controls; +using System.Collections.Generic; +using System.Linq; +using Avalonia.Controls; +using Avalonia.Platform.Storage; namespace Artemis.UI.Shared.Services.Builders; @@ -7,11 +10,12 @@ namespace Artemis.UI.Shared.Services.Builders; /// public class FileDialogFilterBuilder { - private readonly FileDialogFilter _filter; + private string _name; + private readonly List _extensions = new(); internal FileDialogFilterBuilder() { - _filter = new FileDialogFilter(); + _name = "Unknown"; } /// @@ -19,7 +23,7 @@ public class FileDialogFilterBuilder /// public FileDialogFilterBuilder WithName(string name) { - _filter.Name = name; + _name = name; return this; } @@ -28,12 +32,16 @@ public class FileDialogFilterBuilder /// public FileDialogFilterBuilder WithExtension(string extension) { - _filter.Extensions.Add(extension); + if (!_extensions.Contains(extension)) + _extensions.Add(extension); return this; } - internal FileDialogFilter Build() + internal FilePickerFileType Build() { - return _filter; + return new FilePickerFileType(_name) + { + Patterns = _extensions.Select(e => "*." + e).ToList() + }; } } \ No newline at end of file diff --git a/src/Artemis.UI.Shared/Services/Builders/OpenFileDialogBuilder.cs b/src/Artemis.UI.Shared/Services/Builders/OpenFileDialogBuilder.cs index af53d1e72..e3785eea9 100644 --- a/src/Artemis.UI.Shared/Services/Builders/OpenFileDialogBuilder.cs +++ b/src/Artemis.UI.Shared/Services/Builders/OpenFileDialogBuilder.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Avalonia.Controls; +using Avalonia.Platform.Storage; namespace Artemis.UI.Shared.Services.Builders; @@ -10,8 +12,9 @@ namespace Artemis.UI.Shared.Services.Builders; /// public class OpenFileDialogBuilder { - private readonly OpenFileDialog _openFileDialog; private readonly Window _parent; + private readonly FilePickerOpenOptions _options; + private List? _fileTypeFilters; /// /// Creates a new instance of the class. @@ -20,7 +23,7 @@ public class OpenFileDialogBuilder internal OpenFileDialogBuilder(Window parent) { _parent = parent; - _openFileDialog = new OpenFileDialog(); + _options = new FilePickerOpenOptions(); } /// @@ -28,7 +31,7 @@ public class OpenFileDialogBuilder /// public OpenFileDialogBuilder WithAllowMultiple() { - _openFileDialog.AllowMultiple = true; + _options.AllowMultiple = true; return this; } @@ -37,7 +40,7 @@ public class OpenFileDialogBuilder /// public OpenFileDialogBuilder WithTitle(string? title) { - _openFileDialog.Title = title; + _options.Title = title; return this; } @@ -46,16 +49,7 @@ public class OpenFileDialogBuilder /// 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; + _options.SuggestedStartLocation = directory != null ? _parent.StorageProvider.TryGetFolderFromPathAsync(directory).GetAwaiter().GetResult() : null; return this; } @@ -67,8 +61,9 @@ public class OpenFileDialogBuilder FileDialogFilterBuilder builder = new(); configure(builder); - _openFileDialog.Filters ??= new List(); - _openFileDialog.Filters.Add(builder.Build()); + _fileTypeFilters ??= new List(); + _fileTypeFilters.Add(builder.Build()); + _options.FileTypeFilter = _fileTypeFilters; return this; } @@ -82,6 +77,7 @@ public class OpenFileDialogBuilder /// public async Task ShowAsync() { - return await _openFileDialog.ShowAsync(_parent); + IReadOnlyList files = await _parent.StorageProvider.OpenFilePickerAsync(_options); + return files.Select(f => f.Path.AbsolutePath).ToArray(); } } \ No newline at end of file diff --git a/src/Artemis.UI.Shared/Services/Builders/OpenFolderDialogBuilder.cs b/src/Artemis.UI.Shared/Services/Builders/OpenFolderDialogBuilder.cs index 47846d170..25305b25c 100644 --- a/src/Artemis.UI.Shared/Services/Builders/OpenFolderDialogBuilder.cs +++ b/src/Artemis.UI.Shared/Services/Builders/OpenFolderDialogBuilder.cs @@ -1,5 +1,8 @@ -using System.Threading.Tasks; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; using Avalonia.Controls; +using Avalonia.Platform.Storage; namespace Artemis.UI.Shared.Services.Builders; @@ -8,8 +11,8 @@ namespace Artemis.UI.Shared.Services.Builders; /// public class OpenFolderDialogBuilder { - private readonly OpenFolderDialog _openFolderDialog; private readonly Window _parent; + private readonly FolderPickerOpenOptions _options; /// /// Creates a new instance of the class. @@ -18,16 +21,15 @@ public class OpenFolderDialogBuilder internal OpenFolderDialogBuilder(Window parent) { _parent = parent; - _openFolderDialog = new OpenFolderDialog(); + _options = new FolderPickerOpenOptions {AllowMultiple = false}; } - /// /// Set the title of the dialog /// public OpenFolderDialogBuilder WithTitle(string? title) { - _openFolderDialog.Title = title; + _options.Title = title; return this; } @@ -36,7 +38,7 @@ public class OpenFolderDialogBuilder /// public OpenFolderDialogBuilder WithDirectory(string? directory) { - _openFolderDialog.Directory = directory; + _options.SuggestedStartLocation = directory != null ? _parent.StorageProvider.TryGetFolderFromPathAsync(directory).GetAwaiter().GetResult() : null; return this; } @@ -49,6 +51,7 @@ public class OpenFolderDialogBuilder /// public async Task ShowAsync() { - return await _openFolderDialog.ShowAsync(_parent); + IReadOnlyList folder = await _parent.StorageProvider.OpenFolderPickerAsync(_options); + return folder.FirstOrDefault()?.Path.AbsolutePath; } } \ No newline at end of file diff --git a/src/Artemis.UI.Shared/Services/Builders/SaveFileDialogBuilder.cs b/src/Artemis.UI.Shared/Services/Builders/SaveFileDialogBuilder.cs index 7662f7228..a4bc95f18 100644 --- a/src/Artemis.UI.Shared/Services/Builders/SaveFileDialogBuilder.cs +++ b/src/Artemis.UI.Shared/Services/Builders/SaveFileDialogBuilder.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using Avalonia.Controls; +using Avalonia.Platform.Storage; namespace Artemis.UI.Shared.Services.Builders; @@ -11,8 +12,9 @@ namespace Artemis.UI.Shared.Services.Builders; public class SaveFileDialogBuilder { private readonly Window _parent; - private readonly SaveFileDialog _saveFileDialog; - + private readonly FilePickerSaveOptions _options; + private List? _fileTypeFilters; + /// /// Creates a new instance of the class. /// @@ -20,7 +22,7 @@ public class SaveFileDialogBuilder internal SaveFileDialogBuilder(Window parent) { _parent = parent; - _saveFileDialog = new SaveFileDialog(); + _options = new FilePickerSaveOptions(); } /// @@ -28,7 +30,7 @@ public class SaveFileDialogBuilder /// public SaveFileDialogBuilder WithTitle(string? title) { - _saveFileDialog.Title = title; + _options.Title = title; return this; } @@ -37,7 +39,7 @@ public class SaveFileDialogBuilder /// public SaveFileDialogBuilder WithDirectory(string? directory) { - _saveFileDialog.Directory = directory; + _options.SuggestedStartLocation = directory != null ? _parent.StorageProvider.TryGetFolderFromPathAsync(directory).GetAwaiter().GetResult() : null; return this; } @@ -46,16 +48,7 @@ public class SaveFileDialogBuilder /// public SaveFileDialogBuilder WithInitialFileName(string? initialFileName) { - _saveFileDialog.InitialFileName = initialFileName; - return this; - } - - /// - /// Set the default extension of the dialog - /// - public SaveFileDialogBuilder WithDefaultExtension(string? defaultExtension) - { - _saveFileDialog.DefaultExtension = defaultExtension; + _options.SuggestedFileName = initialFileName; return this; } @@ -67,8 +60,9 @@ public class SaveFileDialogBuilder FileDialogFilterBuilder builder = new(); configure(builder); - _saveFileDialog.Filters ??= new List(); - _saveFileDialog.Filters.Add(builder.Build()); + _fileTypeFilters ??= new List(); + _fileTypeFilters.Add(builder.Build()); + _options.FileTypeChoices = _fileTypeFilters; return this; } @@ -82,6 +76,7 @@ public class SaveFileDialogBuilder /// public async Task ShowAsync() { - return await _saveFileDialog.ShowAsync(_parent); + IStorageFile? path = await _parent.StorageProvider.SaveFilePickerAsync(_options); + return path?.Path.AbsolutePath; } } \ No newline at end of file diff --git a/src/Artemis.UI.Shared/Styles/Border.axaml b/src/Artemis.UI.Shared/Styles/Border.axaml index 9bb22454e..afcd9dee8 100644 --- a/src/Artemis.UI.Shared/Styles/Border.axaml +++ b/src/Artemis.UI.Shared/Styles/Border.axaml @@ -8,7 +8,7 @@ I'm in a panel yo! - + I'm in a panel yo! @@ -44,7 +44,7 @@ -