forked from qt-creator/qt-creator
Make "Reset warnings" option reset "Do not ask again" messages.
And unify them. Task-number: QTCREATORBUG-10523 Change-Id: I1e1262ff25f51e6068e16adaeb25d553f9bffb1f Reviewed-by: hjk <hjk121@nokiamail.com> Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
@@ -28,12 +28,14 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "checkablemessagebox.h"
|
||||
#include "qtcassert.h"
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QApplication>
|
||||
#include <QCheckBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QDebug>
|
||||
#include <QPushButton>
|
||||
#include <QSettings>
|
||||
|
||||
/*!
|
||||
\class Utils::CheckableMessageBox
|
||||
@@ -46,6 +48,8 @@
|
||||
static conveniences. The message label can open external URLs.
|
||||
*/
|
||||
|
||||
static const char kDoNotAskAgainKey[] = "DoNotAskAgain";
|
||||
|
||||
namespace Utils {
|
||||
|
||||
class CheckableMessageBoxPrivate
|
||||
@@ -283,4 +287,94 @@ QMessageBox::StandardButton CheckableMessageBox::dialogButtonBoxToMessageBoxButt
|
||||
return static_cast<QMessageBox::StandardButton>(int(db));
|
||||
}
|
||||
|
||||
/*!
|
||||
Shows a message box with given \a title and \a text, and a \gui {Do not ask again} check box.
|
||||
If the user checks the check box and accepts the dialog with the \a acceptButton,
|
||||
further invocations of this function with the same \a settings and \a settingsSubKey will not
|
||||
show the dialog, but instantly return \a acceptButton.
|
||||
|
||||
Returns the clicked button, or QDialogButtonBox::NoButton if the user rejects the dialog
|
||||
with the escape key, or \a acceptButton if the dialog is suppressed.
|
||||
*/
|
||||
QDialogButtonBox::StandardButton
|
||||
CheckableMessageBox::doNotAskAgainQuestion(QWidget *parent, const QString &title,
|
||||
const QString &text, QSettings *settings,
|
||||
const QString &settingsSubKey,
|
||||
QDialogButtonBox::StandardButtons buttons,
|
||||
QDialogButtonBox::StandardButton defaultButton,
|
||||
QDialogButtonBox::StandardButton acceptButton)
|
||||
|
||||
{
|
||||
QTC_CHECK(settings);
|
||||
if (settings) {
|
||||
settings->beginGroup(QLatin1String(kDoNotAskAgainKey));
|
||||
bool shouldNotAsk = settings->value(settingsSubKey, false).toBool();
|
||||
settings->endGroup();
|
||||
if (shouldNotAsk)
|
||||
return acceptButton;
|
||||
}
|
||||
|
||||
CheckableMessageBox mb(parent);
|
||||
mb.setWindowTitle(title);
|
||||
mb.setIconPixmap(QMessageBox::standardIcon(QMessageBox::Question));
|
||||
mb.setText(text);
|
||||
mb.setCheckBoxVisible(true);
|
||||
mb.setCheckBoxText(CheckableMessageBox::msgDoNotAskAgain());
|
||||
mb.setChecked(false);
|
||||
mb.setStandardButtons(buttons);
|
||||
mb.setDefaultButton(defaultButton);
|
||||
mb.exec();
|
||||
|
||||
if (settings) {
|
||||
settings->beginGroup(QLatin1String(kDoNotAskAgainKey));
|
||||
if (mb.isChecked() && (mb.clickedStandardButton() == acceptButton))
|
||||
settings->setValue(settingsSubKey, true);
|
||||
else // clean up doesn't hurt
|
||||
settings->remove(settingsSubKey);
|
||||
settings->endGroup();
|
||||
}
|
||||
return mb.clickedStandardButton();
|
||||
}
|
||||
|
||||
/*!
|
||||
Resets all suppression settings for doNotAskAgainQuestion() found in \a settings,
|
||||
so all these message boxes are shown again.
|
||||
*/
|
||||
void CheckableMessageBox::resetAllDoNotAskAgainQuestions(QSettings *settings)
|
||||
{
|
||||
QTC_ASSERT(settings, return);
|
||||
settings->beginGroup(QLatin1String(kDoNotAskAgainKey));
|
||||
foreach (const QString &subKey, settings->childKeys())
|
||||
settings->remove(subKey);
|
||||
settings->endGroup();
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns whether any message boxes from doNotAskAgainQuestion() are suppressed
|
||||
in the \a settings.
|
||||
*/
|
||||
bool CheckableMessageBox::hasSuppressedQuestions(QSettings *settings)
|
||||
{
|
||||
QTC_ASSERT(settings, return false);
|
||||
bool hasSuppressed = false;
|
||||
settings->beginGroup(QLatin1String(kDoNotAskAgainKey));
|
||||
foreach (const QString &subKey, settings->childKeys()) {
|
||||
if (settings->value(subKey, false).toBool()) {
|
||||
hasSuppressed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
settings->endGroup();
|
||||
return hasSuppressed;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the standard \gui {Do not ask again} check box text.
|
||||
\sa doNotAskAgainQuestion()
|
||||
*/
|
||||
QString CheckableMessageBox::msgDoNotAskAgain()
|
||||
{
|
||||
return QApplication::translate("Utils::CheckableMessageBox", "Do not &ask again");
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
@@ -35,6 +35,10 @@
|
||||
#include <QDialogButtonBox>
|
||||
#include <QMessageBox>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QSettings;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Utils {
|
||||
|
||||
class CheckableMessageBoxPrivate;
|
||||
@@ -71,6 +75,16 @@ public:
|
||||
QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Ok,
|
||||
QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::NoButton);
|
||||
|
||||
static QDialogButtonBox::StandardButton
|
||||
doNotAskAgainQuestion(QWidget *parent,
|
||||
const QString &title,
|
||||
const QString &text,
|
||||
QSettings *settings,
|
||||
const QString &settingsSubKey,
|
||||
QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Yes|QDialogButtonBox::No,
|
||||
QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::No,
|
||||
QDialogButtonBox::StandardButton acceptButton = QDialogButtonBox::Yes);
|
||||
|
||||
QString text() const;
|
||||
void setText(const QString &);
|
||||
|
||||
@@ -101,6 +115,9 @@ public:
|
||||
|
||||
// Conversion convenience
|
||||
static QMessageBox::StandardButton dialogButtonBoxToMessageBoxButton(QDialogButtonBox::StandardButton);
|
||||
static void resetAllDoNotAskAgainQuestions(QSettings *settings);
|
||||
static bool hasSuppressedQuestions(QSettings *settings);
|
||||
static QString msgDoNotAskAgain();
|
||||
|
||||
private slots:
|
||||
void slotClicked(QAbstractButton *b);
|
||||
|
@@ -295,19 +295,12 @@ void BookmarkView::keyPressEvent(QKeyEvent *event)
|
||||
|
||||
void BookmarkView::removeAll()
|
||||
{
|
||||
const QString key = QLatin1String("Bookmarks.DontAskAgain");
|
||||
QSettings *settings = ICore::settings();
|
||||
bool checked = settings->value(key).toBool();
|
||||
if (!checked) {
|
||||
if (Utils::CheckableMessageBox::question(this,
|
||||
if (Utils::CheckableMessageBox::doNotAskAgainQuestion(this,
|
||||
tr("Remove All Bookmarks"),
|
||||
tr("Are you sure you want to remove all bookmarks from all files in the current session?"),
|
||||
tr("Do not &ask again."),
|
||||
&checked, QDialogButtonBox::Yes | QDialogButtonBox::No, QDialogButtonBox::No)
|
||||
!= QDialogButtonBox::Yes)
|
||||
ICore::settings(),
|
||||
QLatin1String("RemoveAllBookmarks")) != QDialogButtonBox::Yes)
|
||||
return;
|
||||
settings->setValue(key, checked);
|
||||
}
|
||||
|
||||
// The performance of this function could be greatly improved.
|
||||
while (m_manager->rowCount()) {
|
||||
|
@@ -33,9 +33,10 @@
|
||||
#include "infobar.h"
|
||||
#include "editormanager/editormanager.h"
|
||||
|
||||
#include <utils/checkablemessagebox.h>
|
||||
#include <utils/consoleprocess.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/stylehelper.h>
|
||||
#include <utils/consoleprocess.h>
|
||||
#include <utils/unixutils.h>
|
||||
|
||||
#include <QMessageBox>
|
||||
@@ -137,7 +138,8 @@ QWidget *GeneralSettings::createPage(QWidget *parent)
|
||||
|
||||
m_page->autoSaveCheckBox->setChecked(EditorManager::autoSaveEnabled());
|
||||
m_page->autoSaveInterval->setValue(EditorManager::autoSaveInterval());
|
||||
m_page->resetWarningsButton->setEnabled(Core::InfoBar::anyGloballySuppressed());
|
||||
m_page->resetWarningsButton->setEnabled(Core::InfoBar::anyGloballySuppressed()
|
||||
|| Utils::CheckableMessageBox::hasSuppressedQuestions(ICore::settings()));
|
||||
|
||||
connect(m_page->resetColorButton, SIGNAL(clicked()),
|
||||
this, SLOT(resetInterfaceColor()));
|
||||
@@ -208,6 +210,7 @@ void GeneralSettings::resetInterfaceColor()
|
||||
void GeneralSettings::resetWarnings()
|
||||
{
|
||||
Core::InfoBar::clearGloballySuppressed();
|
||||
Utils::CheckableMessageBox::resetAllDoNotAskAgainQuestions(ICore::settings());
|
||||
m_page->resetWarningsButton->setEnabled(false);
|
||||
}
|
||||
|
||||
|
@@ -34,6 +34,7 @@
|
||||
#include "debuggercore.h"
|
||||
|
||||
#include <coreplugin/mainwindow.h>
|
||||
#include <utils/checkablemessagebox.h>
|
||||
#include <utils/pathchooser.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/savedaction.h>
|
||||
@@ -866,11 +867,12 @@ void BreakTreeView::setBreakpointsEnabled(const BreakpointModelIds &ids, bool en
|
||||
|
||||
void BreakTreeView::deleteAllBreakpoints()
|
||||
{
|
||||
if (QMessageBox::warning(Core::ICore::mainWindow(),
|
||||
if (Utils::CheckableMessageBox::doNotAskAgainQuestion(Core::ICore::mainWindow(),
|
||||
tr("Remove All Breakpoints"),
|
||||
tr("Are you sure you want to remove all breakpoints "
|
||||
"from all files in the current session?"),
|
||||
QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes)
|
||||
Core::ICore::settings(),
|
||||
QLatin1String("RemoveAllBreakpoints")) == QDialogButtonBox::Yes)
|
||||
deleteBreakpoints(breakHandler()->allBreakpointIds());
|
||||
}
|
||||
|
||||
|
@@ -617,7 +617,7 @@ bool RunControl::showPromptToStopDialog(const QString &title,
|
||||
messageBox.button(QDialogButtonBox::Cancel)->setText(cancelButtonText);
|
||||
messageBox.setDefaultButton(QDialogButtonBox::Yes);
|
||||
if (prompt) {
|
||||
messageBox.setCheckBoxText(tr("Do not ask again"));
|
||||
messageBox.setCheckBoxText(Utils::CheckableMessageBox::msgDoNotAskAgain());
|
||||
messageBox.setChecked(false);
|
||||
} else {
|
||||
messageBox.setCheckBoxVisible(false);
|
||||
|
@@ -102,12 +102,6 @@ static void startLocalTool(IAnalyzerTool *tool)
|
||||
? AnalyzerManager::tr("Debug")
|
||||
: AnalyzerManager::tr("Release");
|
||||
|
||||
QSettings *settings = ICore::settings();
|
||||
const QString configKey = QLatin1String("Analyzer.AnalyzeCorrectMode");
|
||||
int ret;
|
||||
if (settings->contains(configKey)) {
|
||||
ret = settings->value(configKey, QDialog::Accepted).toInt();
|
||||
} else {
|
||||
QString toolModeString;
|
||||
switch (tool->toolMode()) {
|
||||
case IAnalyzerTool::DebugMode:
|
||||
@@ -130,19 +124,10 @@ static void startLocalTool(IAnalyzerTool *tool)
|
||||
"may not be relevant for the other.</p><p>"
|
||||
"Do you want to continue and run the tool in %2 mode?</p></body></html>")
|
||||
.arg(toolName).arg(currentMode).arg(toolModeString);
|
||||
const QString checkBoxText = AnalyzerManager::tr("&Do not ask again");
|
||||
bool checkBoxSetting = false;
|
||||
const QDialogButtonBox::StandardButton button =
|
||||
Utils::CheckableMessageBox::question(ICore::mainWindow(),
|
||||
title, message, checkBoxText,
|
||||
&checkBoxSetting, QDialogButtonBox::Yes|QDialogButtonBox::Cancel,
|
||||
QDialogButtonBox::Cancel);
|
||||
ret = button == QDialogButtonBox::Yes ? QDialog::Accepted : QDialog::Rejected;
|
||||
|
||||
if (checkBoxSetting && ret == QDialog::Accepted)
|
||||
settings->setValue(configKey, ret);
|
||||
}
|
||||
if (ret == QDialog::Rejected)
|
||||
if (Utils::CheckableMessageBox::doNotAskAgainQuestion(ICore::mainWindow(),
|
||||
title, message, ICore::settings(), QLatin1String("AnalyzerCorrectModeWarning"),
|
||||
QDialogButtonBox::Yes|QDialogButtonBox::Cancel,
|
||||
QDialogButtonBox::Cancel, QDialogButtonBox::Yes) != QDialogButtonBox::Yes)
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user