forked from qt-creator/qt-creator
Git: Only allow commit if author information is valid
Check author information to be valid before enableing the commit button. Task-number: QTCREATORBUG-2410
This commit is contained in:
@@ -34,10 +34,13 @@
|
||||
#include <texteditor/fontsettings.h>
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QtGui/QRegExpValidator>
|
||||
#include <QtGui/QSyntaxHighlighter>
|
||||
#include <QtGui/QTextEdit>
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QRegExp>
|
||||
|
||||
namespace Git {
|
||||
@@ -116,11 +119,19 @@ GitSubmitEditorWidget::GitSubmitEditorWidget(QWidget *parent) :
|
||||
m_gitSubmitPanelUi.setupUi(m_gitSubmitPanel);
|
||||
insertTopWidget(m_gitSubmitPanel);
|
||||
new GitSubmitHighlighter(descriptionEdit());
|
||||
|
||||
m_emailValidator = new QRegExpValidator(QRegExp(QLatin1String("[^@ ]+@[^@ ]+\\.[a-zA-Z]+")), this);
|
||||
|
||||
m_gitSubmitPanelUi.emailLineEdit->setValidator(m_emailValidator);
|
||||
connect(m_gitSubmitPanelUi.authorLineEdit, SIGNAL(textChanged(QString)),
|
||||
this, SLOT(authorInformationChanged()));
|
||||
connect(m_gitSubmitPanelUi.emailLineEdit, SIGNAL(textChanged(QString)),
|
||||
this, SLOT(authorInformationChanged()));
|
||||
}
|
||||
|
||||
void GitSubmitEditorWidget::setPanelInfo(const GitSubmitEditorPanelInfo &info)
|
||||
{
|
||||
m_gitSubmitPanelUi.repositoryLabel->setText(info.repository);
|
||||
m_gitSubmitPanelUi.repositoryLabel->setText(QDir::toNativeSeparators(info.repository));
|
||||
m_gitSubmitPanelUi.branchLabel->setText(info.branch);
|
||||
}
|
||||
|
||||
@@ -136,6 +147,32 @@ void GitSubmitEditorWidget::setPanelData(const GitSubmitEditorPanelData &data)
|
||||
{
|
||||
m_gitSubmitPanelUi.authorLineEdit->setText(data.author);
|
||||
m_gitSubmitPanelUi.emailLineEdit->setText(data.email);
|
||||
authorInformationChanged();
|
||||
}
|
||||
|
||||
bool GitSubmitEditorWidget::canSubmit() const
|
||||
{
|
||||
if (m_gitSubmitPanelUi.authorLineEdit->text().isEmpty()
|
||||
|| !emailIsValid())
|
||||
return false;
|
||||
return SubmitEditorWidget::canSubmit();
|
||||
}
|
||||
|
||||
void GitSubmitEditorWidget::authorInformationChanged()
|
||||
{
|
||||
m_gitSubmitPanelUi.invalidAuthorLabel->
|
||||
setVisible(m_gitSubmitPanelUi.authorLineEdit->text().isEmpty());
|
||||
m_gitSubmitPanelUi.invalidEmailLabel->
|
||||
setVisible(!emailIsValid());
|
||||
|
||||
updateSubmitAction();
|
||||
}
|
||||
|
||||
bool GitSubmitEditorWidget::emailIsValid() const
|
||||
{
|
||||
int pos = m_gitSubmitPanelUi.emailLineEdit->cursorPosition();
|
||||
return m_emailValidator->validate(m_gitSubmitPanelUi.emailLineEdit->text(), pos)
|
||||
== QValidator::Acceptable;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -31,8 +31,13 @@
|
||||
#define GITSUBMITEDITORWIDGET_H
|
||||
|
||||
#include "ui_gitsubmitpanel.h"
|
||||
|
||||
#include <utils/submiteditorwidget.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QValidator;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Git {
|
||||
namespace Internal {
|
||||
|
||||
@@ -49,6 +54,7 @@ struct GitSubmitEditorPanelData;
|
||||
|
||||
class GitSubmitEditorWidget : public Utils::SubmitEditorWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GitSubmitEditorWidget(QWidget *parent = 0);
|
||||
@@ -59,9 +65,18 @@ public:
|
||||
|
||||
void setPanelInfo(const GitSubmitEditorPanelInfo &info);
|
||||
|
||||
protected:
|
||||
bool canSubmit() const;
|
||||
|
||||
private slots:
|
||||
void authorInformationChanged();
|
||||
|
||||
private:
|
||||
bool emailIsValid() const;
|
||||
|
||||
QWidget *m_gitSubmitPanel;
|
||||
Ui::GitSubmitPanel m_gitSubmitPanelUi;
|
||||
QValidator *m_emailValidator;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>374</width>
|
||||
<height>229</height>
|
||||
<width>364</width>
|
||||
<height>172</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
@@ -59,49 +59,96 @@
|
||||
<property name="title">
|
||||
<string>Commit Information</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="authorLabel">
|
||||
<property name="text">
|
||||
<string>Author:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="authorLineEdit"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="emailLabel">
|
||||
<property name="text">
|
||||
<string>Email:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="emailLineEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="authorLabel">
|
||||
<property name="text">
|
||||
<string>Author:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="authorLineEdit">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="invalidAuthorLabel">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="../projectexplorer/projectexplorer.qrc">:/projectexplorer/images/compile_error.png</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::MinimumExpanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>161</width>
|
||||
<width>5</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="emailLabel">
|
||||
<property name="text">
|
||||
<string>Email:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="emailLineEdit">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="invalidEmailLabel">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="../projectexplorer/projectexplorer.qrc">:/projectexplorer/images/compile_error.png</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<resources>
|
||||
<include location="../projectexplorer/projectexplorer.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
Reference in New Issue
Block a user