diff --git a/src/libs/utils/pathchooser.cpp b/src/libs/utils/pathchooser.cpp index 256599e1644..961dc5e479f 100644 --- a/src/libs/utils/pathchooser.cpp +++ b/src/libs/utils/pathchooser.cpp @@ -231,6 +231,7 @@ QString PathChooserPrivate::expandedPath(const QString &input) const case PathChooser::Directory: case PathChooser::ExistingDirectory: case PathChooser::File: + case PathChooser::SaveFile: if (!m_baseDirectory.isEmpty() && QFileInfo(path).isRelative()) return QFileInfo(m_baseDirectory + QLatin1Char('/') + path).absoluteFilePath(); break; @@ -382,6 +383,11 @@ void PathChooser::slotBrowse() makeDialogTitle(tr("Choose File")), predefined, d->m_dialogFilter); break; + case PathChooser::SaveFile: + newPath = QFileDialog::getSaveFileName(this, + makeDialogTitle(tr("Choose File")), predefined, + d->m_dialogFilter); + break; case PathChooser::Any: { QFileDialog dialog(this); dialog.setFileMode(QFileDialog::AnyFile); @@ -469,6 +475,13 @@ bool PathChooser::validatePath(const QString &path, QString *errorMessage) return false; } break; + case PathChooser::SaveFile: + if (!fi.absoluteDir().exists()) { + if (errorMessage) + *errorMessage = tr("The directory '%1' does not exist.").arg(QDir::toNativeSeparators(fi.absolutePath())); + return false; + } + break; case PathChooser::ExistingCommand: if (!fi.exists()) { if (errorMessage) @@ -518,6 +531,14 @@ bool PathChooser::validatePath(const QString &path, QString *errorMessage) } break; + case PathChooser::SaveFile: + if (fi.exists() && fi.isDir()) { + if (errorMessage) + *errorMessage = tr("The path %1 is not a file.").arg(QDir::toNativeSeparators(fi.absolutePath())); + return false; + } + break; + case PathChooser::ExistingCommand: if (!fi.isFile() || !fi.isExecutable()) { if (errorMessage) diff --git a/src/libs/utils/pathchooser.h b/src/libs/utils/pathchooser.h index dcb43ed8c1d..cf34dcd2cf5 100644 --- a/src/libs/utils/pathchooser.h +++ b/src/libs/utils/pathchooser.h @@ -72,6 +72,7 @@ public: ExistingDirectory, Directory, // A directory, doesn't need to exist File, + SaveFile, ExistingCommand, // A command that must exist at the time of selection Command, // A command that may or may not exist at the time of selection (e.g. result of a build) Any