Commit 2508fa03 authored by Friedemann Kleint's avatar Friedemann Kleint

Make the "prompt to submit" setting a per-plugin one.

Provide a checkable message box to be able to turn
prompting off when asked.
parent e0550561
#include "checkablemessagebox.h"
#include "ui_checkablemessagebox.h"
#include <QtGui/QPushButton>
#include <QtCore/QDebug>
namespace Core {
namespace Utils {
struct CheckableMessageBoxPrivate {
CheckableMessageBoxPrivate() : clickedButton(0) {}
Ui::CheckableMessageBox ui;
QAbstractButton *clickedButton;
};
CheckableMessageBox::CheckableMessageBox(QWidget *parent) :
QDialog(parent),
m_d(new CheckableMessageBoxPrivate)
{
setModal(true);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
m_d->ui.setupUi(this);
m_d->ui.pixmapLabel->setVisible(false);
connect(m_d->ui.buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(m_d->ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
connect(m_d->ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(slotClicked(QAbstractButton*)));
}
CheckableMessageBox::~CheckableMessageBox()
{
delete m_d;
}
void CheckableMessageBox::slotClicked(QAbstractButton *b)
{
m_d->clickedButton = b;
}
QAbstractButton *CheckableMessageBox::clickedButton() const
{
return m_d->clickedButton;
}
QDialogButtonBox::StandardButton CheckableMessageBox::clickedStandardButton() const
{
if (m_d->clickedButton)
return m_d->ui.buttonBox->standardButton(m_d->clickedButton);
return QDialogButtonBox::NoButton;
}
QString CheckableMessageBox::text() const
{
return m_d->ui.messageLabel->text();
}
void CheckableMessageBox::setText(const QString &t)
{
m_d->ui.messageLabel->setText(t);
}
QPixmap CheckableMessageBox::iconPixmap() const
{
if (const QPixmap *p = m_d->ui.pixmapLabel->pixmap())
return QPixmap(*p);
return QPixmap();
}
void CheckableMessageBox::setIconPixmap(const QPixmap &p)
{
m_d->ui.pixmapLabel->setPixmap(p);
m_d->ui.pixmapLabel->setVisible(!p.isNull());
}
bool CheckableMessageBox::isChecked() const
{
return m_d->ui.checkBox->isChecked();
}
void CheckableMessageBox::setChecked(bool s)
{
m_d->ui.checkBox->setChecked(s);
}
QString CheckableMessageBox::checkBoxText() const
{
return m_d->ui.checkBox->text();
}
void CheckableMessageBox::setCheckBoxText(const QString &t)
{
m_d->ui.checkBox->setText(t);
}
QDialogButtonBox::StandardButtons CheckableMessageBox::standardButtons() const
{
return m_d->ui.buttonBox->standardButtons();
}
void CheckableMessageBox::setStandardButtons(QDialogButtonBox::StandardButtons s)
{
m_d->ui.buttonBox->setStandardButtons(s);
}
QDialogButtonBox::StandardButton CheckableMessageBox::defaultButton() const
{
foreach (QAbstractButton *b, m_d->ui.buttonBox->buttons())
if (QPushButton *pb = qobject_cast<QPushButton *>(b))
if (pb->isDefault())
return m_d->ui.buttonBox->standardButton(pb);
return QDialogButtonBox::NoButton;
}
void CheckableMessageBox::setDefaultButton(QDialogButtonBox::StandardButton s)
{
if (QPushButton *b = m_d->ui.buttonBox->button(s)) {
b->setDefault(true);
b->setFocus();
}
}
QDialogButtonBox::StandardButton
CheckableMessageBox::question(QWidget *parent,
const QString &title,
const QString &question,
const QString &checkBoxText,
bool *checkBoxSetting,
QDialogButtonBox::StandardButtons buttons,
QDialogButtonBox::StandardButton defaultButton)
{
CheckableMessageBox mb(parent);
mb.setWindowTitle(title);
mb.setIconPixmap(QMessageBox::standardIcon(QMessageBox::Question));
mb.setText(question);
mb.setCheckBoxText(checkBoxText);
mb.setChecked(*checkBoxSetting);
mb.setStandardButtons(buttons);
mb.setDefaultButton(defaultButton);
mb.exec();
*checkBoxSetting = mb.isChecked();
return mb.clickedStandardButton();
}
QMessageBox::StandardButton CheckableMessageBox::dialogButtonBoxToMessageBoxButton(QDialogButtonBox::StandardButton db)
{
return static_cast<QMessageBox::StandardButton>(int(db));
}
} // namespace Utils
} // namespace Core
#ifndef CHECKABLEMESSAGEBOX_H
#define CHECKABLEMESSAGEBOX_H
#include "utils_global.h"
#include <QtGui/QDialogButtonBox>
#include <QtGui/QMessageBox>
#include <QtGui/QDialog>
namespace Core {
namespace Utils {
struct CheckableMessageBoxPrivate;
/* A messagebox suitable for questions with a
* "Do not ask me again" checkbox. Emulates the QMessageBox API with
* static conveniences. */
class QTCREATOR_UTILS_EXPORT CheckableMessageBox : public QDialog
{
Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(QPixmap iconPixmap READ iconPixmap WRITE setIconPixmap)
Q_PROPERTY(bool isChecked READ isChecked WRITE setChecked)
Q_PROPERTY(QString checkBoxText READ checkBoxText WRITE setCheckBoxText)
Q_PROPERTY(QDialogButtonBox::StandardButtons buttons READ standardButtons WRITE setStandardButtons)
Q_PROPERTY(QDialogButtonBox::StandardButton defaultButton READ defaultButton WRITE setDefaultButton)
public:
explicit CheckableMessageBox(QWidget *parent);
virtual ~CheckableMessageBox();
static QDialogButtonBox::StandardButton
question(QWidget *parent,
const QString &title,
const QString &question,
const QString &checkBoxText,
bool *checkBoxSetting,
QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Yes|QDialogButtonBox::No,
QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::No);
QString text() const;
void setText(const QString &);
bool isChecked() const;
void setChecked(bool s);
QString checkBoxText() const;
void setCheckBoxText(const QString &);
QDialogButtonBox::StandardButtons standardButtons() const;
void setStandardButtons(QDialogButtonBox::StandardButtons s);
QDialogButtonBox::StandardButton defaultButton() const;
void setDefaultButton(QDialogButtonBox::StandardButton s);
// see static QMessageBox::standardPixmap()
QPixmap iconPixmap() const;
void setIconPixmap (const QPixmap &p);
// Query the result
QAbstractButton *clickedButton() const;
QDialogButtonBox::StandardButton clickedStandardButton() const;
// Conversion convenience
static QMessageBox::StandardButton dialogButtonBoxToMessageBoxButton(QDialogButtonBox::StandardButton);
private slots:
void slotClicked(QAbstractButton *b);
private:
CheckableMessageBoxPrivate *m_d;
};
} // namespace Utils
} // namespace Core
#endif // CHECKABLEMESSAGEBOX_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Core::Utils::CheckableMessageBox</class>
<widget class="QDialog" name="Core::Utils::CheckableMessageBox">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>195</width>
<height>107</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="pixmapLabel"/>
</item>
<item>
<spacer name="pixmapSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="messageLabel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="checkBoxLeftSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
<item>
<spacer name="checkBoxRightSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="buttonSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Core::Utils::CheckableMessageBox</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Core::Utils::CheckableMessageBox</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
......@@ -28,7 +28,8 @@ SOURCES += reloadpromptutils.cpp \
consoleprocess.cpp \
uncommentselection.cpp \
parameteraction.cpp \
treewidgetcolumnstretcher.cpp
treewidgetcolumnstretcher.cpp \
checkablemessagebox.cpp
win32 {
SOURCES += abstractprocess_win.cpp \
consoleprocess_win.cpp \
......@@ -63,9 +64,11 @@ HEADERS += utils_global.h \
submitfieldwidget.h \
uncommentselection.h \
parameteraction.h \
treewidgetcolumnstretcher.h
treewidgetcolumnstretcher.h \
checkablemessagebox.h
FORMS += filewizardpage.ui \
projectintropage.ui \
newclasswidget.ui \
submiteditorwidget.ui
submiteditorwidget.ui \
checkablemessagebox.ui
RESOURCES += utils.qrc
......@@ -690,12 +690,14 @@ bool GitPlugin::editorAboutToClose(Core::IEditor *iEditor)
return true;
// Prompt user. Force a prompt unless submit was actually invoked (that
// is, the editor was closed or shutdown).
GitSettings settings = m_gitClient->settings();
const bool wantedPrompt = settings.promptToSubmit;
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?"),
!m_submitActionTriggered);
m_submitActionTriggered = false;
&settings.promptToSubmit, !m_submitActionTriggered);
m_submitActionTriggered = false;
switch (answer) {
case VCSBase::VCSBaseSubmitEditor::SubmitCanceled:
return false; // Keep editing and change file
......@@ -705,6 +707,8 @@ bool GitPlugin::editorAboutToClose(Core::IEditor *iEditor)
default:
break;
}
if (wantedPrompt != settings.promptToSubmit)
m_gitClient->setSettings(settings);
// Go ahead!
const QStringList fileList = editor->checkedFiles();
if (Git::Constants::debug)
......
......@@ -41,6 +41,7 @@ static const char *sysEnvKeyC = "SysEnv";
static const char *pathKeyC = "Path";
static const char *logCountKeyC = "LogCount";
static const char *timeoutKeyC = "TimeOut";
static const char *promptToSubmitKeyC = "PromptForSubmit";
enum { defaultLogCount = 10 , defaultTimeOut = 30};
......@@ -50,7 +51,8 @@ namespace Internal {
GitSettings::GitSettings() :
adoptPath(false),
logCount(defaultLogCount),
timeout(defaultTimeOut)
timeout(defaultTimeOut),
promptToSubmit(true)
{
}
......@@ -61,6 +63,7 @@ void GitSettings::fromSettings(QSettings *settings)
path = settings->value(QLatin1String(pathKeyC), QString()).toString();
logCount = settings->value(QLatin1String(logCountKeyC), defaultLogCount).toInt();
timeout = settings->value(QLatin1String(timeoutKeyC), defaultTimeOut).toInt();
promptToSubmit = settings->value(QLatin1String(promptToSubmitKeyC), true).toBool();
settings->endGroup();
}
......@@ -71,12 +74,14 @@ void GitSettings::toSettings(QSettings *settings) const
settings->setValue(QLatin1String(pathKeyC), path);
settings->setValue(QLatin1String(logCountKeyC), logCount);
settings->setValue(QLatin1String(timeoutKeyC), timeout);
settings->setValue(QLatin1String(promptToSubmitKeyC), promptToSubmit);
settings->endGroup();
}
bool GitSettings::equals(const GitSettings &s) const
{
return adoptPath == s.adoptPath && path == s.path && logCount == s.logCount && timeout == s.timeout;
return adoptPath == s.adoptPath && path == s.path && logCount == s.logCount
&& timeout == s.timeout && promptToSubmit == s.promptToSubmit;
}
QString GitSettings::gitBinaryPath(bool *ok, QString *errorMessage) const
......
......@@ -55,6 +55,7 @@ struct GitSettings
QString path;
int logCount;
int timeout;
bool promptToSubmit;
};
inline bool operator==(const GitSettings &p1, const GitSettings &p2)
......
......@@ -54,6 +54,7 @@ GitSettings SettingsPageWidget::settings() const
rc.adoptPath = m_ui.environmentGroupBox->isChecked() && !rc.path.isEmpty();
rc.logCount = m_ui.logCountSpinBox->value();
rc.timeout = m_ui.timeoutSpinBox->value();
rc.promptToSubmit = m_ui.promptToSubmitCheckBox->isChecked();
return rc;
}
......@@ -63,6 +64,7 @@ void SettingsPageWidget::setSettings(const GitSettings &s)
m_ui.pathLineEdit->setText(s.path);
m_ui.logCountSpinBox->setValue(s.logCount);
m_ui.timeoutSpinBox->setValue(s.timeout);
m_ui.promptToSubmitCheckBox->setChecked(s.promptToSubmit);
}
void SettingsPageWidget::setSystemPath()
......
......@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>403</width>
<width>409</width>
<height>251</height>
</rect>
</property>
......@@ -104,6 +104,13 @@
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="promptToSubmitCheckBox">
<property name="text">
<string>Prompt to submit</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
......
......@@ -930,20 +930,26 @@ bool PerforcePlugin::editorAboutToClose(Core::IEditor *editor)
if (!perforceEditor)
return true;
QFileInfo editorFile(fileIFace->fileName());
QFileInfo changeFile(m_changeTmpFile->fileName());
QFileInfo changeFile(m_changeTmpFile->fileName());
if (editorFile.absoluteFilePath() == changeFile.absoluteFilePath()) {
// Prompt the user. Force a prompt unless submit was actually invoked (that
// is, the editor was closed or shutdown).
bool wantsPrompt = m_settings.promptToSubmit();
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"),
!m_submitActionTriggered);
&wantsPrompt, !m_submitActionTriggered);
m_submitActionTriggered = false;
if (answer == VCSBase::VCSBaseSubmitEditor::SubmitCanceled)
return false;
// Set without triggering the checking mechanism
if (wantsPrompt != m_settings.promptToSubmit()) {
m_settings.setPromptToSubmit(wantsPrompt);
m_settings.toSettings(Core::ICore::instance()->settings());
}
core->fileManager()->blockFileChange(fileIFace);
fileIFace->save();
core->fileManager()->unblockFileChange(fileIFace);
......
......@@ -44,6 +44,7 @@ static const char *defaultKeyC = "Default";
static const char *portKeyC = "Port";
static const char *clientKeyC = "Client";
static const char *userKeyC = "User";
static const char *promptToSubmitKeyC = "PromptForSubmit";
static QString defaultCommand()
{
......@@ -59,7 +60,8 @@ namespace Perforce {
namespace Internal {
Settings::Settings() :
defaultEnv(true)
defaultEnv(true),
promptToSubmit(true)
{
}
......@@ -67,7 +69,8 @@ bool Settings::equals(const Settings &rhs) const
{
return defaultEnv == rhs.defaultEnv
&& p4Command == rhs.p4Command && p4Port == rhs.p4Port
&& p4Client == rhs.p4Client && p4User == rhs.p4User;
&& p4Client == rhs.p4Client && p4User == rhs.p4User
&& promptToSubmit == rhs.promptToSubmit;
};
QStringList Settings::basicP4Args() const
......@@ -188,6 +191,7 @@ void PerforceSettings::fromSettings(QSettings *settings)
m_settings.p4Port = settings->value(QLatin1String(portKeyC), QString()).toString();
m_settings.p4Client = settings->value(QLatin1String(clientKeyC), QString()).toString();
m_settings.p4User = settings->value(QLatin1String(userKeyC), QString()).toString();
m_settings.promptToSubmit = settings->value(QLatin1String(promptToSubmitKeyC), true).toBool();
settings->endGroup();
m_mutex.unlock();
......@@ -198,11 +202,12 @@ void PerforceSettings::toSettings(QSettings *settings) const
{
m_mutex.lock();
settings->beginGroup(QLatin1String(groupC));
settings->setValue(commandKeyC, m_settings.p4Command);
settings->setValue(defaultKeyC, m_settings.defaultEnv);
settings->setValue(portKeyC, m_settings.p4Port);
settings->setValue(clientKeyC, m_settings.p4Client);
settings->setValue(userKeyC, m_settings.p4User);
settings->setValue(QLatin1String(commandKeyC), m_settings.p4Command);
settings->setValue(QLatin1String(defaultKeyC), m_settings.defaultEnv);
settings->setValue(QLatin1String(portKeyC), m_settings.p4Port);
settings->setValue(QLatin1String(clientKeyC), m_settings.p4Client);
settings->setValue(QLatin1String(userKeyC), m_settings.p4User);
settings->setValue(QLatin1String(promptToSubmitKeyC), m_settings.promptToSubmit);
settings->endGroup();
m_mutex.unlock();
}
......@@ -249,6 +254,16 @@ bool PerforceSettings::defaultEnv() const
return m_settings.defaultEnv;
}
bool PerforceSettings::promptToSubmit() const
{
return m_settings.promptToSubmit;
}
void PerforceSettings::setPromptToSubmit(bool p)
{
m_settings.promptToSubmit = p;
}
QString PerforceSettings::errorString() const
{
m_mutex.lock();
......
......@@ -54,6 +54,7 @@ struct Settings {
QString p4User;
QString errorString;
bool defaultEnv;
bool promptToSubmit;
};
inline bool operator==(const Settings &s1, const Settings &s2) { return s1.equals(s2); }
......@@ -81,6 +82,9 @@ public: