From bf55c0ac3b9c4ab8ab900ebdf2347faa1f17e12b Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 4 Oct 2012 11:36:11 +0200 Subject: Windows: Append file suffix in save-dialog. Task-number: QTBUG-27186 Change-Id: I04304fce1cbf6fb6794f352ff896eb463699d42b Reviewed-by: Miikka Heikkinen --- .../platforms/windows/qwindowsdialoghelpers.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp index 8b053a5ee4..34c8d69668 100644 --- a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp +++ b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp @@ -1025,6 +1025,26 @@ public: virtual QStringList selectedFiles() const; }; +// Append a suffix from the name filter "Foo files (*.foo;*.bar)" +// unless the file name already has one. +static inline QString appendSuffix(const QString &fileName, const QString &filter) +{ + const int lastDot = fileName.lastIndexOf(QLatin1Char('.')); + const int lastSlash = fileName.lastIndexOf(QLatin1Char('/')); + if (lastDot >= 0 && (lastSlash == -1 || lastDot > lastSlash)) + return fileName; + int suffixPos = filter.indexOf(QLatin1String("(*.")); + if (suffixPos < 0) + return fileName; + suffixPos += 3; + int endPos = filter.indexOf(QLatin1Char(';'), suffixPos + 1); + if (endPos < 0) + endPos = filter.indexOf(QLatin1Char(')'), suffixPos + 1); + if (endPos < 0) + return fileName; + return fileName + QLatin1Char('.') + filter.mid(suffixPos, endPos - suffixPos); +} + QPlatformDialogHelper::DialogCode QWindowsNativeSaveFileDialog::fileResult(QStringList *result /* = 0 */) const { if (result) @@ -1034,7 +1054,7 @@ QPlatformDialogHelper::DialogCode QWindowsNativeSaveFileDialog::fileResult(QStri if (FAILED(hr) || !item) return QPlatformDialogHelper::Rejected; if (result) - result->push_back(QWindowsNativeFileDialogBase::itemPath(item)); + result->push_back(appendSuffix(QWindowsNativeFileDialogBase::itemPath(item), selectedNameFilter())); return QPlatformDialogHelper::Accepted; } -- cgit v1.2.3