From c53955eaa085b14ef8e5348e951f8cd2cbfa4ea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 5 Jan 2024 16:21:22 +0100 Subject: [PATCH] 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. Pick-to: 6.7 Change-Id: Ib9a014352d5e567e54f95414e744566615d735d8 Reviewed-by: Timur Pocheptsov --- .../platforms/cocoa/qcocoafiledialoghelper.mm | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm index cd92c59a5e..96bf46f45a 100644 --- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm @@ -83,21 +83,29 @@ typedef QSharedPointer 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; }