-
Notifications
You must be signed in to change notification settings - Fork 568
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
macOS: Support choosing file formats in the file dialog. #998
Comments
Some light research suggests that the popup menu must be created manually, supplied to the save panel as an |
It's definitely possible via an accessory view, but the reason I'm thinking it might be possible in another way is the wording of the Human Interface Guidelines. At the end of that page the accessory view extending and the format pop-up are described separately. Of course this might also be a another Catalina thing, where previously the pop-up showed up without an accessory view but that's no longer the case in Catalina. Would need someone with an older macOS to comment on that. |
I started working on this and have a implementation that fulfills the requirement: There is a way to get this behaviour for free, but only if the application uses While I have the UI working, I have trouble returning the proper result. On macOS, such a dialog results in two pieces of data:
However, the /// Information about the path to be opened or saved.
///
/// This path might point to a file or a directory.
#[derive(Debug, Clone)]
pub struct FileInfo {
pub(crate) path: PathBuf,
} So how do I coalesce these two data into one. My initial approach was to take the path and replace the extension with the chosen extension from the file format. However, this omits crucial data. There might be situations where the file ending is the same, but the file data is different depending on the output format. E.g. I'm generating HTML and the output formats are "HTML with Javascript" and "HTML without Javascript". Or Blender files they're always So the other option would be to expand FileInfo: pub struct FileInfo {
pub(crate) path: PathBuf,
pub(crate) format: FileSpec
} But this would be breaking and surely affect the other platforms. I didn't look into it yet but I'd just imagine that the file choosers on other platforms don't let you access the chosen format after the fact. So I'd just go with the rewritten output I'll post a link to the interim branch once I'm done cleaning it up. |
I'm okay with modifying What would be most important is documenting this. I think that we should try to provide as much information as possible in |
I've updated the branch accordingly and tried to add documentation. |
When a user is saving a file they should be able to choose from among the supported file formats.
The Windows and GTK implementations already support this and other apps on macOS support this.
According to Apple's Human Interface Guidelines this should be possible even without a custom extension.
It's unclear how these output formats can be specified.
NSSavePanel
only seems to haveallowedFileTypes
which we are using already. However the way we are using them is just an array of strings, so we couldn't even specify the format name like Rich Text Document.The
allowedFileTypes
also seems to support UTIs. Would we get the format selection if we defined UTIs? Are there other ways to get the format selection?The text was updated successfully, but these errors were encountered: