diff --git a/src/libs/utils/pathchooser.cpp b/src/libs/utils/pathchooser.cpp index f591f605389..9246366b68e 100644 --- a/src/libs/utils/pathchooser.cpp +++ b/src/libs/utils/pathchooser.cpp @@ -542,6 +542,11 @@ bool PathChooser::validatePath(FancyLineEdit *edit, QString *errorMessage) const *errorMessage = tr("The path \"%1\" does not exist.").arg(QDir::toNativeSeparators(expandedPath)); return false; } + if (!fi.isFile()) { + if (errorMessage) + *errorMessage = tr("The path %1 is not a file.").arg(QDir::toNativeSeparators(expandedPath)); + return false; + } break; case PathChooser::SaveFile: if (!fi.absoluteDir().exists()) { @@ -549,6 +554,11 @@ bool PathChooser::validatePath(FancyLineEdit *edit, QString *errorMessage) const *errorMessage = tr("The directory \"%1\" does not exist.").arg(QDir::toNativeSeparators(fi.absolutePath())); return false; } + 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.exists()) { @@ -556,9 +566,9 @@ bool PathChooser::validatePath(FancyLineEdit *edit, QString *errorMessage) const *errorMessage = tr("The path \"%1\" does not exist.").arg(QDir::toNativeSeparators(expandedPath)); return false; } - if (!fi.isExecutable()) { + if (!fi.isFile() || !fi.isExecutable()) { if (errorMessage) - *errorMessage = tr("Cannot execute \"%1\".").arg(QDir::toNativeSeparators(expandedPath)); + *errorMessage = tr("The path %1 is not an executable file.").arg(QDir::toNativeSeparators(expandedPath)); return false; } break; @@ -581,49 +591,6 @@ bool PathChooser::validatePath(FancyLineEdit *edit, QString *errorMessage) const ; } - // Check expected kind - switch (d->m_acceptingKind) { - case PathChooser::ExistingDirectory: - if (!fi.isDir()) { - if (errorMessage) - *errorMessage = tr("The path %1 is not a directory.").arg(QDir::toNativeSeparators(expandedPath)); - return false; - } - break; - - case PathChooser::File: - if (!fi.isFile()) { - if (errorMessage) - *errorMessage = tr("The path %1 is not a file.").arg(QDir::toNativeSeparators(expandedPath)); - return false; - } - 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) - *errorMessage = tr("The path %1 is not an executable file.").arg(QDir::toNativeSeparators(expandedPath)); - return false; - } - - case PathChooser::Command: - break; - - case PathChooser::Any: - break; - - default: - ; - } - if (errorMessage) *errorMessage = tr("Full path: %1").arg(QDir::toNativeSeparators(expandedPath)); return true;