Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set suggested file name for both open file and open folder dialogs #14308

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions samples/ControlCatalog/Pages/DialogsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ List<FileDialogFilter> GetFilters()
{
Title = "Open file",
FileTypeFilter = GetFileTypes(),
SuggestedFileName = "FileName",
SuggestedStartLocation = lastSelectedDirectory,
AllowMultiple = openMultiple.IsChecked == true
});
Expand Down Expand Up @@ -264,6 +265,7 @@ List<FileDialogFilter> GetFilters()
{
Title = "Folder file",
SuggestedStartLocation = lastSelectedDirectory,
SuggestedFileName = "FileName",
AllowMultiple = openMultiple.IsChecked == true
});

Expand Down
5 changes: 0 additions & 5 deletions src/Avalonia.Base/Platform/Storage/FilePickerSaveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
10 changes: 9 additions & 1 deletion src/Avalonia.Base/Platform/Storage/PickerOptions.cs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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 changes: 1 addition & 1 deletion src/Avalonia.Native/SystemDialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override async Task<IReadOnlyList<IStorageFile>> OpenFilePickerAsync(File
options.AllowMultiple.AsComBool(),
options.Title ?? string.Empty,
suggestedDirectory,
string.Empty,
options.SuggestedFileName ?? string.Empty,
fileTypes);

var result = await events.Task.ConfigureAwait(false);
Expand Down
4 changes: 2 additions & 2 deletions src/Windows/Avalonia.Win32/Win32StorageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override async Task<IReadOnlyList<IStorageFolder>> OpenFolderPickerAsync(
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);
}
Expand All @@ -49,7 +49,7 @@ public override async Task<IReadOnlyList<IStorageFile>> OpenFilePickerAsync(File
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);
Expand Down