summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@digia.com>2013-10-31 15:39:49 +0100
committerEike Ziller <eike.ziller@digia.com>2013-11-01 10:14:39 +0100
commit36f149342d633d48b2f4a424c7562a4f16c98564 (patch)
tree4d210c1383720081df863b07c546ae3a260c52f3
parent949bd4239932d6b7333b1100cfa5bfc8f50e7440 (diff)
downloadqt-creator-36f149342d633d48b2f4a424c7562a4f16c98564.tar.gz
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>
-rw-r--r--src/libs/utils/checkablemessagebox.cpp98
-rw-r--r--src/libs/utils/checkablemessagebox.h17
-rw-r--r--src/plugins/bookmarks/bookmarkmanager.cpp19
-rw-r--r--src/plugins/coreplugin/generalsettings.cpp7
-rw-r--r--src/plugins/debugger/breakwindow.cpp6
-rw-r--r--src/plugins/projectexplorer/runconfiguration.cpp2
-rw-r--r--src/plugins/valgrind/valgrindtool.cpp65
7 files changed, 154 insertions, 60 deletions
diff --git a/src/libs/utils/checkablemessagebox.cpp b/src/libs/utils/checkablemessagebox.cpp
index 3d6523a09b..a052ab0386 100644
--- a/src/libs/utils/checkablemessagebox.cpp
+++ b/src/libs/utils/checkablemessagebox.cpp
@@ -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
diff --git a/src/libs/utils/checkablemessagebox.h b/src/libs/utils/checkablemessagebox.h
index 42756a4d49..f71c65e2b6 100644
--- a/src/libs/utils/checkablemessagebox.h
+++ b/src/libs/utils/checkablemessagebox.h
@@ -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);
diff --git a/src/plugins/bookmarks/bookmarkmanager.cpp b/src/plugins/bookmarks/bookmarkmanager.cpp
index 4c09532671..d0e0f1035b 100644
--- a/src/plugins/bookmarks/bookmarkmanager.cpp
+++ b/src/plugins/bookmarks/bookmarkmanager.cpp
@@ -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,
- 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)
- return;
- settings->setValue(key, checked);
- }
+ 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?"),
+ ICore::settings(),
+ QLatin1String("RemoveAllBookmarks")) != QDialogButtonBox::Yes)
+ return;
// The performance of this function could be greatly improved.
while (m_manager->rowCount()) {
diff --git a/src/plugins/coreplugin/generalsettings.cpp b/src/plugins/coreplugin/generalsettings.cpp
index e052a77ca4..1e11947db3 100644
--- a/src/plugins/coreplugin/generalsettings.cpp
+++ b/src/plugins/coreplugin/generalsettings.cpp
@@ -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);
}
diff --git a/src/plugins/debugger/breakwindow.cpp b/src/plugins/debugger/breakwindow.cpp
index 310f99751c..1e8fd16946 100644
--- a/src/plugins/debugger/breakwindow.cpp
+++ b/src/plugins/debugger/breakwindow.cpp
@@ -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());
}
diff --git a/src/plugins/projectexplorer/runconfiguration.cpp b/src/plugins/projectexplorer/runconfiguration.cpp
index 9f08ff1860..4bdf6cac03 100644
--- a/src/plugins/projectexplorer/runconfiguration.cpp
+++ b/src/plugins/projectexplorer/runconfiguration.cpp
@@ -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);
diff --git a/src/plugins/valgrind/valgrindtool.cpp b/src/plugins/valgrind/valgrindtool.cpp
index fd1f008b4c..83c60b5b3d 100644
--- a/src/plugins/valgrind/valgrindtool.cpp
+++ b/src/plugins/valgrind/valgrindtool.cpp
@@ -102,47 +102,32 @@ 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:
- toolModeString = AnalyzerManager::tr("Debug");
- 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);
+ QString toolModeString;
+ switch (tool->toolMode()) {
+ case IAnalyzerTool::DebugMode:
+ toolModeString = AnalyzerManager::tr("Debug");
+ break;
+ case IAnalyzerTool::ReleaseMode:
+ toolModeString = AnalyzerManager::tr("Release");
+ break;
+ default:
+ QTC_CHECK(false);
}
- 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;
}