From a4c34dc7dea265e99e0ae2e5d864e2cb2bb91f7f Mon Sep 17 00:00:00 2001 From: Orgad Shaneh <orgad.shaneh@audiocodes.com> Date: Thu, 10 Jan 2013 18:18:28 +0200 Subject: [PATCH] InfoBar: Introduce global suppression * Generalize "Do not show again" * Use in CMakeEditor Change-Id: Ia86b7c79b9022cbfcd06fed02b94fe0b15c87a56 Reviewed-by: hjk <qthjk@ovi.com> --- .../cmakeprojectmanager/cmakeeditor.cpp | 3 +- src/plugins/coreplugin/coreplugin.cpp | 2 + src/plugins/coreplugin/infobar.cpp | 53 ++++++++++++++++--- src/plugins/coreplugin/infobar.h | 13 ++++- 4 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp index 52a4f947b5d..0fcc20d4147 100644 --- a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp @@ -86,7 +86,8 @@ void CMakeEditor::markAsChanged() if (!infoBar->canInfoBeAdded(infoRunCmake)) return; Core::InfoBarEntry info(infoRunCmake, - tr("Changes to cmake files are shown in the project tree after building.")); + tr("Changes to cmake files are shown in the project tree after building."), + Core::InfoBarEntry::GlobalSuppressionEnabled); info.setCustomButtonInfo(tr("Build now"), this, SLOT(build())); infoBar->addInfo(info); } diff --git a/src/plugins/coreplugin/coreplugin.cpp b/src/plugins/coreplugin/coreplugin.cpp index 7f2bd66a9b6..049b61d0cbc 100644 --- a/src/plugins/coreplugin/coreplugin.cpp +++ b/src/plugins/coreplugin/coreplugin.cpp @@ -37,6 +37,7 @@ #include "mainwindow.h" #include "mimedatabase.h" #include "modemanager.h" +#include "infobar.h" #include <extensionsystem/pluginmanager.h> @@ -92,6 +93,7 @@ bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage) addObject(m_editMode); ModeManager::activateMode(m_editMode->id()); m_designMode = new DesignMode; + InfoBar::initializeGloballySuppressed(); } return success; } diff --git a/src/plugins/coreplugin/infobar.cpp b/src/plugins/coreplugin/infobar.cpp index 31b84db655f..8f1ffedd527 100644 --- a/src/plugins/coreplugin/infobar.cpp +++ b/src/plugins/coreplugin/infobar.cpp @@ -29,24 +29,30 @@ #include "infobar.h" -#include <coreplugin/coreconstants.h> +#include "coreconstants.h" +#include "icore.h" #include <QFrame> #include <QHBoxLayout> #include <QLabel> +#include <QSettings> #include <QToolButton> - #include <QVariant> +static const char C_SUPPRESSED_WARNINGS[] = "SuppressedWarnings"; + namespace Core { -InfoBarEntry::InfoBarEntry(Id _id, const QString &_infoText) +QSet<Id> InfoBar::globallySuppressed; + +InfoBarEntry::InfoBarEntry(Id _id, const QString &_infoText, GlobalSuppressionMode _globalSuppression) : id(_id) , infoText(_infoText) , object(0) , buttonPressMember(0) , cancelObject(0) , cancelButtonPressMember(0) + , globalSuppression(_globalSuppression) { } @@ -108,7 +114,7 @@ void InfoBar::suppressInfo(Id id) // Info can not be added more than once, or if it is suppressed bool InfoBar::canInfoBeAdded(Id id) const { - return !containsInfo(id) && !m_suppressed.contains(id); + return !containsInfo(id) && !m_suppressed.contains(id) && !globallySuppressed.contains(id); } void InfoBar::enableInfo(Id id) @@ -124,6 +130,22 @@ void InfoBar::clear() } } +void InfoBar::globallySuppressInfo(Id id) +{ + globallySuppressed.insert(id); + QStringList list; + foreach (Id i, globallySuppressed) + list << QLatin1String(i.name()); + ICore::settings()->setValue(QLatin1String(C_SUPPRESSED_WARNINGS), list); +} + +void InfoBar::initializeGloballySuppressed() +{ + QStringList list = ICore::settings()->value(QLatin1String(C_SUPPRESSED_WARNINGS)).toStringList(); + foreach (const QString &id, list) + globallySuppressed.insert(Id(id.toLatin1())); +} + InfoBarDisplay::InfoBarDisplay(QObject *parent) : QObject(parent) @@ -200,6 +222,14 @@ void InfoBarDisplay::update() hbox->addWidget(infoWidgetButton); } + QToolButton *infoWidgetSuppressButton = 0; + if (info.globalSuppression == InfoBarEntry::GlobalSuppressionEnabled) { + infoWidgetSuppressButton = new QToolButton; + infoWidgetSuppressButton->setProperty("infoId", info.id.uniqueIdentifier()); + infoWidgetSuppressButton->setText(tr("Do not show again")); + connect(infoWidgetSuppressButton, SIGNAL(clicked()), SLOT(suppressButtonClicked())); + } + QToolButton *infoWidgetCloseButton = new QToolButton; infoWidgetCloseButton->setProperty("infoId", info.id.uniqueIdentifier()); @@ -214,12 +244,16 @@ void InfoBarDisplay::update() infoWidgetCloseButton->setAutoRaise(true); infoWidgetCloseButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_CLEAR))); infoWidgetCloseButton->setToolTip(tr("Close")); + if (infoWidgetSuppressButton) + hbox->addWidget(infoWidgetSuppressButton); + hbox->addWidget(infoWidgetCloseButton); } else { infoWidgetCloseButton->setText(info.cancelButtonText); + hbox->addWidget(infoWidgetCloseButton); + if (infoWidgetSuppressButton) + hbox->addWidget(infoWidgetSuppressButton); } - hbox->addWidget(infoWidgetCloseButton); - connect(infoWidget, SIGNAL(destroyed()), SLOT(widgetDestroyed())); m_boxLayout->insertWidget(m_boxIndex, infoWidget); m_infoWidgets << infoWidget; @@ -236,4 +270,11 @@ void InfoBarDisplay::cancelButtonClicked() m_infoBar->removeInfo(Id::fromUniqueIdentifier(sender()->property("infoId").toInt())); } +void InfoBarDisplay::suppressButtonClicked() +{ + Id id = Id::fromUniqueIdentifier(sender()->property("infoId").toInt()); + m_infoBar->removeInfo(id); + InfoBar::globallySuppressInfo(id); +} + } // namespace Core diff --git a/src/plugins/coreplugin/infobar.h b/src/plugins/coreplugin/infobar.h index 28b9d389a54..0d55d72070a 100644 --- a/src/plugins/coreplugin/infobar.h +++ b/src/plugins/coreplugin/infobar.h @@ -48,7 +48,13 @@ class InfoBarDisplay; class CORE_EXPORT InfoBarEntry { public: - InfoBarEntry(Id _id, const QString &_infoText); + enum GlobalSuppressionMode + { + GlobalSuppressionDisabled, + GlobalSuppressionEnabled + }; + + InfoBarEntry(Id _id, const QString &_infoText, GlobalSuppressionMode _globalSuppression = GlobalSuppressionDisabled); InfoBarEntry(const InfoBarEntry &other) { *this = other; } void setCustomButtonInfo(const QString &_buttonText, QObject *_object, const char *_member); void setCancelButtonInfo(QObject *_object, const char *_member); @@ -63,6 +69,7 @@ private: QString cancelButtonText; QObject *cancelObject; const char *cancelButtonPressMember; + GlobalSuppressionMode globalSuppression; friend class InfoBar; friend class InfoBarDisplay; }; @@ -79,6 +86,8 @@ public: bool canInfoBeAdded(Id id) const; void enableInfo(Id id); void clear(); + static void globallySuppressInfo(Id id); + static void initializeGloballySuppressed(); signals: void changed(); @@ -86,6 +95,7 @@ signals: private: QList<InfoBarEntry> m_infoBarEntries; QSet<Id> m_suppressed; + static QSet<Id> globallySuppressed; friend class InfoBarDisplay; }; @@ -100,6 +110,7 @@ public: private slots: void cancelButtonClicked(); + void suppressButtonClicked(); void update(); void infoBarDestroyed(); void widgetDestroyed(); -- GitLab