From bfd73eaba3000861037d03787f87d1f4dafefea8 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Wed, 23 Jan 2013 12:48:21 +0100 Subject: Respect the filename specified when showing the native filedialog When a filename was specified as part of the start up directory then it should ensure this is put in the filename lineedit in the native filedialog. Change-Id: I2b190933d46553908b5bcf17506cb2a95fb1f982 Reviewed-by: Friedemann Kleint --- .../platforms/windows/qwindowsdialoghelpers.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp index 15520c98b0..74193c47a3 100644 --- a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp +++ b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp @@ -668,6 +668,7 @@ public: inline void setNameFilters(const QStringList &f); inline void selectNameFilter(const QString &filter); inline QString selectedNameFilter() const; + void selectFile(const QString &fileName) const; bool hideFiltersDetails() const { return m_hideFiltersDetails; } void setHideFiltersDetails(bool h) { m_hideFiltersDetails = h; } void setDefaultSuffix(const QString &s); @@ -961,6 +962,11 @@ void QWindowsNativeFileDialogBase::setLabelText(QFileDialogOptions::DialogLabel } } +void QWindowsNativeFileDialogBase::selectFile(const QString &fileName) const +{ + m_fileDialog->SetFileName((wchar_t*)fileName.utf16()); +} + // Return the index of the selected filter, accounting for QFileDialog // sometimes stripping the filter specification depending on the // hideFilterDetails setting. @@ -1230,6 +1236,12 @@ QWindowsNativeDialogBase *QWindowsFileDialogHelper::createNativeDialog() const QString initialDirectory = opts->initialDirectory(); if (!initialDirectory.isEmpty()) result->setDirectory(initialDirectory); + const QStringList initialSelection = opts->initiallySelectedFiles(); + if (initialSelection.size() > 0) { + QFileInfo info(initialSelection.front()); + if (!info.isDir()) + result->selectFile(info.fileName()); + } const QString initialNameFilter = opts->initiallySelectedNameFilter(); if (!initialNameFilter.isEmpty()) result->selectNameFilter(initialNameFilter); @@ -1255,9 +1267,13 @@ QString QWindowsFileDialogHelper::directory() const return QString(); } -void QWindowsFileDialogHelper::selectFile(const QString & /* filename */) +void QWindowsFileDialogHelper::selectFile(const QString &fileName) { - // Not implemented. + if (QWindowsContext::verboseDialogs) + qDebug("%s %s" , __FUNCTION__, qPrintable(fileName)); + + if (QWindowsNativeFileDialogBase *nfd = nativeFileDialog()) + nfd->selectFile(fileName); } QStringList QWindowsFileDialogHelper::selectedFiles() const -- cgit v1.2.3