diff options
author | Richard Moe Gustavsen <richard.gustavsen@nokia.com> | 2010-08-20 08:06:04 (GMT) |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@nokia.com> | 2010-08-20 08:20:46 (GMT) |
commit | 0e4a9ab0f60faff3bde86cb7f08250161c18103e (patch) | |
tree | 8f376e58f2294782a93f1b180e039fd79e79a344 /src/gui/dialogs | |
parent | 33419b3f6238f8f707afb9ba27b96a408e70137a (diff) | |
download | Qt-0e4a9ab0f60faff3bde86cb7f08250161c18103e.zip Qt-0e4a9ab0f60faff3bde86cb7f08250161c18103e.tar.gz Qt-0e4a9ab0f60faff3bde86cb7f08250161c18103e.tar.bz2 |
QFileDialog::HideNameFilterDetails breaks Cocoa QFileDIalog filter
Using namefilters in the non-native file dialog is a bit broken by
design, since it don't store the whole selected name filter, but
only the filter with details stripped off (if this is specified). And
it stores this data in gui widgets. And the native file dialog also
suffers from this. At least this patch will pick the first matching
name filter (with details) given a details-stripped version.
Task-number: QTBUG-12870
Reviewed-by: cduclos
Diffstat (limited to 'src/gui/dialogs')
-rw-r--r-- | src/gui/dialogs/qfiledialog_mac.mm | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/gui/dialogs/qfiledialog_mac.mm b/src/gui/dialogs/qfiledialog_mac.mm index 64fc0ee..87850a7 100644 --- a/src/gui/dialogs/qfiledialog_mac.mm +++ b/src/gui/dialogs/qfiledialog_mac.mm @@ -119,6 +119,7 @@ QT_USE_NAMESPACE - (QString)removeExtensions:(const QString &)filter; - (void)createTextField; - (void)createPopUpButton:(const QString &)selectedFilter hideDetails:(BOOL)hideDetails; +- (QStringList)findStrippedFilterWithVisualFilterName:(QString)name; - (void)createAccessory; @end @@ -127,8 +128,6 @@ QT_USE_NAMESPACE - (id)initWithAcceptMode:(QT_PREPEND_NAMESPACE(QFileDialog::AcceptMode))acceptMode title:(const QString &)title - nameFilters:(const QStringList &)nameFilters - selectedNameFilter:(const QString &)selectedNameFilter hideNameFilterDetails:(bool)hideNameFilterDetails qDirFilter:(QT_PREPEND_NAMESPACE(QDir::Filters))qDirFilter fileOptions:(QT_PREPEND_NAMESPACE(QFileDialog::Options))fileOptions @@ -158,8 +157,10 @@ QT_USE_NAMESPACE mPriv = priv; mLastFilterCheckPath = new QString; mQDirFilterEntryList = new QStringList; - mNameFilterDropDownList = new QStringList(nameFilters); - mSelectedNameFilter = new QStringList(qt_clean_filter_list(selectedNameFilter)); + mNameFilterDropDownList = new QStringList(priv->nameFilters); + QString selectedVisualNameFilter = priv->qFileDialogUi->fileTypeCombo->currentText(); + mSelectedNameFilter = new QStringList([self findStrippedFilterWithVisualFilterName:selectedVisualNameFilter]); + QFileInfo sel(selectFile); if (sel.isDir()){ mCurrentDir = [qt_mac_QStringToNSString(sel.absoluteFilePath()) retain]; @@ -168,8 +169,9 @@ QT_USE_NAMESPACE mCurrentDir = [qt_mac_QStringToNSString(sel.absolutePath()) retain]; mCurrentSelection = new QString(sel.absoluteFilePath()); } + [mSavePanel setTitle:qt_mac_QStringToNSString(title)]; - [self createPopUpButton:selectedNameFilter hideDetails:hideNameFilterDetails]; + [self createPopUpButton:selectedVisualNameFilter hideDetails:hideNameFilterDetails]; [self createTextField]; [self createAccessory]; [mSavePanel setAccessoryView:mNameFilterDropDownList->size() > 1 ? mAccessoryView : nil]; @@ -350,7 +352,7 @@ QT_USE_NAMESPACE // This mDelegate function is called when the _name_ filter changes. Q_UNUSED(sender); QString selection = mNameFilterDropDownList->value([mPopUpButton indexOfSelectedItem]); - *mSelectedNameFilter = QT_PREPEND_NAMESPACE(qt_clean_filter_list)(selection); + *mSelectedNameFilter = [self findStrippedFilterWithVisualFilterName:selection]; [mSavePanel validateVisibleColumns]; [self updateProperties]; if (mPriv) @@ -499,6 +501,15 @@ QT_USE_NAMESPACE } } +- (QStringList) findStrippedFilterWithVisualFilterName:(QString)name +{ + for (int i=0; i<mNameFilterDropDownList->size(); ++i) { + if (mNameFilterDropDownList->at(i).startsWith(name)) + return qt_clean_filter_list(mNameFilterDropDownList->at(i)); + } + return QStringList(); +} + - (void)createAccessory { NSRect accessoryRect = { { 0.0, 0.0 }, { 450.0, 33.0 } }; @@ -1039,8 +1050,6 @@ void QFileDialogPrivate::createNSOpenSavePanelDelegate() QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *delegate = [[QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) alloc] initWithAcceptMode:acceptMode title:q->windowTitle() - nameFilters:q->nameFilters() - selectedNameFilter:q->selectedNameFilter() hideNameFilterDetails:q->testOption(QFileDialog::HideNameFilterDetails) qDirFilter:model->filter() fileOptions:opts |