Commit d6c64717 authored by Rafael Roquetto's avatar Rafael Roquetto Committed by Rafael Roquetto
Browse files

Add SaveFile functionality to Utils::PathChooser



Change-Id: I4e35c15a16eda924af217a668159cf2f65af0e94
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent 7c74482a
......@@ -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 <b>%1</b> is not a file.").arg(QDir::toNativeSeparators(fi.absolutePath()));
return false;
}
break;
case PathChooser::ExistingCommand:
if (!fi.isFile() || !fi.isExecutable()) {
if (errorMessage)
......
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment