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

Add more features to the patterns arg for file dialogs. #1567

Merged
merged 2 commits into from
Jun 23, 2024

Conversation

SiegeLord
Copy link
Member

@SiegeLord SiegeLord commented Jun 19, 2024

Here's the new docstring for it:

patterns: A string containing newline separated sets of patterns to match.
A pattern is either a shell-style glob pattern (e.g. "*.txt") or a MIME
type (e.g. "image/png"). Not all platforms support both (and some don't
even support globs), so a portable solution is to specify a MIME type and
simple style globs which Allegro will pick from to match what the platform
supports (e.g. do "image/png;*.png"). Multiple patterns are separated
using a semicolon. If the platform does not provide support for patterns,
this parameter is ignored. Here are some example patterns:

  • "*.txt" -- defines a single filter, matching *.txt files.
  • "*.txt;*.md" -- like above, but matching two types of files.
  • "Text files (*.txt, *.md) *.txt;*.md" -- like above, but with a custom
    description (separated from the patterns using a space).
  • "Text files *.txt\nPNG images image/png;*.png" -- defines two filters,
    with the second filter using a MIME type and extension at the same time.

Note: Windows does not support MIME types. Android supports only MIME
types. Instead of file patterns, MacOS supports extensions, so matching
based on filename beyond file type does not work. Allegro will parse your
file pattern to try to extract the file extension. MacOS also supports
MIME types, which behave more predictably. MacOS does not support detailed
descriptions or multiple pattern sets, Allegro will strip the detailed
descriptions and concatenate all patterns into one list.

description (separated from the patterns using a space).
- `"Text files *.txt\nPNG images image/png"` -- defines two filters, with
the second filter using a MIME type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add an example of what an explicit catchall looks like? It's just * right? (since *.* would exclude extensionless files)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

. on windows doesn't actually exclude them, but I made it so * is the cross-platform way to access it.

@connorjclark
Copy link
Contributor

I think this is a great backwards compatible way to extend this - nice!

only thing I wanna note is this disallows / from the description component of the filter. Maybe consider adding a way to escape a /?

@SiegeLord SiegeLord force-pushed the better_file_dialog_patterns branch 2 times, most recently from 980fa7f to 94c85dd Compare June 22, 2024 21:30
@SiegeLord SiegeLord marked this pull request as ready for review June 22, 2024 21:33
This adds:

- Support for multiple pattern sets (Windows/Linux)
- Supports for custom pattern set descriptions (Windows/Linux)
- Support for MIME types on MacOS

Also:

- Remove the implicit catch-all pattern on Windows (the "All files
  *.*"), it was inconsistent with other platforms.
- Make MacOS do a better job at extracting the file extension
- Improve documentation overall
@SiegeLord SiegeLord force-pushed the better_file_dialog_patterns branch from 94c85dd to ce05752 Compare June 23, 2024 20:30
@SiegeLord SiegeLord merged commit 3aba4b8 into liballeg:master Jun 23, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants