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

Missing FileDialog filter options #2949

Closed
b2soft opened this issue Sep 9, 2019 · 15 comments
Closed

Missing FileDialog filter options #2949

b2soft opened this issue Sep 9, 2019 · 15 comments

Comments

@b2soft
Copy link

b2soft commented Sep 9, 2019

There are only 2 options that can be used in filters for FileDialog - InitialFileName and Extensions

In WPF I can specify filter to choose only files named as "Name.exe" in this way:

OpenFileDialog dlg = new OpenFileDialog();

dlg.Filter = "Name.exe|Name.exe";

if (dlg.ShowDialog() == true)
{
...
}

Requesting to add missing FileDialog's filter options (based on WPF) to Avalonia

@grokys
Copy link
Member

grokys commented Sep 9, 2019

@kekekeks @danwalmsley can this reasonably be implemented on all our dialog backends?

@kekekeks
Copy link
Member

kekekeks commented Sep 9, 2019

OSX file dialogs don't use glob patterns and need a list of accepted file extensions or UTIs

@b2soft
Copy link
Author

b2soft commented Sep 9, 2019

Is there any workaround to such a problem?

@kekekeks
Copy link
Member

kekekeks commented Sep 9, 2019

On OSX? No, I don't think we can restrict the system file dialog to use a fixed name.

@b2soft
Copy link
Author

b2soft commented Sep 9, 2019

I'm targeting only Win and Linux, so OSX is not the case. What will be the best solution to have a strict filename inside file dialog (and not swtiching to WPF instead of avalonia)?

@Toemsel
Copy link

Toemsel commented May 3, 2021

            var fileExtensions = new List<string>() { $"dump|*.{fileExtension};" };
            var extensionFilter = new FileDialogFilter() { Extensions = fileExtensions };

            var dialog = new OpenFileDialog();
            dialog.AllowMultiple = false;
            dialog.Filters.Add(extensionFilter);
            await dialog.ShowAsync(DjiWindow.Instance);

Will throw an ArgumentException, as a filter has been defined. Without the filter it works just fine.

@chyyran
Copy link

chyyran commented Jun 21, 2022

Copy-pasting dialog implementations and altering them to fit your needs, I guess.

https://github.com/AvaloniaUI/Avalonia/blob/master/src/Windows/Avalonia.Win32/SystemDialogImpl.cs

https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.X11/NativeDialogs/GtkNativeFileDialogs.cs

This is untenable because many of the internal APIs used are protected and inaccessible, and we end up needing to vendor a large chunk of Avalonia, not to mention requiring unsafe in the project just for fixed name filters.

A proper solution is needed on Windows and GTK for this. The alternative here is to drop down to WPF just for an OpenFileDialog that supports fixed name filters.

Edit: It seems like <UseWPF> is not necessary as long as the project targets `.netX.0-windows'. Doing so bloats the file size of a single file deployment though.

@maxkatz6
Copy link
Member

Filter as it is in WPF won't be supported in Avalonia.
Instead, special FilePickerFileType will be used (as opposite of what's currently available):

class FilePickerFileType
{
    string Title { get; init; }
    // For desktop
    IReadOnlyList<string> Extensions {get; init; }
    // For web and android
    IReadOnlyList<string> MimeTypes {get; init; }
    // For Apple platforms
    IReadOnlyList<string> AppleUniformTypeIdentifiers {get; init; }
}

For more details see #7234 and #8303

@maxkatz6 maxkatz6 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 21, 2022
@chyyran
Copy link

chyyran commented Jun 21, 2022

Will FilePickerFileType allow a fixed filename on supported platforms? There is already a specialization for Apple platforms for UTIs, so I don't see why this functionality would be left out when targeting only platforms where fixed filename filters are supported.

@maxkatz6
Copy link
Member

You can set suggested file name and a type extension. Not much flexibility here with non-windows platforms.

@chyyran
Copy link

chyyran commented Jun 21, 2022

In addition to Windows, GTK also allows glob-style filters. It is only macOS and mobile/web platforms that do not support this.

There is already a specialization for Apple platforms with UTIs that are only relevant on macOS. It would not be difficult to add a property to support fixed filename filters on platforms that support it, which does not just include Windows.

@chyyran
Copy link

chyyran commented Jun 21, 2022

To be clear here I am not asking for full support of WPF style globs. Simply allowing the file picker to filter on a fixed name will already go a long way, and is well supported on both Windows and GTK.

@maxkatz6
Copy link
Member

Well, I suppose glob pattern support won't be a problem as part of new API.

@chyyran
Copy link

chyyran commented Jun 21, 2022

If full support for globs made it in that would be great as well but just having support for fixed file names would already cover 95% of use cases when including the existing extension based filter.

The only thing is if extensions are only relevant for non-macOS desktop environments, then all such environments already support globs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants