forked from qt-creator/qt-creator
fix file name validation bug
This commit is contained in:
@@ -55,7 +55,8 @@ namespace Utils {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ------------------ PathValidatingLineEdit
|
// ------------------ PathValidatingLineEdit
|
||||||
class PathValidatingLineEdit : public BaseValidatingLineEdit {
|
class PathValidatingLineEdit : public BaseValidatingLineEdit
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
explicit PathValidatingLineEdit(PathChooser *chooser, QWidget *parent = 0);
|
explicit PathValidatingLineEdit(PathChooser *chooser, QWidget *parent = 0);
|
||||||
|
|
||||||
@@ -79,7 +80,8 @@ bool PathValidatingLineEdit::validate(const QString &value, QString *errorMessag
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ------------------ PathChooserPrivate
|
// ------------------ PathChooserPrivate
|
||||||
struct PathChooserPrivate {
|
struct PathChooserPrivate
|
||||||
|
{
|
||||||
PathChooserPrivate(PathChooser *chooser);
|
PathChooserPrivate(PathChooser *chooser);
|
||||||
|
|
||||||
PathValidatingLineEdit *m_lineEdit;
|
PathValidatingLineEdit *m_lineEdit;
|
||||||
@@ -160,9 +162,9 @@ void PathChooser::slotBrowse()
|
|||||||
|
|
||||||
// TODO make cross-platform
|
// TODO make cross-platform
|
||||||
// Delete trailing slashes unless it is "/", only
|
// Delete trailing slashes unless it is "/", only
|
||||||
if (!newPath .isEmpty()) {
|
if (!newPath.isEmpty()) {
|
||||||
if (newPath .size() > 1 && newPath .endsWith(QDir::separator()))
|
if (newPath.size() > 1 && newPath.endsWith(QDir::separator()))
|
||||||
newPath .truncate(newPath .size() - 1);
|
newPath.truncate(newPath.size() - 1);
|
||||||
setPath(newPath);
|
setPath(newPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,7 +176,7 @@ bool PathChooser::isValid() const
|
|||||||
|
|
||||||
QString PathChooser::errorMessage() const
|
QString PathChooser::errorMessage() const
|
||||||
{
|
{
|
||||||
return m_d->m_lineEdit->errorMessage();
|
return m_d->m_lineEdit->errorMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PathChooser::validatePath(const QString &path, QString *errorMessage)
|
bool PathChooser::validatePath(const QString &path, QString *errorMessage)
|
||||||
@@ -207,17 +209,19 @@ bool PathChooser::validatePath(const QString &path, QString *errorMessage)
|
|||||||
// Check expected kind
|
// Check expected kind
|
||||||
switch (m_d->m_acceptingKind) {
|
switch (m_d->m_acceptingKind) {
|
||||||
case PathChooser::Directory:
|
case PathChooser::Directory:
|
||||||
if (!isDir)
|
if (!isDir) {
|
||||||
if (errorMessage)
|
if (errorMessage)
|
||||||
*errorMessage = tr("The path '%1' is not a directory.").arg(path);
|
*errorMessage = tr("The path '%1' is not a directory.").arg(path);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PathChooser::File:
|
case PathChooser::File:
|
||||||
if (isDir)
|
if (isDir) {
|
||||||
if (errorMessage)
|
if (errorMessage)
|
||||||
*errorMessage = tr("The path '%1' is not a file.").arg(path);
|
*errorMessage = tr("The path '%1' is not a file.").arg(path);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PathChooser::Command:
|
case PathChooser::Command:
|
||||||
|
|||||||
Reference in New Issue
Block a user