Browse Source

set filename for both open file and open folder dialogs (#14308)

pull/14329/head
Emmanuel Hansen 2 years ago
committed by GitHub
parent
commit
ac91b14caf
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      samples/ControlCatalog/Pages/DialogsPage.xaml.cs
  2. 5
      src/Avalonia.Base/Platform/Storage/FilePickerSaveOptions.cs
  3. 10
      src/Avalonia.Base/Platform/Storage/PickerOptions.cs
  4. 2
      src/Avalonia.Native/SystemDialogs.cs
  5. 4
      src/Windows/Avalonia.Win32/Win32StorageProvider.cs

2
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
});

5
src/Avalonia.Base/Platform/Storage/FilePickerSaveOptions.cs

@ -7,11 +7,6 @@ namespace Avalonia.Platform.Storage;
/// </summary>
public class FilePickerSaveOptions : PickerOptions
{
/// <summary>
/// Gets or sets the file name that the file save picker suggests to the user.
/// </summary>
public string? SuggestedFileName { get; set; }
/// <summary>
/// Gets or sets the default extension to be used to save the file.
/// </summary>

10
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;
/// <summary>
/// Common options for <see cref="IStorageProvider.OpenFolderPickerAsync"/>, <see cref="IStorageProvider.OpenFilePickerAsync"/> and <see cref="IStorageProvider.SaveFilePickerAsync"/> methods.
@ -16,4 +19,9 @@ public class PickerOptions
/// or <see cref="IStorageProvider.TryGetWellKnownFolderAsync"/>.
/// </summary>
public IStorageFolder? SuggestedStartLocation { get; set; }
/// <summary>
/// Gets or sets the file name that the file picker suggests to the user.
/// </summary>
public string? SuggestedFileName { get; set; }
}

2
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);

4
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);

Loading…
Cancel
Save