forked from qt-creator/qt-creator
VCS: Improve dialog on submit prompt
The dialog appears when closing the commit dialog without committing, or when "prompt to submit" setting is enabled. Fixes: QTCREATORBUG-18799 Change-Id: I8eb20becbcee7281b9f673a35ec698c6f8e04a40 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Robert Loehning <robert.loehning@qt.io> Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
committed by
Orgad Shaneh
parent
7d56d89f25
commit
15b176e30c
@@ -635,11 +635,8 @@ bool BazaarPlugin::submitEditorAboutToClose()
|
||||
IDocument *editorDocument = commitEditor->document();
|
||||
QTC_ASSERT(editorDocument, return true);
|
||||
|
||||
bool dummyPrompt = false;
|
||||
const VcsBaseSubmitEditor::PromptSubmitResult response =
|
||||
commitEditor->promptSubmit(tr("Close Commit Editor"), tr("Do you want to commit the changes?"),
|
||||
tr("Message check failed. Do you want to proceed?"),
|
||||
&dummyPrompt, !m_submitActionTriggered);
|
||||
commitEditor->promptSubmit(this, nullptr, !m_submitActionTriggered);
|
||||
m_submitActionTriggered = false;
|
||||
|
||||
switch (response) {
|
||||
|
@@ -593,10 +593,7 @@ bool ClearCasePlugin::submitEditorAboutToClose()
|
||||
// is, the editor was closed or shutdown).
|
||||
bool prompt = m_settings.promptToCheckIn;
|
||||
const VcsBaseSubmitEditor::PromptSubmitResult answer =
|
||||
editor->promptSubmit(tr("Closing ClearCase Editor"),
|
||||
tr("Do you want to check in the files?"),
|
||||
tr("The comment check failed. Do you want to check in the files?"),
|
||||
&prompt, !m_submitActionTriggered);
|
||||
editor->promptSubmit(this, &prompt, !m_submitActionTriggered);
|
||||
m_submitActionTriggered = false;
|
||||
switch (answer) {
|
||||
case VcsBaseSubmitEditor::SubmitCanceled:
|
||||
|
@@ -431,11 +431,8 @@ bool CvsPlugin::submitEditorAboutToClose()
|
||||
|
||||
// Prompt user. Force a prompt unless submit was actually invoked (that
|
||||
// is, the editor was closed or shutdown).
|
||||
const VcsBaseSubmitEditor::PromptSubmitResult answer =
|
||||
editor->promptSubmit(tr("Closing CVS Editor"),
|
||||
tr("Do you want to commit the change?"),
|
||||
tr("The commit message check failed. Do you want to commit the change?"),
|
||||
client()->settings().boolPointer(CvsSettings::promptOnSubmitKey),
|
||||
const VcsBaseSubmitEditor::PromptSubmitResult answer = editor->promptSubmit(
|
||||
this, client()->settings().boolPointer(CvsSettings::promptOnSubmitKey),
|
||||
!m_submitActionTriggered);
|
||||
m_submitActionTriggered = false;
|
||||
switch (answer) {
|
||||
|
@@ -1034,12 +1034,8 @@ bool GitPlugin::submitEditorAboutToClose()
|
||||
return true;
|
||||
// Prompt user. Force a prompt unless submit was actually invoked (that
|
||||
// is, the editor was closed or shutdown).
|
||||
bool promptData = false;
|
||||
const VcsBaseSubmitEditor::PromptSubmitResult answer
|
||||
= editor->promptSubmit(tr("Closing Git Editor"),
|
||||
tr("Do you want to commit the change?"),
|
||||
tr("Git will not accept this commit. Do you want to continue to edit it?"),
|
||||
&promptData, !m_submitActionTriggered, false);
|
||||
= editor->promptSubmit(this, nullptr, !m_submitActionTriggered, false);
|
||||
m_submitActionTriggered = false;
|
||||
switch (answer) {
|
||||
case VcsBaseSubmitEditor::SubmitCanceled:
|
||||
|
@@ -551,11 +551,8 @@ bool MercurialPlugin::submitEditorAboutToClose()
|
||||
Core::IDocument *editorFile = commitEditor->document();
|
||||
QTC_ASSERT(editorFile, return true);
|
||||
|
||||
bool dummyPrompt = false;
|
||||
const VcsBaseSubmitEditor::PromptSubmitResult response =
|
||||
commitEditor->promptSubmit(tr("Close Commit Editor"), tr("Do you want to commit the changes?"),
|
||||
tr("Message check failed. Do you want to proceed?"),
|
||||
&dummyPrompt, !m_submitActionTriggered);
|
||||
commitEditor->promptSubmit(this, nullptr, !m_submitActionTriggered);
|
||||
m_submitActionTriggered = false;
|
||||
|
||||
switch (response) {
|
||||
|
@@ -1310,10 +1310,7 @@ bool PerforcePlugin::submitEditorAboutToClose()
|
||||
// is, the editor was closed or shutdown).
|
||||
bool wantsPrompt = m_settings.promptToSubmit();
|
||||
const 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?"),
|
||||
&wantsPrompt, !m_submitActionTriggered);
|
||||
perforceEditor->promptSubmit(this, &wantsPrompt, !m_submitActionTriggered);
|
||||
m_submitActionTriggered = false;
|
||||
|
||||
if (answer == VcsBaseSubmitEditor::SubmitCanceled)
|
||||
|
@@ -425,11 +425,8 @@ bool SubversionPlugin::submitEditorAboutToClose()
|
||||
// Prompt user. Force a prompt unless submit was actually invoked (that
|
||||
// is, the editor was closed or shutdown).
|
||||
VcsBaseClientSettings &newSettings = client()->settings();
|
||||
const 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?"),
|
||||
newSettings.boolPointer(SubversionSettings::promptOnSubmitKey),
|
||||
const VcsBaseSubmitEditor::PromptSubmitResult answer = editor->promptSubmit(
|
||||
this, newSettings.boolPointer(SubversionSettings::promptOnSubmitKey),
|
||||
!m_submitActionTriggered);
|
||||
m_submitActionTriggered = false;
|
||||
switch (answer) {
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#include "submiteditorwidget.h"
|
||||
#include "submitfieldwidget.h"
|
||||
#include "submitfilemodel.h"
|
||||
#include "vcsbaseplugin.h"
|
||||
#include "vcsoutputwindow.h"
|
||||
#include "vcsplugin.h"
|
||||
#include "vcsprojectcache.h"
|
||||
@@ -58,6 +59,7 @@
|
||||
#include <QFileInfo>
|
||||
#include <QPointer>
|
||||
#include <QProcess>
|
||||
#include <QPushButton>
|
||||
#include <QSet>
|
||||
#include <QStringListModel>
|
||||
#include <QStyle>
|
||||
@@ -523,14 +525,31 @@ void VcsBaseSubmitEditor::setDescriptionMandatory(bool v)
|
||||
|
||||
enum { checkDialogMinimumWidth = 500 };
|
||||
|
||||
static QString withUnusedMnemonic(QString string, const QList<QPushButton *> &otherButtons)
|
||||
{
|
||||
QSet<QChar> mnemonics;
|
||||
for (QPushButton *button : otherButtons) {
|
||||
const QString text = button->text();
|
||||
const int ampersandPos = text.indexOf('&');
|
||||
if (ampersandPos >= 0 && ampersandPos < text.size() - 1)
|
||||
mnemonics.insert(text.at(ampersandPos + 1));
|
||||
}
|
||||
for (int i = 0, total = string.length(); i < total; ++i) {
|
||||
if (!mnemonics.contains(string.at(i)))
|
||||
return string.insert(i, '&');
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
VcsBaseSubmitEditor::PromptSubmitResult
|
||||
VcsBaseSubmitEditor::promptSubmit(const QString &title,
|
||||
const QString &question,
|
||||
const QString &checkFailureQuestion,
|
||||
VcsBaseSubmitEditor::promptSubmit(VcsBasePlugin *plugin,
|
||||
bool *promptSetting,
|
||||
bool forcePrompt,
|
||||
bool canCommitOnFailure)
|
||||
{
|
||||
bool dummySetting = false;
|
||||
if (!promptSetting)
|
||||
promptSetting = &dummySetting;
|
||||
auto submitWidget = static_cast<SubmitEditorWidget *>(this->widget());
|
||||
|
||||
Core::EditorManager::activateEditor(this, Core::EditorManager::IgnoreNavigationHistory);
|
||||
@@ -539,67 +558,52 @@ VcsBaseSubmitEditor::PromptSubmitResult
|
||||
return SubmitDiscarded;
|
||||
|
||||
QString errorMessage;
|
||||
QMessageBox::StandardButton answer = QMessageBox::Yes;
|
||||
|
||||
const bool prompt = forcePrompt || *promptSetting;
|
||||
|
||||
QWidget *parent = Core::ICore::mainWindow();
|
||||
// Pop up a message depending on whether the check succeeded and the
|
||||
// user wants to be prompted
|
||||
bool canCommit = checkSubmitMessage(&errorMessage) && submitWidget->canSubmit(&errorMessage);
|
||||
if (canCommit) {
|
||||
// Check ok, do prompt?
|
||||
if (prompt) {
|
||||
// Provide check box to turn off prompt ONLY if it was not forced
|
||||
if (*promptSetting && !forcePrompt) {
|
||||
const QDialogButtonBox::StandardButton danswer =
|
||||
CheckableMessageBox::question(parent, title, question,
|
||||
tr("Prompt to submit"), promptSetting,
|
||||
QDialogButtonBox::Yes|QDialogButtonBox::No|
|
||||
QDialogButtonBox::Cancel,
|
||||
QDialogButtonBox::Yes);
|
||||
answer = CheckableMessageBox::dialogButtonBoxToMessageBoxButton(danswer);
|
||||
} else {
|
||||
answer = QMessageBox::question(parent, title, question,
|
||||
QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel,
|
||||
QMessageBox::Yes);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Check failed.
|
||||
QMessageBox::StandardButtons buttons;
|
||||
if (canCommitOnFailure)
|
||||
buttons = QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel;
|
||||
else
|
||||
buttons = QMessageBox::Yes|QMessageBox::No;
|
||||
QMessageBox msgBox(QMessageBox::Question, title, checkFailureQuestion,
|
||||
buttons, parent);
|
||||
msgBox.setDefaultButton(QMessageBox::Cancel);
|
||||
msgBox.setInformativeText(errorMessage);
|
||||
msgBox.setMinimumWidth(checkDialogMinimumWidth);
|
||||
answer = static_cast<QMessageBox::StandardButton>(msgBox.exec());
|
||||
}
|
||||
if (!canCommit && !canCommitOnFailure) {
|
||||
switch (answer) {
|
||||
case QMessageBox::No:
|
||||
return SubmitDiscarded;
|
||||
case QMessageBox::Yes:
|
||||
return SubmitCanceled;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (answer) {
|
||||
case QMessageBox::No:
|
||||
return SubmitDiscarded;
|
||||
case QMessageBox::Yes:
|
||||
if (canCommit && !prompt)
|
||||
return SubmitConfirmed;
|
||||
default:
|
||||
break;
|
||||
CheckableMessageBox mb(Core::ICore::dialogParent());
|
||||
const QString commitName = plugin->commitDisplayName();
|
||||
mb.setWindowTitle(tr("Close %1 %2 Editor")
|
||||
.arg(plugin->versionControl()->displayName(), commitName));
|
||||
mb.setIconPixmap(QMessageBox::standardIcon(QMessageBox::Question));
|
||||
QString message;
|
||||
if (canCommit) {
|
||||
message = tr("What do you want to do with these changes?");
|
||||
} else {
|
||||
message = tr("Cannot %1%2.\nWhat do you want to do?",
|
||||
"%2 is an optional error message with ': ' prefix. Do not separate it from %1.")
|
||||
.arg(commitName.toLower(),
|
||||
errorMessage.isEmpty() ? errorMessage : ": " + errorMessage);
|
||||
}
|
||||
mb.setText(message);
|
||||
mb.setCheckBoxText(tr("Prompt to %1").arg(commitName.toLower()));
|
||||
mb.setChecked(*promptSetting);
|
||||
// Provide check box to turn off prompt ONLY if it was not forced
|
||||
mb.setCheckBoxVisible(*promptSetting && !forcePrompt);
|
||||
QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Close | QDialogButtonBox::Cancel;
|
||||
if (canCommit || canCommitOnFailure)
|
||||
buttons |= QDialogButtonBox::Ok;
|
||||
mb.setStandardButtons(buttons);
|
||||
QPushButton *cancelButton = mb.button(QDialogButtonBox::Cancel);
|
||||
cancelButton->setText(tr("&Keep Editing"));
|
||||
cancelButton->setDefault(true);
|
||||
if (QPushButton *commitButton = mb.button(QDialogButtonBox::Ok)) {
|
||||
commitButton->setText(withUnusedMnemonic(commitName,
|
||||
{cancelButton, mb.button(QDialogButtonBox::Close)}));
|
||||
}
|
||||
|
||||
if (mb.exec() == QDialog::Accepted)
|
||||
*promptSetting = mb.isChecked();
|
||||
QAbstractButton *chosen = mb.clickedButton();
|
||||
if (!chosen || chosen == cancelButton)
|
||||
return SubmitCanceled;
|
||||
if (chosen == mb.button(QDialogButtonBox::Close))
|
||||
return SubmitDiscarded;
|
||||
return SubmitConfirmed;
|
||||
}
|
||||
|
||||
QString VcsBaseSubmitEditor::promptForNickName()
|
||||
|
@@ -46,6 +46,7 @@ namespace Internal {
|
||||
|
||||
class SubmitEditorWidget;
|
||||
class SubmitFileModel;
|
||||
class VcsBasePlugin;
|
||||
class VcsBaseSubmitEditorPrivate;
|
||||
|
||||
class VCSBASE_EXPORT VcsBaseSubmitEditorParameters
|
||||
@@ -84,8 +85,7 @@ public:
|
||||
// 'promptSetting' points to a bool variable containing the plugin's
|
||||
// prompt setting. The user can uncheck it from the message box.
|
||||
enum PromptSubmitResult { SubmitConfirmed, SubmitCanceled, SubmitDiscarded };
|
||||
PromptSubmitResult promptSubmit(const QString &title, const QString &question,
|
||||
const QString &checkFailureQuestion,
|
||||
PromptSubmitResult promptSubmit(VcsBasePlugin *plugin,
|
||||
bool *promptSetting,
|
||||
bool forcePrompt = false,
|
||||
bool canCommitOnFailure = true);
|
||||
|
Reference in New Issue
Block a user