Browse Source

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

pull/14329/head
Emmanuel Hansen 3 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", Title = "Open file",
FileTypeFilter = GetFileTypes(), FileTypeFilter = GetFileTypes(),
SuggestedFileName = "FileName",
SuggestedStartLocation = lastSelectedDirectory, SuggestedStartLocation = lastSelectedDirectory,
AllowMultiple = openMultiple.IsChecked == true AllowMultiple = openMultiple.IsChecked == true
}); });
@ -264,6 +265,7 @@ namespace ControlCatalog.Pages
{ {
Title = "Folder file", Title = "Folder file",
SuggestedStartLocation = lastSelectedDirectory, SuggestedStartLocation = lastSelectedDirectory,
SuggestedFileName = "FileName",
AllowMultiple = openMultiple.IsChecked == true AllowMultiple = openMultiple.IsChecked == true
}); });

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

@ -7,11 +7,6 @@ namespace Avalonia.Platform.Storage;
/// </summary> /// </summary>
public class FilePickerSaveOptions : PickerOptions 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> /// <summary>
/// Gets or sets the default extension to be used to save the file. /// Gets or sets the default extension to be used to save the file.
/// </summary> /// </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> /// <summary>
/// Common options for <see cref="IStorageProvider.OpenFolderPickerAsync"/>, <see cref="IStorageProvider.OpenFilePickerAsync"/> and <see cref="IStorageProvider.SaveFilePickerAsync"/> methods. /// 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"/>. /// or <see cref="IStorageProvider.TryGetWellKnownFolderAsync"/>.
/// </summary> /// </summary>
public IStorageFolder? SuggestedStartLocation { get; set; } 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.AllowMultiple.AsComBool(),
options.Title ?? string.Empty, options.Title ?? string.Empty,
suggestedDirectory, suggestedDirectory,
string.Empty, options.SuggestedFileName ?? string.Empty,
fileTypes); fileTypes);
var result = await events.Task.ConfigureAwait(false); var result = await events.Task.ConfigureAwait(false);

4
src/Windows/Avalonia.Win32/Win32StorageProvider.cs

@ -39,7 +39,7 @@ namespace Avalonia.Win32
return await ShowFilePicker( return await ShowFilePicker(
true, true, true, true,
options.AllowMultiple, false, options.AllowMultiple, false,
options.Title, null, options.SuggestedStartLocation, null, null, options.Title, options.SuggestedFileName, options.SuggestedStartLocation, null, null,
f => new BclStorageFolder(new DirectoryInfo(f))) f => new BclStorageFolder(new DirectoryInfo(f)))
.ConfigureAwait(false); .ConfigureAwait(false);
} }
@ -49,7 +49,7 @@ namespace Avalonia.Win32
return await ShowFilePicker( return await ShowFilePicker(
true, false, true, false,
options.AllowMultiple, false, options.AllowMultiple, false,
options.Title, null, options.SuggestedStartLocation, options.Title, options.SuggestedFileName, options.SuggestedStartLocation,
null, options.FileTypeFilter, null, options.FileTypeFilter,
f => new BclStorageFile(new FileInfo(f))) f => new BclStorageFile(new FileInfo(f)))
.ConfigureAwait(false); .ConfigureAwait(false);

Loading…
Cancel
Save