summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-03-04 09:54:35 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2020-03-04 19:10:37 +0000
commita0ffdf765e34820b591bcb9d1bee6df0985056cf (patch)
tree2328cacb6547e7de3535a968d234aa84942b445f /src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
parentd57adfe5f375121c3e233465526ee5d9df03e1e9 (diff)
parent2a4b95778993b00499eb94f61a87330fdbadf947 (diff)
Merge "Merge remote-tracking branch 'origin/5.15' into dev"
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm')
-rw-r--r--src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm61
1 files changed, 42 insertions, 19 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
index 6aa21d78d1..8b76e45616 100644
--- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
+++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
@@ -419,8 +419,7 @@ static QString strippedText(QString s)
[mPopUpButton setHidden:chooseDirsOnly]; // TODO hide the whole sunken pane instead?
if (mOptions->acceptMode() == QFileDialogOptions::AcceptSave) {
- const QStringList ext = [self acceptableExtensionsForSave];
- [mSavePanel setAllowedFileTypes:ext.isEmpty() ? nil : qt_mac_QStringListToNSMutableArray(ext)];
+ [self recomputeAcceptableExtensionsForSave];
} else {
[mOpenPanel setAllowedFileTypes:nil]; // delegate panel:shouldEnableURL: does the file filtering for NSOpenPanel
}
@@ -457,25 +456,49 @@ static QString strippedText(QString s)
}
/*
- Returns a list of extensions (e.g. "png", "jpg", "gif")
- for the current name filter. If a filter do not conform
- to the format *.xyz or * or *.*, an empty list
- is returned meaning accept everything.
+ Computes a list of extensions (e.g. "png", "jpg", "gif")
+ for the current name filter, and updates the save panel.
+
+ If a filter do not conform to the format *.xyz or * or *.*,
+ all files types are allowed.
+
+ Extensions with more than one part (e.g. "tar.gz") are
+ reduced to their final part, as NSSavePanel does not deal
+ well with multi-part extensions.
*/
-- (QStringList)acceptableExtensionsForSave
-{
- QStringList result;
- for (int i=0; i<mSelectedNameFilter->count(); ++i) {
- const QString &filter = mSelectedNameFilter->at(i);
- if (filter.startsWith(QLatin1String("*."))
- && !filter.contains(QLatin1Char('?'))
- && filter.count(QLatin1Char('*')) == 1) {
- result += filter.mid(2);
- } else {
- return QStringList(); // Accept everything
- }
+- (void)recomputeAcceptableExtensionsForSave
+{
+ QStringList fileTypes;
+ for (const QString &filter : *mSelectedNameFilter) {
+ if (!filter.startsWith(QLatin1String("*.")))
+ continue;
+
+ if (filter.contains(QLatin1Char('?')))
+ continue;
+
+ if (filter.count(QLatin1Char('*')) != 1)
+ continue;
+
+ auto extensions = filter.split('.', Qt::SkipEmptyParts);
+ fileTypes += extensions.last();
+
+ // 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 it will not have any effect when
+ // swithcing filters in an already opened dialog.
+ if (extensions.size() > 2)
+ mSavePanel.extensionHidden = NO;
}
- return result;
+
+ mSavePanel.allowedFileTypes = fileTypes.isEmpty() ? nil
+ : qt_mac_QStringListToNSMutableArray(fileTypes);
}
- (QString)removeExtensions:(const QString &)filter