Fix QFileDialog::defaultSuffix on macOS
Don't prepend the default suffix to the NSSavePanel allowedFileTypes. "If no extension is given by the user, the first item in the allowedFileTypes array will be used as the extension for the save panel." The user expects to get the suffix displayed to them in the drop down filter, not the default suffix set by the developer. Apply the default suffix if neither the user or the NSSavePanel provide a suffix. Task-number: QTBUG-66066 Change-Id: I64093b9f3178bd2377a7b65d6f23aed6214a4119 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>bb10
parent
4cd90a3579
commit
9b29133778
|
|
@ -418,6 +418,13 @@ static QString strippedText(QString s)
|
|||
} else {
|
||||
QList<QUrl> result;
|
||||
QString filename = QString::fromNSString([[mSavePanel URL] path]).normalized(QString::NormalizationForm_C);
|
||||
const QString defaultSuffix = mOptions->defaultSuffix();
|
||||
const QFileInfo fileInfo(filename);
|
||||
// If neither the user or the NSSavePanel have provided a suffix, use
|
||||
// the default suffix (if it exists).
|
||||
if (fileInfo.suffix().isEmpty() && !defaultSuffix.isEmpty()) {
|
||||
filename.append('.').append(defaultSuffix);
|
||||
}
|
||||
result << QUrl::fromLocalFile(filename.remove(QLatin1String("___qt_very_unlikely_prefix_")));
|
||||
return result;
|
||||
}
|
||||
|
|
@ -445,10 +452,7 @@ static QString strippedText(QString s)
|
|||
[mPopUpButton setHidden:chooseDirsOnly]; // TODO hide the whole sunken pane instead?
|
||||
|
||||
if (mOptions->acceptMode() == QFileDialogOptions::AcceptSave) {
|
||||
QStringList ext = [self acceptableExtensionsForSave];
|
||||
const QString defaultSuffix = mOptions->defaultSuffix();
|
||||
if (!ext.isEmpty() && !defaultSuffix.isEmpty())
|
||||
ext.prepend(defaultSuffix);
|
||||
const QStringList ext = [self acceptableExtensionsForSave];
|
||||
[mSavePanel setAllowedFileTypes:ext.isEmpty() ? nil : qt_mac_QStringListToNSMutableArray(ext)];
|
||||
} else {
|
||||
[mOpenPanel setAllowedFileTypes:nil]; // delegate panel:shouldEnableURL: does the file filtering for NSOpenPanel
|
||||
|
|
|
|||
Loading…
Reference in New Issue