diff --git a/src/Gui/FileDialog.cpp b/src/Gui/FileDialog.cpp index 3a007ef901c3..642414744e71 100644 --- a/src/Gui/FileDialog.cpp +++ b/src/Gui/FileDialog.cpp @@ -93,6 +93,27 @@ void FileDialog::onSelectedFilter(const QString& /*filter*/) } } +QList FileDialog::fetchSidebarUrls() +{ + QStringList list; + list << QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); + list << QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); + list << QStandardPaths::writableLocation(QStandardPaths::HomeLocation); + list << QStandardPaths::writableLocation(QStandardPaths::PicturesLocation); + list << getWorkingDirectory(); + list << restoreLocation(); + list << QDir::currentPath(); + + QList urls; + for (const auto& it : list) { + if (QFileInfo::exists(it)) { + urls << QUrl::fromLocalFile(it); + } + } + + return urls; +} + bool FileDialog::hasSuffix(const QString& ext) const { QRegExp rx(QString::fromLatin1("\\*.(%1)\\W").arg(ext)); @@ -182,18 +203,9 @@ QString FileDialog::getSaveFileName (QWidget * parent, const QString & caption, // before showing the file dialog. QString file; if (DialogOptions::dontUseNativeFileDialog()) { - QList urls; + QList urls = fetchSidebarUrls(); options |= QFileDialog::DontUseNativeDialog; - urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); - urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)); - urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); - urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::MusicLocation)); - urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)); - urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::MoviesLocation)); - urls << QUrl::fromLocalFile(getWorkingDirectory()); - urls << QUrl::fromLocalFile(restoreLocation()); - urls << QUrl::fromLocalFile(QDir::currentPath()); FileDialog dlg(parent); dlg.setOptions(options); @@ -264,18 +276,9 @@ QString FileDialog::getOpenFileName(QWidget * parent, const QString & caption, c QString file; if (DialogOptions::dontUseNativeFileDialog()) { - QList urls; + QList urls = fetchSidebarUrls(); options |= QFileDialog::DontUseNativeDialog; - urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); - urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)); - urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); - urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::MusicLocation)); - urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)); - urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::MoviesLocation)); - urls << QUrl::fromLocalFile(getWorkingDirectory()); - urls << QUrl::fromLocalFile(restoreLocation()); - urls << QUrl::fromLocalFile(QDir::currentPath()); FileDialog dlg(parent); dlg.setOptions(options); @@ -326,18 +329,9 @@ QStringList FileDialog::getOpenFileNames (QWidget * parent, const QString & capt QStringList files; if (DialogOptions::dontUseNativeFileDialog()) { - QList urls; + QList urls = fetchSidebarUrls(); options |= QFileDialog::DontUseNativeDialog; - urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); - urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)); - urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); - urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::MusicLocation)); - urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)); - urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::MoviesLocation)); - urls << QUrl::fromLocalFile(getWorkingDirectory()); - urls << QUrl::fromLocalFile(restoreLocation()); - urls << QUrl::fromLocalFile(QDir::currentPath()); FileDialog dlg(parent); dlg.setOptions(options); diff --git a/src/Gui/FileDialog.h b/src/Gui/FileDialog.h index 1804737c496d..f1f28fa4b221 100644 --- a/src/Gui/FileDialog.h +++ b/src/Gui/FileDialog.h @@ -86,6 +86,7 @@ private Q_SLOTS: private: bool hasSuffix(const QString&) const; + static QList fetchSidebarUrls(); static QString workingDirectory; };