Skip to content

macos: Add save-dialog format picker for named filters - #328

Merged
PolyMeilex merged 3 commits into
PolyMeilex:masterfrom
davideme:claude/musing-euclid-da2915
Jul 17, 2026
Merged

macos: Add save-dialog format picker for named filters#328
PolyMeilex merged 3 commits into
PolyMeilex:masterfrom
davideme:claude/musing-euclid-da2915

Conversation

@davideme

@davideme davideme commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

NSSavePanel previously merged every filter registered via add_filter into one
flat, unnamed allowed-types list (via the deprecated setAllowedFileTypes), unlike
Windows and Linux, which already show filter names to the user. This PR adds a
"Format:" picker to the macOS save dialog, matching the native convention used by
apps like TextEdit/Safari.

  • When two or more filters are registered, save_file now shows a "Format:"
    accessory view (an NSPopUpButton) listing each filter's name. Selecting one
    live-updates the panel's allowed content types (and the auto-appended extension)
    via the modern allowedContentTypes API.
  • When zero or one filter is registered, behavior is unchanged — no picker is
    shown, since there's nothing to choose between.
  • Added FileDialog::set_format_label/AsyncFileDialog::set_format_label so
    callers can customize the picker's label (defaults to "Format:").
  • Updated the add_filter/save_file doc comments to describe the new
    macOS behavior.
Screenshot 2026-07-06 at 15 27 05

Test plan

  • cargo build/cargo check clean on macOS
  • Manually verified via examples/save.rs with two filters registered:
    • Format picker renders correctly, centered, with proper padding
    • Selecting a filter live-switches the allowed content type and the
      auto-appended extension (.txt.rtf)
    • Custom label via set_format_label renders correctly at various lengths
    • 0-filter and 1-filter cases regression-tested — no picker shown, unchanged
      behavior
    • Existing open-picker (pick_file/pick_files) filtering unaffected

davideme added 3 commits July 6, 2026 14:57
NSSavePanel previously merged every registered filter into one flat,
unnamed allowed-types list (via the deprecated setAllowedFileTypes),
unlike Windows/Linux which already show filter names. When two or
more filters are registered, save_file now shows a "Format:" accessory
view (label configurable via set_format_label) that switches the
panel's allowed content types live via the modern allowedContentTypes
API. Open-panel filtering was also modernized off the deprecated API
as part of the same cleanup.
add_filters is only used by the open-panel builders, which are
unrelated to the save-dialog format-picker feature added in aee3582.
Restore its original deprecated setAllowedFileTypes implementation to
keep this branch scoped to the save dialog; behavior is unchanged
either way (filters are still merged into one flat list).
The previous phrasing nested "0 or 1 filters registered" inside a
"don't support filter names" parenthetical, which read awkwardly and
implied the 0-filter case was somehow about unsupported names rather
than there being nothing to name.
@davideme

Copy link
Copy Markdown
Contributor Author

Hi @PolyMeilex I'm happy to close this PR, if you don't feel it match the purpose or the intent of this repo.

@PolyMeilex
PolyMeilex merged commit 32e2dd4 into PolyMeilex:master Jul 17, 2026
13 of 14 checks passed
@PolyMeilex

Copy link
Copy Markdown
Owner

Thanks

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.

2 participants