forked from qt-creator/qt-creator
Add SaveFile functionality to Utils::PathChooser
Change-Id: I4e35c15a16eda924af217a668159cf2f65af0e94 Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
committed by
Rafael Roquetto
parent
7c74482ad3
commit
d6c6471776
@@ -231,6 +231,7 @@ QString PathChooserPrivate::expandedPath(const QString &input) const
|
|||||||
case PathChooser::Directory:
|
case PathChooser::Directory:
|
||||||
case PathChooser::ExistingDirectory:
|
case PathChooser::ExistingDirectory:
|
||||||
case PathChooser::File:
|
case PathChooser::File:
|
||||||
|
case PathChooser::SaveFile:
|
||||||
if (!m_baseDirectory.isEmpty() && QFileInfo(path).isRelative())
|
if (!m_baseDirectory.isEmpty() && QFileInfo(path).isRelative())
|
||||||
return QFileInfo(m_baseDirectory + QLatin1Char('/') + path).absoluteFilePath();
|
return QFileInfo(m_baseDirectory + QLatin1Char('/') + path).absoluteFilePath();
|
||||||
break;
|
break;
|
||||||
@@ -382,6 +383,11 @@ void PathChooser::slotBrowse()
|
|||||||
makeDialogTitle(tr("Choose File")), predefined,
|
makeDialogTitle(tr("Choose File")), predefined,
|
||||||
d->m_dialogFilter);
|
d->m_dialogFilter);
|
||||||
break;
|
break;
|
||||||
|
case PathChooser::SaveFile:
|
||||||
|
newPath = QFileDialog::getSaveFileName(this,
|
||||||
|
makeDialogTitle(tr("Choose File")), predefined,
|
||||||
|
d->m_dialogFilter);
|
||||||
|
break;
|
||||||
case PathChooser::Any: {
|
case PathChooser::Any: {
|
||||||
QFileDialog dialog(this);
|
QFileDialog dialog(this);
|
||||||
dialog.setFileMode(QFileDialog::AnyFile);
|
dialog.setFileMode(QFileDialog::AnyFile);
|
||||||
@@ -469,6 +475,13 @@ bool PathChooser::validatePath(const QString &path, QString *errorMessage)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
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:
|
case PathChooser::ExistingCommand:
|
||||||
if (!fi.exists()) {
|
if (!fi.exists()) {
|
||||||
if (errorMessage)
|
if (errorMessage)
|
||||||
@@ -518,6 +531,14 @@ bool PathChooser::validatePath(const QString &path, QString *errorMessage)
|
|||||||
}
|
}
|
||||||
break;
|
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:
|
case PathChooser::ExistingCommand:
|
||||||
if (!fi.isFile() || !fi.isExecutable()) {
|
if (!fi.isFile() || !fi.isExecutable()) {
|
||||||
if (errorMessage)
|
if (errorMessage)
|
||||||
|
@@ -72,6 +72,7 @@ public:
|
|||||||
ExistingDirectory,
|
ExistingDirectory,
|
||||||
Directory, // A directory, doesn't need to exist
|
Directory, // A directory, doesn't need to exist
|
||||||
File,
|
File,
|
||||||
|
SaveFile,
|
||||||
ExistingCommand, // A command that must exist at the time of selection
|
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)
|
Command, // A command that may or may not exist at the time of selection (e.g. result of a build)
|
||||||
Any
|
Any
|
||||||
|
Reference in New Issue
Block a user