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:
Eike Ziller
2013-10-31 15:39:49 +01:00
parent 949bd42399
commit 36f149342d
7 changed files with 154 additions and 60 deletions

View File

@@ -28,12 +28,14 @@
****************************************************************************/ ****************************************************************************/
#include "checkablemessagebox.h" #include "checkablemessagebox.h"
#include "qtcassert.h"
#include <QPushButton> #include <QApplication>
#include <QCheckBox> #include <QCheckBox>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QLabel> #include <QLabel>
#include <QDebug> #include <QPushButton>
#include <QSettings>
/*! /*!
\class Utils::CheckableMessageBox \class Utils::CheckableMessageBox
@@ -46,6 +48,8 @@
static conveniences. The message label can open external URLs. static conveniences. The message label can open external URLs.
*/ */
static const char kDoNotAskAgainKey[] = "DoNotAskAgain";
namespace Utils { namespace Utils {
class CheckableMessageBoxPrivate class CheckableMessageBoxPrivate
@@ -283,4 +287,94 @@ QMessageBox::StandardButton CheckableMessageBox::dialogButtonBoxToMessageBoxButt
return static_cast<QMessageBox::StandardButton>(int(db)); 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 } // namespace Utils

View File

@@ -35,6 +35,10 @@
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QMessageBox> #include <QMessageBox>
QT_BEGIN_NAMESPACE
class QSettings;
QT_END_NAMESPACE
namespace Utils { namespace Utils {
class CheckableMessageBoxPrivate; class CheckableMessageBoxPrivate;
@@ -71,6 +75,16 @@ public:
QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Ok, QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Ok,
QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::NoButton); 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; QString text() const;
void setText(const QString &); void setText(const QString &);
@@ -101,6 +115,9 @@ public:
// Conversion convenience // Conversion convenience
static QMessageBox::StandardButton dialogButtonBoxToMessageBoxButton(QDialogButtonBox::StandardButton); static QMessageBox::StandardButton dialogButtonBoxToMessageBoxButton(QDialogButtonBox::StandardButton);
static void resetAllDoNotAskAgainQuestions(QSettings *settings);
static bool hasSuppressedQuestions(QSettings *settings);
static QString msgDoNotAskAgain();
private slots: private slots:
void slotClicked(QAbstractButton *b); void slotClicked(QAbstractButton *b);

View File

@@ -295,19 +295,12 @@ void BookmarkView::keyPressEvent(QKeyEvent *event)
void BookmarkView::removeAll() void BookmarkView::removeAll()
{ {
const QString key = QLatin1String("Bookmarks.DontAskAgain"); if (Utils::CheckableMessageBox::doNotAskAgainQuestion(this,
QSettings *settings = ICore::settings(); tr("Remove All Bookmarks"),
bool checked = settings->value(key).toBool(); tr("Are you sure you want to remove all bookmarks from all files in the current session?"),
if (!checked) { ICore::settings(),
if (Utils::CheckableMessageBox::question(this, QLatin1String("RemoveAllBookmarks")) != QDialogButtonBox::Yes)
tr("Remove All Bookmarks"), return;
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)
return;
settings->setValue(key, checked);
}
// The performance of this function could be greatly improved. // The performance of this function could be greatly improved.
while (m_manager->rowCount()) { while (m_manager->rowCount()) {

View File

@@ -33,9 +33,10 @@
#include "infobar.h" #include "infobar.h"
#include "editormanager/editormanager.h" #include "editormanager/editormanager.h"
#include <utils/checkablemessagebox.h>
#include <utils/consoleprocess.h>
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
#include <utils/stylehelper.h> #include <utils/stylehelper.h>
#include <utils/consoleprocess.h>
#include <utils/unixutils.h> #include <utils/unixutils.h>
#include <QMessageBox> #include <QMessageBox>
@@ -137,7 +138,8 @@ QWidget *GeneralSettings::createPage(QWidget *parent)
m_page->autoSaveCheckBox->setChecked(EditorManager::autoSaveEnabled()); m_page->autoSaveCheckBox->setChecked(EditorManager::autoSaveEnabled());
m_page->autoSaveInterval->setValue(EditorManager::autoSaveInterval()); 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()), connect(m_page->resetColorButton, SIGNAL(clicked()),
this, SLOT(resetInterfaceColor())); this, SLOT(resetInterfaceColor()));
@@ -208,6 +210,7 @@ void GeneralSettings::resetInterfaceColor()
void GeneralSettings::resetWarnings() void GeneralSettings::resetWarnings()
{ {
Core::InfoBar::clearGloballySuppressed(); Core::InfoBar::clearGloballySuppressed();
Utils::CheckableMessageBox::resetAllDoNotAskAgainQuestions(ICore::settings());
m_page->resetWarningsButton->setEnabled(false); m_page->resetWarningsButton->setEnabled(false);
} }

View File

@@ -34,6 +34,7 @@
#include "debuggercore.h" #include "debuggercore.h"
#include <coreplugin/mainwindow.h> #include <coreplugin/mainwindow.h>
#include <utils/checkablemessagebox.h>
#include <utils/pathchooser.h> #include <utils/pathchooser.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/savedaction.h> #include <utils/savedaction.h>
@@ -866,11 +867,12 @@ void BreakTreeView::setBreakpointsEnabled(const BreakpointModelIds &ids, bool en
void BreakTreeView::deleteAllBreakpoints() void BreakTreeView::deleteAllBreakpoints()
{ {
if (QMessageBox::warning(Core::ICore::mainWindow(), if (Utils::CheckableMessageBox::doNotAskAgainQuestion(Core::ICore::mainWindow(),
tr("Remove All Breakpoints"), tr("Remove All Breakpoints"),
tr("Are you sure you want to remove all breakpoints " tr("Are you sure you want to remove all breakpoints "
"from all files in the current session?"), "from all files in the current session?"),
QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes) Core::ICore::settings(),
QLatin1String("RemoveAllBreakpoints")) == QDialogButtonBox::Yes)
deleteBreakpoints(breakHandler()->allBreakpointIds()); deleteBreakpoints(breakHandler()->allBreakpointIds());
} }

View File

@@ -617,7 +617,7 @@ bool RunControl::showPromptToStopDialog(const QString &title,
messageBox.button(QDialogButtonBox::Cancel)->setText(cancelButtonText); messageBox.button(QDialogButtonBox::Cancel)->setText(cancelButtonText);
messageBox.setDefaultButton(QDialogButtonBox::Yes); messageBox.setDefaultButton(QDialogButtonBox::Yes);
if (prompt) { if (prompt) {
messageBox.setCheckBoxText(tr("Do not ask again")); messageBox.setCheckBoxText(Utils::CheckableMessageBox::msgDoNotAskAgain());
messageBox.setChecked(false); messageBox.setChecked(false);
} else { } else {
messageBox.setCheckBoxVisible(false); messageBox.setCheckBoxVisible(false);

View File

@@ -102,47 +102,32 @@ static void startLocalTool(IAnalyzerTool *tool)
? AnalyzerManager::tr("Debug") ? AnalyzerManager::tr("Debug")
: AnalyzerManager::tr("Release"); : AnalyzerManager::tr("Release");
QSettings *settings = ICore::settings(); QString toolModeString;
const QString configKey = QLatin1String("Analyzer.AnalyzeCorrectMode"); switch (tool->toolMode()) {
int ret; case IAnalyzerTool::DebugMode:
if (settings->contains(configKey)) { toolModeString = AnalyzerManager::tr("Debug");
ret = settings->value(configKey, QDialog::Accepted).toInt(); break;
} else { case IAnalyzerTool::ReleaseMode:
QString toolModeString; toolModeString = AnalyzerManager::tr("Release");
switch (tool->toolMode()) { break;
case IAnalyzerTool::DebugMode: default:
toolModeString = AnalyzerManager::tr("Debug"); QTC_CHECK(false);
break;
case IAnalyzerTool::ReleaseMode:
toolModeString = AnalyzerManager::tr("Release");
break;
default:
QTC_CHECK(false);
}
//const QString toolName = tool->displayName();
const QString toolName = AnalyzerManager::tr("Tool"); // FIXME
const QString title = AnalyzerManager::tr("Run %1 in %2 Mode?").arg(toolName).arg(currentMode);
const QString message = AnalyzerManager::tr("<html><head/><body><p>You are trying "
"to run the tool \"%1\" on an application in %2 mode. "
"The tool is designed to be used in %3 mode.</p><p>"
"Debug and Release mode run-time characteristics differ "
"significantly, analytical findings for one mode may or "
"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) //const QString toolName = tool->displayName();
const QString toolName = AnalyzerManager::tr("Tool"); // FIXME
const QString title = AnalyzerManager::tr("Run %1 in %2 Mode?").arg(toolName).arg(currentMode);
const QString message = AnalyzerManager::tr("<html><head/><body><p>You are trying "
"to run the tool \"%1\" on an application in %2 mode. "
"The tool is designed to be used in %3 mode.</p><p>"
"Debug and Release mode run-time characteristics differ "
"significantly, analytical findings for one mode may or "
"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);
if (Utils::CheckableMessageBox::doNotAskAgainQuestion(ICore::mainWindow(),
title, message, ICore::settings(), QLatin1String("AnalyzerCorrectModeWarning"),
QDialogButtonBox::Yes|QDialogButtonBox::Cancel,
QDialogButtonBox::Cancel, QDialogButtonBox::Yes) != QDialogButtonBox::Yes)
return; return;
} }