macOS: Explicitly show extensions in save dialog if filter is "all files"

Otherwise clicking an existing file in the dialog will not populate the
full file name, which is what you'd expect for a filter allowing all
files.

Change-Id: Ib9a014352d5e567e54f95414e744566615d735d8
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
(cherry picked from commit c53955eaa085b14ef8e5348e951f8cd2cbfa4ea5)
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Tor Arne Vestbø 2024-01-05 16:21:22 +01:00
parent c44caa1eaa
commit c7bfee363e

View File

@ -85,21 +85,29 @@ typedef QSharedPointer<QFileDialogOptions> SharedPointerFileDialogOptions;
QString selectedVisualNameFilter = m_options->initiallySelectedNameFilter();
m_selectedNameFilter = [self findStrippedFilterWithVisualFilterName:selectedVisualNameFilter];
// Explicitly show extensions if we detect a filter
// that has a multi-part extension. This prevents
// confusing situations where the user clicks e.g.
// 'foo.tar.gz' and 'foo.tar' is populated in the
// file name box, but when then clicking save macOS
// will warn that the file needs to end in .gz,
// due to thinking the user tried to save the file
// as a 'tar' file instead. Unfortunately this
// property can only be set before the panel is
// shown, so we can't toggle it on and off based
// on the active filter.
m_panel.extensionHidden = [&]{
for (const auto &nameFilter : m_nameFilterDropDownList) {
const auto extensions = QPlatformFileDialogHelper::cleanFilterList(nameFilter);
for (const auto &extension : extensions) {
// Explicitly show extensions if we detect a filter
// of "all files", as clicking a single file with
// extensions hidden will then populate the name
// field with only the file name, without any
// extension.
if (extension == "*"_L1 || extension == "*.*"_L1)
return false;
// Explicitly show extensions if we detect a filter
// that has a multi-part extension. This prevents
// confusing situations where the user clicks e.g.
// 'foo.tar.gz' and 'foo.tar' is populated in the
// file name box, but when then clicking save macOS
// will warn that the file needs to end in .gz,
// due to thinking the user tried to save the file
// as a 'tar' file instead. Unfortunately this
// property can only be set before the panel is
// shown, so we can't toggle it on and off based
// on the active filter.
if (extension.count('.') > 1)
return false;
}