Commit 927578ed authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Fixes: Polish submit message checking.

Details: Use a global model for nicknames that is shared by all dialogs to solve the updating  problems. Make p4 plugin submit work again. Force a submit prompt in case of shutdown or editor close (as opposed to user clickling on "Submit").
parent 79d6c96d
......@@ -142,7 +142,8 @@ GitPlugin::GitPlugin() :
m_coreListener(0),
m_submitEditorFactory(0),
m_versionControl(0),
m_changeTmpFile(0)
m_changeTmpFile(0),
m_submitActionTriggered(false)
{
m_instance = this;
}
......@@ -651,6 +652,7 @@ Core::IEditor *GitPlugin::openSubmitEditor(const QString &fileName, const Commit
void GitPlugin::submitCurrentLog()
{
// Close the submit editor
m_submitActionTriggered = true;
QList<Core::IEditor*> editors;
editors.push_back(m_core->editorManager()->currentEditor());
m_core->editorManager()->closeEditors(editors);
......@@ -672,11 +674,14 @@ bool GitPlugin::editorAboutToClose(Core::IEditor *iEditor)
// Paranoia!
if (editorFile.absoluteFilePath() != changeFile.absoluteFilePath())
return true;
// Prompt user.
// Prompt user. Force a prompt unless submit was actually invoked (that
// is, the editor was closed or shutdown).
const VCSBase::VCSBaseSubmitEditor::PromptSubmitResult answer =
editor->promptSubmit(tr("Closing git editor"),
tr("Do you want to commit the change?"),
tr("The commit message check failed. Do you want to commit the change?"));
tr("The commit message check failed. Do you want to commit the change?"),
!m_submitActionTriggered);
m_submitActionTriggered = false;
switch (answer) {
case VCSBase::VCSBaseSubmitEditor::SubmitCanceled:
return false; // Keep editing and change file
......
......@@ -171,6 +171,7 @@ private:
QString m_submitRepository;
QStringList m_submitOrigCommitFiles;
QTemporaryFile *m_changeTmpFile;
bool m_submitActionTriggered;
};
} // namespace Git
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>201</width>
<height>189</height>
<width>374</width>
<height>229</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
......@@ -59,26 +59,43 @@
<property name="title">
<string>Commit Information</string>
</property>
<layout class="QFormLayout" name="editFormLayout">
<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"/>
<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>
</item>
<item row="1" column="0">
<widget class="QLabel" name="emailLabel">
<property name="text">
<string>Email:</string>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="emailLineEdit"/>
<property name="sizeHint" stdset="0">
<size>
<width>161</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
......
......@@ -175,13 +175,18 @@ PerforcePlugin::PerforcePlugin() :
m_diffProjectAction(0),
m_diffAllAction(0),
m_resolveAction(0),
m_submitAction(0),
m_submitAction(0),
m_pendingAction(0),
m_describeAction(0),
m_annotateCurrentAction(0),
m_annotateAction(0),
m_filelogCurrentAction(0),
m_filelogAction(0),
m_submitCurrentLogAction(0),
m_submitActionTriggered(false),
m_diffSelectedFiles(0),
m_undoAction(0),
m_redoAction(0),
m_changeTmpFile(0),
#ifdef USE_P4_API
m_workbenchClientUser(0),
......@@ -949,6 +954,7 @@ void PerforcePlugin::describe(const QString & source, const QString &n)
void PerforcePlugin::submitCurrentLog()
{
m_submitActionTriggered = true;
Core::EditorManager *em = Core::EditorManager::instance();
em->closeEditors(QList<Core::IEditor*>() << em->currentEditor());
}
......@@ -966,11 +972,15 @@ bool PerforcePlugin::editorAboutToClose(Core::IEditor *editor)
return true;
QFileInfo editorFile(fileIFace->fileName());
QFileInfo changeFile(m_changeTmpFile->fileName());
if (editorFile.absoluteFilePath() == changeFile.absoluteFilePath()) {
if (editorFile.absoluteFilePath() == changeFile.absoluteFilePath()) {
// Prompt the user. Force a prompt unless submit was actually invoked (that
// is, the editor was closed or shutdown).
const VCSBase::VCSBaseSubmitEditor::PromptSubmitResult answer =
perforceEditor->promptSubmit(tr("Closing p4 Editor"),
tr("Do you want to submit this change list?"),
tr("The commit message check failed. Do you want to submit this change list"));
tr("The commit message check failed. Do you want to submit this change list"),
!m_submitActionTriggered);
m_submitActionTriggered = false;
if (answer == VCSBase::VCSBaseSubmitEditor::SubmitCanceled)
return false;
......@@ -1010,10 +1020,10 @@ bool PerforcePlugin::editorAboutToClose(Core::IEditor *editor)
m_changeTmpFile = 0;
return false;
}
QString output = QString::fromUtf8(proc.readAll());
const QString output = QString::fromUtf8(proc.readAll());
showOutput(output);
if (output.contains("Out of date files must be resolved or reverted"), true) {
QMessageBox::warning(editor->widget(), "Pending change", "Could not submit the change, because your workspace was out of date. Created a pending submit instead.");
if (output.contains(QLatin1String("Out of date files must be resolved or reverted)"))) {
QMessageBox::warning(editor->widget(), tr("Pending change"), tr("Could not submit the change, because your workspace was out of date. Created a pending submit instead."));
}
QApplication::restoreOverrideCursor();
}
......
......@@ -190,6 +190,7 @@ private:
QAction *m_filelogCurrentAction;
QAction *m_filelogAction;
QAction *m_submitCurrentLogAction;
bool m_submitActionTriggered;
QAction *m_diffSelectedFiles;
QAction *m_undoAction;
......@@ -232,7 +233,7 @@ private:
PerforceVersionControl *m_versionControl;
PerforceSettings m_settings;
friend class PerforceOutputWindow;
friend class PerforceOutputWindow; // needs openFiles()
};
} // namespace Perforce
......
......@@ -188,7 +188,8 @@ SubversionPlugin::SubversionPlugin() :
m_submitCurrentLogAction(0),
m_submitDiffAction(0),
m_submitUndoAction(0),
m_submitRedoAction(0)
m_submitRedoAction(0),
m_submitActionTriggered(false)
{
}
......@@ -463,11 +464,14 @@ bool SubversionPlugin::editorAboutToClose(Core::IEditor *iEditor)
if (editorFile.absoluteFilePath() != changeFile.absoluteFilePath())
return true; // Oops?!
// Prompt user.
// Prompt user. Force a prompt unless submit was actually invoked (that
// is, the editor was closed or shutdown).
const VCSBase::VCSBaseSubmitEditor::PromptSubmitResult answer =
editor->promptSubmit(tr("Closing Subversion Editor"),
tr("Do you want to commit the change?"),
tr("The commit message check failed. Do you want to commit the change?"));
tr("The commit message check failed. Do you want to commit the change?"),
!m_submitActionTriggered);
m_submitActionTriggered = false;
switch (answer) {
case VCSBase::VCSBaseSubmitEditor::SubmitCanceled:
return false; // Keep editing and change file
......@@ -922,6 +926,7 @@ void SubversionPlugin::slotDescribe()
void SubversionPlugin::submitCurrentLog()
{
m_submitActionTriggered = true;
Core::EditorManager::instance()->closeEditors(QList<Core::IEditor*>()
<< Core::EditorManager::instance()->currentEditor());
}
......
......@@ -168,6 +168,7 @@ private:
QAction *m_submitDiffAction;
QAction *m_submitUndoAction;
QAction *m_submitRedoAction;
bool m_submitActionTriggered;
static const char * const SUBVERSION_MENU;
static const char * const ADD;
......
......@@ -28,6 +28,7 @@
**************************************************************************/
#include "nicknamedialog.h"
#include "vcsbaseplugin.h"
#include "ui_nicknamedialog.h"
#include <QtCore/QDebug>
......@@ -36,13 +37,19 @@
#include <QtGui/QStandardItemModel>
#include <QtGui/QSortFilterProxyModel>
enum { NickNameRole = Qt::UserRole + 1 };
namespace VCSBase {
namespace Internal {
struct NickEntry {
// For code clarity, a struct representing the entries of a mail map file
// with parse and model functions.
struct NickNameEntry {
void clear();
bool parse(const QString &);
QString nickName() const;
QList<QStandardItem *> toModelRow() const;
static QString nickNameOf(const QStandardItem *item);
QString name;
QString email;
......@@ -50,7 +57,7 @@ struct NickEntry {
QString aliasEmail;
};
void NickEntry::clear()
void NickNameEntry::clear()
{
name.clear();
email.clear();
......@@ -60,7 +67,7 @@ void NickEntry::clear()
// Parse "Hans Mustermann <HM@acme.de> [Alias [<alias@acme.de>]]"
bool NickEntry::parse(const QString &l)
bool NickNameEntry::parse(const QString &l)
{
clear();
const QChar lessThan = QLatin1Char('<');
......@@ -105,50 +112,59 @@ static inline QString formatNick(const QString &name, const QString &email)
return rc;
}
QString NickEntry::nickName() const
QString NickNameEntry::nickName() const
{
return aliasName.isEmpty() ? formatNick(name, email) : formatNick(aliasName, aliasEmail);
}
// Sort by name
bool operator<(const NickEntry &n1, const NickEntry &n2)
QList<QStandardItem *> NickNameEntry::toModelRow() const
{
return n1.name < n2.name;
const QVariant nickNameData = nickName();
QStandardItem *i1 = new QStandardItem(name);
i1->setData(nickNameData, NickNameRole);
QStandardItem *i2 = new QStandardItem(email);
i2->setData(nickNameData, NickNameRole);
QStandardItem *i3 = new QStandardItem(aliasName);
i3->setData(nickNameData, NickNameRole);
QStandardItem *i4 = new QStandardItem(aliasEmail);
i4->setData(nickNameData, NickNameRole);
QList<QStandardItem *> row;
row << i1 << i2 << i3 << i4;
return row;
}
QDebug operator<<(QDebug d, const NickEntry &e)
QString NickNameEntry::nickNameOf(const QStandardItem *item)
{
return item->data(NickNameRole).toString();
}
QDebug operator<<(QDebug d, const NickNameEntry &e)
{
d.nospace() << "Name='" << e.name << "' Mail='" << e.email
<< " Alias='" << e.aliasName << " AliasEmail='" << e.aliasEmail << "'\n";
return d;
}
// Globally cached list
static QList<NickEntry> &nickList()
// Globally cached model tacked onto the plugin.
static QStandardItemModel *nickModel()
{
static QList<NickEntry> rc;
return rc;
static QStandardItemModel *model = 0;
if (!model) {
model = new QStandardItemModel(VCSBasePlugin::instance());
QStringList headers;
headers << NickNameDialog::tr("Name")
<< NickNameDialog::tr("E-mail")
<< NickNameDialog::tr("Alias")
<< NickNameDialog::tr("Alias e-mail");
model->setHorizontalHeaderLabels(headers);
}
return model;
}
// Create a model populated with the names
static QStandardItemModel *createModel(QObject *parent)
{
QStandardItemModel *rc = new QStandardItemModel(parent);
QStringList headers;
headers << NickNameDialog::tr("Name")
<< NickNameDialog::tr("E-mail")
<< NickNameDialog::tr("Alias")
<< NickNameDialog::tr("Alias e-mail");
rc->setHorizontalHeaderLabels(headers);
foreach(const NickEntry &ne, nickList()) {
QList<QStandardItem *> row;
row.push_back(new QStandardItem(ne.name));
row.push_back(new QStandardItem(ne.email));
row.push_back(new QStandardItem(ne.aliasName));
row.push_back(new QStandardItem(ne.aliasEmail));
rc->appendRow(row);
}
return rc;
static inline void clearModel(QStandardItemModel *model)
{
if (const int rowCount = model->rowCount())
model->removeRows(0, rowCount);
}
NickNameDialog::NickNameDialog(QWidget *parent) :
......@@ -161,7 +177,7 @@ NickNameDialog::NickNameDialog(QWidget *parent) :
okButton()->setEnabled(false);
// Populate model and grow tree to accommodate it
m_filterModel->setSourceModel(createModel(this));
m_filterModel->setSourceModel(nickModel());
m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
m_ui->filterTreeView->setModel(m_filterModel);
const int columnCount = m_filterModel->columnCount();
......@@ -205,14 +221,15 @@ QString NickNameDialog::nickName() const
const QModelIndex index = m_ui->filterTreeView->selectionModel()->currentIndex();
if (index.isValid()) {
const QModelIndex sourceIndex = m_filterModel->mapToSource(index);
return nickList().at(sourceIndex.row()).nickName();
if (const QStandardItem *item = nickModel()->itemFromIndex(sourceIndex))
return NickNameEntry::nickNameOf(item);
}
return QString();
}
void NickNameDialog::clearNickNames()
{
nickList().clear();
clearModel(nickModel());
}
bool NickNameDialog::readNickNamesFromMailCapFile(const QString &fileName, QString *errorMessage)
......@@ -222,28 +239,30 @@ bool NickNameDialog::readNickNamesFromMailCapFile(const QString &fileName, QStri
*errorMessage = tr("Cannot open '%1': %2").arg(fileName, file.errorString());
return false;
}
QStandardItemModel *model = nickModel();
clearModel(model);
// Split into lines and read
QList<NickEntry> &nl = nickList();
nl.clear();
NickEntry entry;
NickNameEntry entry;
const QStringList lines = QString::fromUtf8(file.readAll()).trimmed().split(QLatin1Char('\n'));
const int count = lines.size();
for (int i = 0; i < count; i++) {
if (entry.parse(lines.at(i))) {
nl.push_back(entry);
model->appendRow(entry.toModelRow());
} else {
qWarning("%s: Invalid mail cap entry at line %d: '%s'\n", qPrintable(fileName), i + 1, qPrintable(lines.at(i)));
}
}
qStableSort(nl);
model->sort(0);
return true;
}
QStringList NickNameDialog::nickNameList()
{
QStringList rc;
foreach(const NickEntry &ne, nickList())
rc.push_back(ne.nickName());
const QStandardItemModel *model = nickModel();
const int rowCount = model->rowCount();
for (int r = 0; r < rowCount; r++)
rc.push_back(NickNameEntry::nickNameOf(model->item(r, 0)));
return rc;
}
......
......@@ -48,7 +48,9 @@ namespace Internal {
* mail cap file, consisting of 4 columns:
* "Name Mail [AliasName [AliasMail]]".
* The names can be used for insertion into "RevBy:" fields; aliases will
* be preferred. */
* be preferred. The static functions to read/clear the mail map
* files access a global model which is shared by all instances of the
* dialog to achieve updating. */
class NickNameDialog : public QDialog {
Q_OBJECT
......
......@@ -47,11 +47,11 @@
<item row="2" column="0">
<widget class="QLabel" name="nickNameMailMapLabel">
<property name="toolTip">
<string>A file listing user names in 2-column mailmap format:
<string>A file listing user names and email addresses in a 4-column mailmap format:
name &lt;email&gt; alias &lt;email&gt;</string>
</property>
<property name="text">
<string>User name file:</string>
<string>User/alias configuration file:</string>
</property>
</widget>
</item>
......
......@@ -115,7 +115,7 @@ VCSBaseSubmitEditor::VCSBaseSubmitEditor(const VCSBaseSubmitEditorParameters *pa
const Internal::VCSBaseSettings settings = Internal::VCSBasePlugin::instance()->settings();
// Add additional context menu settings
if (!settings.submitMessageCheckScript.isEmpty() || !settings.nickNameFieldListFile.isEmpty()) {
if (!settings.submitMessageCheckScript.isEmpty() || !settings.nickNameMailMap.isEmpty()) {
QAction *sep = new QAction(this);
sep->setSeparator(true);
m_d->m_widget->addDescriptionEditContextMenuAction(sep);
......@@ -126,7 +126,7 @@ VCSBaseSubmitEditor::VCSBaseSubmitEditor(const VCSBaseSubmitEditorParameters *pa
m_d->m_widget->addDescriptionEditContextMenuAction(checkAction);
}
// Insert nick
if (!settings.nickNameFieldListFile.isEmpty()) {
if (!settings.nickNameMailMap.isEmpty()) {
QAction *insertAction = new QAction(tr("Insert name..."), this);
connect(insertAction, SIGNAL(triggered()), this, SLOT(slotInsertNickName()));
m_d->m_widget->addDescriptionEditContextMenuAction(insertAction);
......@@ -369,17 +369,22 @@ bool VCSBaseSubmitEditor::setFileContents(const QString &contents)
enum { checkDialogMinimumWidth = 500 };
VCSBaseSubmitEditor::PromptSubmitResult
VCSBaseSubmitEditor::promptSubmit(const QString &title, const QString &question, const QString &checkFailureQuestion) const
VCSBaseSubmitEditor::promptSubmit(const QString &title,
const QString &question,
const QString &checkFailureQuestion,
bool forcePrompt) const
{
QString errorMessage;
QMessageBox::StandardButton answer = QMessageBox::Yes;
const bool prompt = forcePrompt || Internal::VCSBasePlugin::instance()->settings().promptForSubmit;
QWidget *parent = Core::ICore::instance()->mainWindow();
// Pop up a message depending on whether the check succeeded and the
// user wants to be prompted
if (checkSubmitMessage(&errorMessage)) {
// Check ok, do prompt?
if (Internal::VCSBasePlugin::instance()->settings().promptForSubmit) {
if (prompt) {
answer = QMessageBox::question(parent, title, question,
QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel,
QMessageBox::Yes);
......@@ -443,6 +448,14 @@ bool VCSBaseSubmitEditor::checkSubmitMessage(QString *errorMessage) const
const QString checkScript = submitMessageCheckScript();
if (checkScript.isEmpty())
return true;
QApplication::setOverrideCursor(Qt::WaitCursor);
const bool rc = runSubmitMessageCheckScript(checkScript, errorMessage);
QApplication::restoreOverrideCursor();
return rc;
}
bool VCSBaseSubmitEditor::runSubmitMessageCheckScript(const QString &checkScript, QString *errorMessage) const
{
// Write out message
QString tempFilePattern = QDir::tempPath();
if (!tempFilePattern.endsWith(QDir::separator()))
......
......@@ -106,11 +106,14 @@ public:
virtual ~VCSBaseSubmitEditor();
// A utility routine to be called when clsing a submit editor.
// A utility routine to be called when closing a submit editor.
// Runs checks on the message and prompts according to configuration.
// Force prompt should be true if it is invoked by closing an editor
// as opposed to invoking the "Submit" button.
enum PromptSubmitResult { SubmitConfirmed, SubmitCanceled, SubmitDiscarded };
PromptSubmitResult promptSubmit(const QString &title, const QString &question,
const QString &checkFailureQuestion) const;
const QString &checkFailureQuestion,
bool forcePrompt = false) const;
int fileNameColumn() const;
void setFileNameColumn(int c);
......@@ -169,6 +172,7 @@ protected:
private:
void createUserFields(const QString &fieldConfigFile);
bool checkSubmitMessage(QString *errorMessage) const;
bool runSubmitMessageCheckScript(const QString &script, QString *errorMessage) const;
QString promptForNickName();
VCSBaseSubmitEditorPrivate *m_d;
......
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