From ac91b14cafcc283748143d56e3c6c428fae36876 Mon Sep 17 00:00:00 2001 From: Emmanuel Hansen Date: Mon, 22 Jan 2024 23:02:24 +0000 Subject: [PATCH] set filename for both open file and open folder dialogs (#14308) --- samples/ControlCatalog/Pages/DialogsPage.xaml.cs | 2 ++ .../Platform/Storage/FilePickerSaveOptions.cs | 5 ----- src/Avalonia.Base/Platform/Storage/PickerOptions.cs | 10 +++++++++- src/Avalonia.Native/SystemDialogs.cs | 2 +- src/Windows/Avalonia.Win32/Win32StorageProvider.cs | 4 ++-- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/samples/ControlCatalog/Pages/DialogsPage.xaml.cs b/samples/ControlCatalog/Pages/DialogsPage.xaml.cs index 143db003cd..c92eaf3e0e 100644 --- a/samples/ControlCatalog/Pages/DialogsPage.xaml.cs +++ b/samples/ControlCatalog/Pages/DialogsPage.xaml.cs @@ -222,6 +222,7 @@ namespace ControlCatalog.Pages { Title = "Open file", FileTypeFilter = GetFileTypes(), + SuggestedFileName = "FileName", SuggestedStartLocation = lastSelectedDirectory, AllowMultiple = openMultiple.IsChecked == true }); @@ -264,6 +265,7 @@ namespace ControlCatalog.Pages { Title = "Folder file", SuggestedStartLocation = lastSelectedDirectory, + SuggestedFileName = "FileName", AllowMultiple = openMultiple.IsChecked == true }); diff --git a/src/Avalonia.Base/Platform/Storage/FilePickerSaveOptions.cs b/src/Avalonia.Base/Platform/Storage/FilePickerSaveOptions.cs index fa4fccd47a..267ba59c71 100644 --- a/src/Avalonia.Base/Platform/Storage/FilePickerSaveOptions.cs +++ b/src/Avalonia.Base/Platform/Storage/FilePickerSaveOptions.cs @@ -7,11 +7,6 @@ namespace Avalonia.Platform.Storage; /// public class FilePickerSaveOptions : PickerOptions { - /// - /// Gets or sets the file name that the file save picker suggests to the user. - /// - public string? SuggestedFileName { get; set; } - /// /// Gets or sets the default extension to be used to save the file. /// diff --git a/src/Avalonia.Base/Platform/Storage/PickerOptions.cs b/src/Avalonia.Base/Platform/Storage/PickerOptions.cs index 07f99f32c8..4fcc85a07a 100644 --- a/src/Avalonia.Base/Platform/Storage/PickerOptions.cs +++ b/src/Avalonia.Base/Platform/Storage/PickerOptions.cs @@ -1,4 +1,7 @@ -namespace Avalonia.Platform.Storage; +using System.Collections.Generic; +using Avalonia.Platform.Storage; + +namespace Avalonia.Platform.Storage; /// /// Common options for , and methods. @@ -16,4 +19,9 @@ public class PickerOptions /// or . /// public IStorageFolder? SuggestedStartLocation { get; set; } + + /// + /// Gets or sets the file name that the file picker suggests to the user. + /// + public string? SuggestedFileName { get; set; } } diff --git a/src/Avalonia.Native/SystemDialogs.cs b/src/Avalonia.Native/SystemDialogs.cs index 9106644dc0..76bf2d3bfa 100644 --- a/src/Avalonia.Native/SystemDialogs.cs +++ b/src/Avalonia.Native/SystemDialogs.cs @@ -41,7 +41,7 @@ namespace Avalonia.Native options.AllowMultiple.AsComBool(), options.Title ?? string.Empty, suggestedDirectory, - string.Empty, + options.SuggestedFileName ?? string.Empty, fileTypes); var result = await events.Task.ConfigureAwait(false); diff --git a/src/Windows/Avalonia.Win32/Win32StorageProvider.cs b/src/Windows/Avalonia.Win32/Win32StorageProvider.cs index 56ba96fcf6..11ae0d6c0c 100644 --- a/src/Windows/Avalonia.Win32/Win32StorageProvider.cs +++ b/src/Windows/Avalonia.Win32/Win32StorageProvider.cs @@ -39,7 +39,7 @@ namespace Avalonia.Win32 return await ShowFilePicker( true, true, options.AllowMultiple, false, - options.Title, null, options.SuggestedStartLocation, null, null, + options.Title, options.SuggestedFileName, options.SuggestedStartLocation, null, null, f => new BclStorageFolder(new DirectoryInfo(f))) .ConfigureAwait(false); } @@ -49,7 +49,7 @@ namespace Avalonia.Win32 return await ShowFilePicker( true, false, options.AllowMultiple, false, - options.Title, null, options.SuggestedStartLocation, + options.Title, options.SuggestedFileName, options.SuggestedStartLocation, null, options.FileTypeFilter, f => new BclStorageFile(new FileInfo(f))) .ConfigureAwait(false);