Commit 9fcae416 authored by Marco Bubke's avatar Marco Bubke

Improve validation of the move component refactoring dialog

Using PathChooser and ClassNameValidatingLineEdit improves the usability.

Change-Id: Ib01ee99222ea495b37b0e839fbc68981b071d0a6
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@nokia.com>
parent 1cb66190
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <QFileInfo> #include <QFileInfo>
#include <QFileDialog> #include <QFileDialog>
#include <QPushButton>
using namespace QmlJSEditor::Internal; using namespace QmlJSEditor::Internal;
...@@ -44,9 +45,7 @@ ComponentNameDialog::ComponentNameDialog(QWidget *parent) : ...@@ -44,9 +45,7 @@ ComponentNameDialog::ComponentNameDialog(QWidget *parent) :
{ {
ui->setupUi(this); ui->setupUi(this);
connect(ui->choosePathButton, SIGNAL(clicked()), connect(ui->pathEdit, SIGNAL(changed(QString)),
this, SLOT(choosePath()));
connect(ui->pathEdit, SIGNAL(textChanged(QString)),
this, SLOT(validate())); this, SLOT(validate()));
connect(ui->componentNameEdit, SIGNAL(textChanged(QString)), connect(ui->componentNameEdit, SIGNAL(textChanged(QString)),
this, SLOT(validate())); this, SLOT(validate()));
...@@ -65,38 +64,44 @@ void ComponentNameDialog::go(QString *proposedName, ...@@ -65,38 +64,44 @@ void ComponentNameDialog::go(QString *proposedName,
Q_ASSERT(proposedPath); Q_ASSERT(proposedPath);
ComponentNameDialog d(parent); ComponentNameDialog d(parent);
d.ui->componentNameEdit->setNamespacesEnabled(false);
d.ui->componentNameEdit->setLowerCaseFileName(false);
d.ui->componentNameEdit->setClassNameMustBeCapital(true);
d.ui->componentNameEdit->setText(*proposedName); d.ui->componentNameEdit->setText(*proposedName);
d.ui->pathEdit->setText(*proposedPath); d.ui->pathEdit->setExpectedKind(Utils::PathChooser::ExistingDirectory);
d.ui->pathEdit->setPath(*proposedPath);
if (QDialog::Accepted == d.exec()) { if (QDialog::Accepted == d.exec()) {
*proposedName = d.ui->componentNameEdit->text(); *proposedName = d.ui->componentNameEdit->text();
*proposedPath = d.ui->pathEdit->text(); *proposedPath = d.ui->pathEdit->path();
} }
} }
void ComponentNameDialog::choosePath() void ComponentNameDialog::choosePath()
{ {
QString dir = QFileDialog::getExistingDirectory(this, tr("Choose a path"), QString dir = QFileDialog::getExistingDirectory(this, tr("Choose a path"),
ui->pathEdit->text()); ui->pathEdit->path());
if (!dir.isEmpty()) if (!dir.isEmpty())
ui->pathEdit->setText(dir); ui->pathEdit->setPath(dir);
} }
void ComponentNameDialog::validate() void ComponentNameDialog::validate()
{ {
const QString msg = isValid(); const QString message = isValid();
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(msg.isEmpty()); ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(message.isEmpty());
ui->messageLabel->setText(msg); ui->messageLabel->setText(message);
} }
QString ComponentNameDialog::isValid() const QString ComponentNameDialog::isValid() const
{ {
if (!ui->componentNameEdit->isValid())
return ui->componentNameEdit->errorMessage();
QString compName = ui->componentNameEdit->text(); QString compName = ui->componentNameEdit->text();
if (compName.isEmpty() || !compName[0].isUpper()) if (compName.isEmpty() || !compName[0].isUpper())
return tr("Invalid component name"); return tr("Invalid component name");
QString path = ui->pathEdit->text(); if (!ui->pathEdit->isValid())
if (path.isEmpty() || !QFileInfo(path).isDir())
return tr("Invalid path"); return tr("Invalid path");
return QString(); return QString();
......
...@@ -25,15 +25,15 @@ ...@@ -25,15 +25,15 @@
<property name="verticalSpacing"> <property name="verticalSpacing">
<number>10</number> <number>10</number>
</property> </property>
<item row="0" column="0"> <item row="2" column="1" colspan="2">
<widget class="QLabel" name="componentNameLabel"> <widget class="QLabel" name="messageLabel">
<property name="text"> <property name="text">
<string>Component name:</string> <string/>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLineEdit" name="componentNameEdit"/> <widget class="Utils::ClassNameValidatingLineEdit" name="componentNameEdit"/>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="choosePathLabel"> <widget class="QLabel" name="choosePathLabel">
...@@ -42,22 +42,15 @@ ...@@ -42,22 +42,15 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="0" column="0">
<widget class="QLineEdit" name="pathEdit"/> <widget class="QLabel" name="componentNameLabel">
</item>
<item row="1" column="2">
<widget class="QPushButton" name="choosePathButton">
<property name="text"> <property name="text">
<string>Choose...</string> <string>Component name:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1" colspan="2"> <item row="1" column="1">
<widget class="QLabel" name="messageLabel"> <widget class="Utils::PathChooser" name="pathEdit" native="true"/>
<property name="text">
<string/>
</property>
</widget>
</item> </item>
</layout> </layout>
</item> </item>
...@@ -86,6 +79,19 @@ ...@@ -86,6 +79,19 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>Utils::ClassNameValidatingLineEdit</class>
<extends>QLineEdit</extends>
<header location="global">utils/classnamevalidatinglineedit.h</header>
</customwidget>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header location="global">utils/pathchooser.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections> <connections>
<connection> <connection>
......
Markdown is supported
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