Commit a4c34dc7 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by hjk
Browse files

InfoBar: Introduce global suppression



* Generalize "Do not show again"
* Use in CMakeEditor

Change-Id: Ia86b7c79b9022cbfcd06fed02b94fe0b15c87a56
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 4ef8bd53
......@@ -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);
}
......
......@@ -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;
}
......
......@@ -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
......@@ -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();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment