diff --git a/src/libs/utils/submiteditorwidget.cpp b/src/libs/utils/submiteditorwidget.cpp index 0c8aa30a1c4bf04f1c23c33f78ab08ba59e8e43e..10cade5c2e199f5adc962a735e81fc037d61328e 100644 --- a/src/libs/utils/submiteditorwidget.cpp +++ b/src/libs/utils/submiteditorwidget.cpp @@ -139,7 +139,6 @@ struct SubmitEditorWidgetPrivate Ui::SubmitEditorWidget m_ui; bool m_filesSelected; - bool m_filesChecked; int m_fileNameColumn; int m_activatedRow; bool m_emptyFileListEnabled; @@ -148,16 +147,18 @@ struct SubmitEditorWidgetPrivate QVBoxLayout *m_fieldLayout; QList<SubmitFieldWidget *> m_fieldWidgets; int m_lineWidth; + + bool m_commitEnabled; }; SubmitEditorWidgetPrivate::SubmitEditorWidgetPrivate() : m_filesSelected(false), - m_filesChecked(false), m_fileNameColumn(1), m_activatedRow(-1), m_emptyFileListEnabled(false), m_fieldLayout(0), - m_lineWidth(defaultLineWidth) + m_lineWidth(defaultLineWidth), + m_commitEnabled(false) { } @@ -209,10 +210,10 @@ void SubmitEditorWidget::registerActions(QAction *editorUndoAction, QAction *edi int count = 0; if (const QAbstractItemModel *model = m_d->m_ui.fileView->model()) count = model->rowCount(); - qDebug() << Q_FUNC_INFO << submitAction << count << "items" << m_d->m_filesChecked; + qDebug() << Q_FUNC_INFO << submitAction << count << "items"; } - submitAction->setEnabled(m_d->m_filesChecked); - connect(this, SIGNAL(fileCheckStateChanged(bool)), submitAction, SLOT(setEnabled(bool))); + m_d->m_commitEnabled = !canSubmit(); + connect(this, SIGNAL(submitActionEnabledChanged(bool)), submitAction, SLOT(setEnabled(bool))); // Wire setText via QActionSetTextSlotHelper. QActionSetTextSlotHelper *actionSlotHelper = submitAction->findChild<QActionSetTextSlotHelper *>(); if (!actionSlotHelper) @@ -243,7 +244,7 @@ void SubmitEditorWidget::unregisterActions(QAction *editorUndoAction, QAction * } if (submitAction) { - disconnect(this, SIGNAL(fileCheckStateChanged(bool)), submitAction, SLOT(setEnabled(bool))); + disconnect(this, SIGNAL(submitActionEnabledChanged(bool)), submitAction, SLOT(setEnabled(bool))); // Just deactivate the QActionSetTextSlotHelper on the action disconnect(this, SIGNAL(submitActionTextChanged(QString)), 0, 0); } @@ -448,18 +449,20 @@ void SubmitEditorWidget::updateActions() void SubmitEditorWidget::updateSubmitAction() { const unsigned checkedCount = checkedFilesCount(); - const bool newFilesCheckedState = m_d->m_emptyFileListEnabled || checkedCount > 0; + const bool newCommitState = canSubmit(); // Emit signal to update action - if (m_d->m_filesChecked != newFilesCheckedState) { - m_d->m_filesChecked = newFilesCheckedState; - emit fileCheckStateChanged(m_d->m_filesChecked); + if (m_d->m_commitEnabled != newCommitState) { + m_d->m_commitEnabled = newCommitState; + emit submitActionEnabledChanged(m_d->m_commitEnabled); + } + if (m_d->m_ui.fileView && m_d->m_ui.fileView->model()) { + // Update button text. + const int fileCount = m_d->m_ui.fileView->model()->rowCount(); + const QString msg = checkedCount ? + tr("Commit %1/%n Files", 0, fileCount).arg(checkedCount) : + tr("Commit"); + emit submitActionTextChanged(msg); } - // Update button text. - const int fileCount = m_d->m_ui.fileView->model()->rowCount(); - const QString msg = checkedCount ? - tr("Commit %1/%n Files", 0, fileCount).arg(checkedCount) : - tr("Commit"); - emit submitActionTextChanged(msg); } // Enable diff depending on selected files @@ -509,6 +512,12 @@ void SubmitEditorWidget::insertTopWidget(QWidget *w) m_d->m_ui.vboxLayout->insertWidget(0, w); } +bool SubmitEditorWidget::canSubmit() const +{ + const unsigned checkedCount = checkedFilesCount(); + return m_d->m_emptyFileListEnabled || checkedCount > 0; +} + void SubmitEditorWidget::addSubmitFieldWidget(SubmitFieldWidget *f) { if (!m_d->m_fieldLayout) { diff --git a/src/libs/utils/submiteditorwidget.h b/src/libs/utils/submiteditorwidget.h index 457783a9d7f2c906a61b201a8cb963d0ad6de490..37d1c8b0bd959764b8a77625aaf6045b5f8288a4 100644 --- a/src/libs/utils/submiteditorwidget.h +++ b/src/libs/utils/submiteditorwidget.h @@ -129,8 +129,8 @@ public: signals: void diffSelected(const QStringList &); void fileSelectionChanged(bool someFileSelected); - void fileCheckStateChanged(bool someFileChecked); void submitActionTextChanged(const QString &); + void submitActionEnabledChanged(const bool); public slots: void checkAll(); @@ -139,13 +139,16 @@ public slots: protected: virtual void changeEvent(QEvent *e); void insertTopWidget(QWidget *w); + virtual bool canSubmit() const; + +protected slots: + void updateSubmitAction(); private slots: void triggerDiffSelected(); void diffActivated(const QModelIndex &index); void diffActivatedDelayed(); void updateActions(); - void updateSubmitAction(); void updateDiffAction(); void editorCustomContextMenuRequested(const QPoint &); void fileListCustomContextMenuRequested(const QPoint & pos); diff --git a/src/plugins/git/gitsubmiteditorwidget.cpp b/src/plugins/git/gitsubmiteditorwidget.cpp index 1a02f4a8a184b77af480d6449682c065387e83f8..5014a8b20f8ce78c4c5b1977e2a9d711a5f47a79 100644 --- a/src/plugins/git/gitsubmiteditorwidget.cpp +++ b/src/plugins/git/gitsubmiteditorwidget.cpp @@ -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 diff --git a/src/plugins/git/gitsubmiteditorwidget.h b/src/plugins/git/gitsubmiteditorwidget.h index 40d744641fd68d0965c951322b15373fb2a49368..64e4c5aac3c90d3e1937d84adcdc3833082ac6dc 100644 --- a/src/plugins/git/gitsubmiteditorwidget.h +++ b/src/plugins/git/gitsubmiteditorwidget.h @@ -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 diff --git a/src/plugins/git/gitsubmitpanel.ui b/src/plugins/git/gitsubmitpanel.ui index 7dfa9b3ba0fbc4973fe988caedd157a5cd22363c..c790299aa11cd9ed1e74495d87893dacd34067d4 100644 --- a/src/plugins/git/gitsubmitpanel.ui +++ b/src/plugins/git/gitsubmitpanel.ui @@ -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 row="0" column="1"> + <widget class="QLineEdit" name="authorLineEdit"> + <property name="minimumSize"> + <size> + <width>150</width> + <height>0</height> + </size> + </property> + </widget> </item> - <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>