Windows native file dialog: Work around display bug of IFileDialog.

Any filter not filtering on suffix shows up duplicated in filter
combo.

Change-Id: I9fc9e33b6081cf6894fabc6dd52c12a4d3dfd393
Task-number: QTBUG-42405
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
This commit is contained in:
Friedemann Kleint 2014-11-05 14:57:03 +01:00
parent 7a8bb824ff
commit 76735f3fa0

View File

@ -1224,16 +1224,21 @@ void QWindowsNativeFileDialogBase::setNameFilters(const QStringList &filters)
QScopedArrayPointer<WCHAR> buffer(new WCHAR[totalStringLength + 2 * size]); QScopedArrayPointer<WCHAR> buffer(new WCHAR[totalStringLength + 2 * size]);
QScopedArrayPointer<COMDLG_FILTERSPEC> comFilterSpec(new COMDLG_FILTERSPEC[size]); QScopedArrayPointer<COMDLG_FILTERSPEC> comFilterSpec(new COMDLG_FILTERSPEC[size]);
const QString matchesAll = QStringLiteral(" (*)");
WCHAR *ptr = buffer.data(); WCHAR *ptr = buffer.data();
// Split filter specification as 'Texts (*.txt[;] *.doc)' // Split filter specification as 'Texts (*.txt[;] *.doc)'
// into description and filters specification as '*.txt;*.doc' // into description and filters specification as '*.txt;*.doc'
for (int i = 0; i < size; ++i) { for (int i = 0; i < size; ++i) {
// Display glitch (CLSID only): 'All files (*)' shows up as 'All files (*) (*)' // Display glitch (CLSID only): Any filter not filtering on suffix (such as
// '*', 'a.*') will be duplicated in combo: 'All files (*) (*)',
// 'AAA files (a.*) (a.*)'
QString description = specs[i].description; QString description = specs[i].description;
if (!m_hideFiltersDetails && description.endsWith(matchesAll)) const QString &filter = specs[i].filter;
description.truncate(description.size() - matchesAll.size()); if (!m_hideFiltersDetails && !filter.startsWith(QLatin1String("*."))) {
const int pos = description.lastIndexOf(QLatin1Char('('));
if (pos > 0)
description.truncate(pos);
}
// Add to buffer. // Add to buffer.
comFilterSpec[i].pszName = ptr; comFilterSpec[i].pszName = ptr;
ptr += description.toWCharArray(ptr); ptr += description.toWCharArray(ptr);