forked from qt-creator/qt-creator
InfoBar: Introduce global suppression
* Generalize "Do not show again" * Use in CMakeEditor Change-Id: Ia86b7c79b9022cbfcd06fed02b94fe0b15c87a56 Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -86,7 +86,8 @@ void CMakeEditor::markAsChanged()
|
|||||||
if (!infoBar->canInfoBeAdded(infoRunCmake))
|
if (!infoBar->canInfoBeAdded(infoRunCmake))
|
||||||
return;
|
return;
|
||||||
Core::InfoBarEntry info(infoRunCmake,
|
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()));
|
info.setCustomButtonInfo(tr("Build now"), this, SLOT(build()));
|
||||||
infoBar->addInfo(info);
|
infoBar->addInfo(info);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "mimedatabase.h"
|
#include "mimedatabase.h"
|
||||||
#include "modemanager.h"
|
#include "modemanager.h"
|
||||||
|
#include "infobar.h"
|
||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
@@ -92,6 +93,7 @@ bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
|||||||
addObject(m_editMode);
|
addObject(m_editMode);
|
||||||
ModeManager::activateMode(m_editMode->id());
|
ModeManager::activateMode(m_editMode->id());
|
||||||
m_designMode = new DesignMode;
|
m_designMode = new DesignMode;
|
||||||
|
InfoBar::initializeGloballySuppressed();
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,24 +29,30 @@
|
|||||||
|
|
||||||
#include "infobar.h"
|
#include "infobar.h"
|
||||||
|
|
||||||
#include <coreplugin/coreconstants.h>
|
#include "coreconstants.h"
|
||||||
|
#include "icore.h"
|
||||||
|
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QSettings>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
|
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
|
static const char C_SUPPRESSED_WARNINGS[] = "SuppressedWarnings";
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
InfoBarEntry::InfoBarEntry(Id _id, const QString &_infoText)
|
QSet<Id> InfoBar::globallySuppressed;
|
||||||
|
|
||||||
|
InfoBarEntry::InfoBarEntry(Id _id, const QString &_infoText, GlobalSuppressionMode _globalSuppression)
|
||||||
: id(_id)
|
: id(_id)
|
||||||
, infoText(_infoText)
|
, infoText(_infoText)
|
||||||
, object(0)
|
, object(0)
|
||||||
, buttonPressMember(0)
|
, buttonPressMember(0)
|
||||||
, cancelObject(0)
|
, cancelObject(0)
|
||||||
, cancelButtonPressMember(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
|
// Info can not be added more than once, or if it is suppressed
|
||||||
bool InfoBar::canInfoBeAdded(Id id) const
|
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)
|
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)
|
InfoBarDisplay::InfoBarDisplay(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
@@ -200,6 +222,14 @@ void InfoBarDisplay::update()
|
|||||||
hbox->addWidget(infoWidgetButton);
|
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;
|
QToolButton *infoWidgetCloseButton = new QToolButton;
|
||||||
infoWidgetCloseButton->setProperty("infoId", info.id.uniqueIdentifier());
|
infoWidgetCloseButton->setProperty("infoId", info.id.uniqueIdentifier());
|
||||||
|
|
||||||
@@ -214,11 +244,15 @@ void InfoBarDisplay::update()
|
|||||||
infoWidgetCloseButton->setAutoRaise(true);
|
infoWidgetCloseButton->setAutoRaise(true);
|
||||||
infoWidgetCloseButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_CLEAR)));
|
infoWidgetCloseButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_CLEAR)));
|
||||||
infoWidgetCloseButton->setToolTip(tr("Close"));
|
infoWidgetCloseButton->setToolTip(tr("Close"));
|
||||||
|
if (infoWidgetSuppressButton)
|
||||||
|
hbox->addWidget(infoWidgetSuppressButton);
|
||||||
|
hbox->addWidget(infoWidgetCloseButton);
|
||||||
} else {
|
} else {
|
||||||
infoWidgetCloseButton->setText(info.cancelButtonText);
|
infoWidgetCloseButton->setText(info.cancelButtonText);
|
||||||
}
|
|
||||||
|
|
||||||
hbox->addWidget(infoWidgetCloseButton);
|
hbox->addWidget(infoWidgetCloseButton);
|
||||||
|
if (infoWidgetSuppressButton)
|
||||||
|
hbox->addWidget(infoWidgetSuppressButton);
|
||||||
|
}
|
||||||
|
|
||||||
connect(infoWidget, SIGNAL(destroyed()), SLOT(widgetDestroyed()));
|
connect(infoWidget, SIGNAL(destroyed()), SLOT(widgetDestroyed()));
|
||||||
m_boxLayout->insertWidget(m_boxIndex, infoWidget);
|
m_boxLayout->insertWidget(m_boxIndex, infoWidget);
|
||||||
@@ -236,4 +270,11 @@ void InfoBarDisplay::cancelButtonClicked()
|
|||||||
m_infoBar->removeInfo(Id::fromUniqueIdentifier(sender()->property("infoId").toInt()));
|
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
|
} // namespace Core
|
||||||
|
|||||||
@@ -48,7 +48,13 @@ class InfoBarDisplay;
|
|||||||
class CORE_EXPORT InfoBarEntry
|
class CORE_EXPORT InfoBarEntry
|
||||||
{
|
{
|
||||||
public:
|
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; }
|
InfoBarEntry(const InfoBarEntry &other) { *this = other; }
|
||||||
void setCustomButtonInfo(const QString &_buttonText, QObject *_object, const char *_member);
|
void setCustomButtonInfo(const QString &_buttonText, QObject *_object, const char *_member);
|
||||||
void setCancelButtonInfo(QObject *_object, const char *_member);
|
void setCancelButtonInfo(QObject *_object, const char *_member);
|
||||||
@@ -63,6 +69,7 @@ private:
|
|||||||
QString cancelButtonText;
|
QString cancelButtonText;
|
||||||
QObject *cancelObject;
|
QObject *cancelObject;
|
||||||
const char *cancelButtonPressMember;
|
const char *cancelButtonPressMember;
|
||||||
|
GlobalSuppressionMode globalSuppression;
|
||||||
friend class InfoBar;
|
friend class InfoBar;
|
||||||
friend class InfoBarDisplay;
|
friend class InfoBarDisplay;
|
||||||
};
|
};
|
||||||
@@ -79,6 +86,8 @@ public:
|
|||||||
bool canInfoBeAdded(Id id) const;
|
bool canInfoBeAdded(Id id) const;
|
||||||
void enableInfo(Id id);
|
void enableInfo(Id id);
|
||||||
void clear();
|
void clear();
|
||||||
|
static void globallySuppressInfo(Id id);
|
||||||
|
static void initializeGloballySuppressed();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void changed();
|
void changed();
|
||||||
@@ -86,6 +95,7 @@ signals:
|
|||||||
private:
|
private:
|
||||||
QList<InfoBarEntry> m_infoBarEntries;
|
QList<InfoBarEntry> m_infoBarEntries;
|
||||||
QSet<Id> m_suppressed;
|
QSet<Id> m_suppressed;
|
||||||
|
static QSet<Id> globallySuppressed;
|
||||||
friend class InfoBarDisplay;
|
friend class InfoBarDisplay;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -100,6 +110,7 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void cancelButtonClicked();
|
void cancelButtonClicked();
|
||||||
|
void suppressButtonClicked();
|
||||||
void update();
|
void update();
|
||||||
void infoBarDestroyed();
|
void infoBarDestroyed();
|
||||||
void widgetDestroyed();
|
void widgetDestroyed();
|
||||||
|
|||||||
Reference in New Issue
Block a user