forked from qt-creator/qt-creator
Git: Only enable submit button when a description is available
Only enable submit button in the git submit editor when a non-empty desciption of the patch is available. Git rejects empty commit messages and old versions fail without even giving an error Qt Creator can detect, so this should make commiting a bit more save. Task-number: QTCREATORBUG-2410
This commit is contained in:
@@ -172,6 +172,8 @@ SubmitEditorWidget::SubmitEditorWidget(QWidget *parent) :
|
|||||||
m_d->m_ui.description->setWordWrapMode(QTextOption::WordWrap);
|
m_d->m_ui.description->setWordWrapMode(QTextOption::WordWrap);
|
||||||
connect(m_d->m_ui.description, SIGNAL(customContextMenuRequested(QPoint)),
|
connect(m_d->m_ui.description, SIGNAL(customContextMenuRequested(QPoint)),
|
||||||
this, SLOT(editorCustomContextMenuRequested(QPoint)));
|
this, SLOT(editorCustomContextMenuRequested(QPoint)));
|
||||||
|
connect(m_d->m_ui.description, SIGNAL(textChanged()),
|
||||||
|
this, SLOT(updateSubmitAction()));
|
||||||
|
|
||||||
// File List
|
// File List
|
||||||
m_d->m_ui.fileView->setContextMenuPolicy(Qt::CustomContextMenu);
|
m_d->m_ui.fileView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
@@ -291,11 +293,12 @@ static QString wrappedText(const QTextEdit *e)
|
|||||||
|
|
||||||
QString SubmitEditorWidget::descriptionText() const
|
QString SubmitEditorWidget::descriptionText() const
|
||||||
{
|
{
|
||||||
QString rc = trimMessageText(lineWrap() ? wrappedText(m_d->m_ui.description) : m_d->m_ui.description->toPlainText());
|
QString rc = trimMessageText(lineWrap() ? wrappedText(m_d->m_ui.description) :
|
||||||
|
m_d->m_ui.description->toPlainText());
|
||||||
// append field entries
|
// append field entries
|
||||||
foreach(const SubmitFieldWidget *fw, m_d->m_fieldWidgets)
|
foreach(const SubmitFieldWidget *fw, m_d->m_fieldWidgets)
|
||||||
rc += fw->fieldValues();
|
rc += fw->fieldValues();
|
||||||
return rc;
|
return cleanupDescription(rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SubmitEditorWidget::setDescriptionText(const QString &text)
|
void SubmitEditorWidget::setDescriptionText(const QString &text)
|
||||||
@@ -495,6 +498,11 @@ unsigned SubmitEditorWidget::checkedFilesCount() const
|
|||||||
return checkedCount;
|
return checkedCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString SubmitEditorWidget::cleanupDescription(const QString &input) const
|
||||||
|
{
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
void SubmitEditorWidget::changeEvent(QEvent *e)
|
void SubmitEditorWidget::changeEvent(QEvent *e)
|
||||||
{
|
{
|
||||||
QWidget::changeEvent(e);
|
QWidget::changeEvent(e);
|
||||||
|
|||||||
@@ -139,6 +139,7 @@ public slots:
|
|||||||
void uncheckAll();
|
void uncheckAll();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual QString cleanupDescription(const QString &) const;
|
||||||
virtual void changeEvent(QEvent *e);
|
virtual void changeEvent(QEvent *e);
|
||||||
void insertTopWidget(QWidget *w);
|
void insertTopWidget(QWidget *w);
|
||||||
|
|
||||||
|
|||||||
@@ -120,25 +120,6 @@ void GitSubmitEditor::slotDiffSelected(const QStringList &files)
|
|||||||
emit diff(unstagedFiles, stagedFiles);
|
emit diff(unstagedFiles, stagedFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GitSubmitEditor::fileContents() const
|
|
||||||
{
|
|
||||||
// We need to manually purge out comment lines starting with
|
|
||||||
// hash '#' since git does not do that when using -F.
|
|
||||||
const QChar newLine = QLatin1Char('\n');
|
|
||||||
const QChar hash = QLatin1Char('#');
|
|
||||||
QString message = VCSBase::VCSBaseSubmitEditor::fileContents();
|
|
||||||
for (int pos = 0; pos < message.size(); ) {
|
|
||||||
const int newLinePos = message.indexOf(newLine, pos);
|
|
||||||
const int startOfNextLine = newLinePos == -1 ? message.size() : newLinePos + 1;
|
|
||||||
if (message.at(pos) == hash) {
|
|
||||||
message.remove(pos, startOfNextLine - pos);
|
|
||||||
} else {
|
|
||||||
pos = startOfNextLine;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
GitSubmitEditorPanelData GitSubmitEditor::panelData() const
|
GitSubmitEditorPanelData GitSubmitEditor::panelData() const
|
||||||
{
|
{
|
||||||
return const_cast<GitSubmitEditor*>(this)->submitEditorWidget()->panelData();
|
return const_cast<GitSubmitEditor*>(this)->submitEditorWidget()->panelData();
|
||||||
|
|||||||
@@ -54,8 +54,6 @@ public:
|
|||||||
void setCommitData(const CommitData &);
|
void setCommitData(const CommitData &);
|
||||||
GitSubmitEditorPanelData panelData() const;
|
GitSubmitEditorPanelData panelData() const;
|
||||||
|
|
||||||
virtual QString fileContents() const;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void diff(const QStringList &unstagedFiles, const QStringList &stagedFiles);
|
void diff(const QStringList &unstagedFiles, const QStringList &stagedFiles);
|
||||||
|
|
||||||
|
|||||||
@@ -151,12 +151,35 @@ void GitSubmitEditorWidget::setPanelData(const GitSubmitEditorPanelData &data)
|
|||||||
|
|
||||||
bool GitSubmitEditorWidget::canSubmit() const
|
bool GitSubmitEditorWidget::canSubmit() const
|
||||||
{
|
{
|
||||||
|
QString message = cleanupDescription(descriptionText()).trimmed();
|
||||||
|
|
||||||
if (m_gitSubmitPanelUi.invalidAuthorLabel->isVisible()
|
if (m_gitSubmitPanelUi.invalidAuthorLabel->isVisible()
|
||||||
|| m_gitSubmitPanelUi.invalidEmailLabel->isVisible())
|
|| m_gitSubmitPanelUi.invalidEmailLabel->isVisible()
|
||||||
|
|| message.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
return SubmitEditorWidget::canSubmit();
|
return SubmitEditorWidget::canSubmit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString GitSubmitEditorWidget::cleanupDescription(const QString &input) const
|
||||||
|
{
|
||||||
|
// We need to manually purge out comment lines starting with
|
||||||
|
// hash '#' since git does not do that when using -F.
|
||||||
|
const QChar newLine = QLatin1Char('\n');
|
||||||
|
const QChar hash = QLatin1Char('#');
|
||||||
|
QString message = input;
|
||||||
|
for (int pos = 0; pos < message.size(); ) {
|
||||||
|
const int newLinePos = message.indexOf(newLine, pos);
|
||||||
|
const int startOfNextLine = newLinePos == -1 ? message.size() : newLinePos + 1;
|
||||||
|
if (message.at(pos) == hash) {
|
||||||
|
message.remove(pos, startOfNextLine - pos);
|
||||||
|
} else {
|
||||||
|
pos = startOfNextLine;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void GitSubmitEditorWidget::authorInformationChanged()
|
void GitSubmitEditorWidget::authorInformationChanged()
|
||||||
{
|
{
|
||||||
bool bothEmpty = m_gitSubmitPanelUi.authorLineEdit->text().isEmpty() &&
|
bool bothEmpty = m_gitSubmitPanelUi.authorLineEdit->text().isEmpty() &&
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool canSubmit() const;
|
bool canSubmit() const;
|
||||||
|
QString cleanupDescription(const QString &) const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void authorInformationChanged();
|
void authorInformationChanged();
|
||||||
|
|||||||
Reference in New Issue
Block a user