forked from qt-creator/qt-creator
Move InfoBar to Utils
The only reason it was required to be in Core plugin, was its use of Id, which now is available in Utils. Change-Id: I66ce863c24924e6448d339b3422538a7fe167336 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -91,7 +91,6 @@ add_qtc_plugin(Core
|
||||
ifilewizardextension.h
|
||||
imode.cpp imode.h
|
||||
inavigationwidgetfactory.cpp inavigationwidgetfactory.h
|
||||
infobar.cpp infobar.h
|
||||
ioutputpane.cpp ioutputpane.h
|
||||
iversioncontrol.cpp iversioncontrol.h
|
||||
iwelcomepage.cpp iwelcomepage.h
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include "helpmanager.h"
|
||||
#include "icore.h"
|
||||
#include "idocument.h"
|
||||
#include "infobar.h"
|
||||
#include "iwizardfactory.h"
|
||||
#include "mainwindow.h"
|
||||
#include "modemanager.h"
|
||||
@@ -50,9 +49,10 @@
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <extensionsystem/pluginspec.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/pathchooser.h>
|
||||
#include <utils/infobar.h>
|
||||
#include <utils/macroexpander.h>
|
||||
#include <utils/mimetypes/mimedatabase.h>
|
||||
#include <utils/pathchooser.h>
|
||||
#include <utils/savefile.h>
|
||||
#include <utils/stringutils.h>
|
||||
#include <utils/theme/theme.h>
|
||||
|
||||
@@ -71,7 +71,6 @@ SOURCES += corejsextensions.cpp \
|
||||
sidebar.cpp \
|
||||
fileiconprovider.cpp \
|
||||
icore.cpp \
|
||||
infobar.cpp \
|
||||
editormanager/ieditor.cpp \
|
||||
dialogs/ioptionspage.cpp \
|
||||
settingsdatabase.cpp \
|
||||
@@ -168,7 +167,6 @@ HEADERS += corejsextensions.h \
|
||||
reaper_p.h \
|
||||
icontext.h \
|
||||
icore.h \
|
||||
infobar.h \
|
||||
imode.h \
|
||||
ioutputpane.h \
|
||||
coreconstants.h \
|
||||
|
||||
@@ -102,8 +102,6 @@ Project {
|
||||
"imode.h",
|
||||
"inavigationwidgetfactory.cpp",
|
||||
"inavigationwidgetfactory.h",
|
||||
"infobar.cpp",
|
||||
"infobar.h",
|
||||
"ioutputpane.cpp",
|
||||
"ioutputpane.h",
|
||||
"iversioncontrol.cpp",
|
||||
|
||||
@@ -52,7 +52,6 @@
|
||||
#include <coreplugin/find/searchresultitem.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/imode.h>
|
||||
#include <coreplugin/infobar.h>
|
||||
#include <coreplugin/iversioncontrol.h>
|
||||
#include <coreplugin/modemanager.h>
|
||||
#include <coreplugin/outputpane.h>
|
||||
@@ -68,6 +67,7 @@
|
||||
#include <utils/executeondestruction.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/infobar.h>
|
||||
#include <utils/macroexpander.h>
|
||||
#include <utils/mimetypes/mimedatabase.h>
|
||||
#include <utils/mimetypes/mimetype.h>
|
||||
|
||||
@@ -31,13 +31,13 @@
|
||||
#include "documentmodel_p.h"
|
||||
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <coreplugin/editortoolbar.h>
|
||||
#include <coreplugin/findplaceholder.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/infobar.h>
|
||||
#include <coreplugin/locator/locatorconstants.h>
|
||||
#include <coreplugin/minisplitter.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <coreplugin/findplaceholder.h>
|
||||
#include <utils/infobar.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/theme/theme.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
@@ -50,10 +50,13 @@ class QStackedWidget;
|
||||
class QToolButton;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Utils {
|
||||
class InfoBarDisplay;
|
||||
}
|
||||
|
||||
namespace Core {
|
||||
class IDocument;
|
||||
class IEditor;
|
||||
class InfoBarDisplay;
|
||||
class EditorToolBar;
|
||||
|
||||
namespace Internal {
|
||||
@@ -130,7 +133,7 @@ private:
|
||||
EditorToolBar *m_toolBar;
|
||||
|
||||
QStackedWidget *m_container;
|
||||
InfoBarDisplay *m_infoBarDisplay;
|
||||
Utils::InfoBarDisplay *m_infoBarDisplay;
|
||||
QString m_statusWidgetId;
|
||||
QFrame *m_statusHLine;
|
||||
QFrame *m_statusWidget;
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "infobar.h"
|
||||
#include <utils/infobar.h>
|
||||
|
||||
#include <QIcon>
|
||||
#include <QWidget>
|
||||
@@ -159,7 +159,7 @@ public:
|
||||
|
||||
int currentIndex() const;
|
||||
QStatusBar *statusBar() const;
|
||||
InfoBar *infoBar();
|
||||
Utils::InfoBar *infoBar();
|
||||
|
||||
void setTabEnabled(int index, bool enable);
|
||||
bool isTabEnabled(int index) const;
|
||||
@@ -186,8 +186,8 @@ private:
|
||||
QStackedLayout *m_modesStack;
|
||||
QWidget *m_selectionWidget;
|
||||
QStatusBar *m_statusBar;
|
||||
InfoBarDisplay m_infoBarDisplay;
|
||||
InfoBar m_infoBar;
|
||||
Utils::InfoBarDisplay m_infoBarDisplay;
|
||||
Utils::InfoBar m_infoBar;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include "searchresultwindow.h"
|
||||
|
||||
#include <coreplugin/infobar.h>
|
||||
#include <utils/infobar.h>
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
@@ -127,8 +127,8 @@ private:
|
||||
int m_count = 0;
|
||||
QString m_dontAskAgainGroup;
|
||||
QFrame *m_messageWidget = nullptr;
|
||||
InfoBar m_infoBar;
|
||||
InfoBarDisplay m_infoBarDisplay;
|
||||
Utils::InfoBar m_infoBar;
|
||||
Utils::InfoBarDisplay m_infoBarDisplay;
|
||||
QWidget *m_topReplaceWidget = nullptr;
|
||||
QLabel *m_replaceLabel = nullptr;
|
||||
QLineEdit *m_replaceTextEdit = nullptr;
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include "generalsettings.h"
|
||||
#include "coreconstants.h"
|
||||
#include "icore.h"
|
||||
#include "infobar.h"
|
||||
|
||||
#include "ui_generalsettings.h"
|
||||
|
||||
@@ -34,6 +33,7 @@
|
||||
|
||||
#include <utils/checkablemessagebox.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/infobar.h>
|
||||
#include <utils/stylehelper.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
||||
@@ -654,7 +654,7 @@ QStatusBar *ICore::statusBar()
|
||||
Use for notifying the user of something without interrupting with
|
||||
dialog. Use sparingly.
|
||||
*/
|
||||
InfoBar *ICore::infoBar()
|
||||
Utils::InfoBar *ICore::infoBar()
|
||||
{
|
||||
return m_mainwindow->infoBar();
|
||||
}
|
||||
|
||||
@@ -42,10 +42,13 @@ class QStatusBar;
|
||||
class QWidget;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Utils {
|
||||
class InfoBar;
|
||||
}
|
||||
|
||||
namespace Core {
|
||||
class Context;
|
||||
class IContext;
|
||||
class InfoBar;
|
||||
class IWizardFactory;
|
||||
class SettingsDatabase;
|
||||
|
||||
@@ -100,7 +103,7 @@ public:
|
||||
|
||||
static QMainWindow *mainWindow();
|
||||
static QWidget *dialogParent();
|
||||
static InfoBar *infoBar();
|
||||
static Utils::InfoBar *infoBar();
|
||||
|
||||
static void raiseWindow(QWidget *widget);
|
||||
|
||||
|
||||
@@ -25,9 +25,8 @@
|
||||
|
||||
#include "idocument.h"
|
||||
|
||||
#include "infobar.h"
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/infobar.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QFile>
|
||||
@@ -76,7 +75,7 @@ public:
|
||||
QString preferredDisplayName;
|
||||
QString uniqueDisplayName;
|
||||
QString autoSaveName;
|
||||
InfoBar *infoBar = nullptr;
|
||||
Utils::InfoBar *infoBar = nullptr;
|
||||
Id id;
|
||||
bool temporary = false;
|
||||
bool hasWriteWarning = false;
|
||||
@@ -286,9 +285,9 @@ void IDocument::setRestoredFrom(const QString &name)
|
||||
{
|
||||
d->autoSaveName = name;
|
||||
d->restored = true;
|
||||
InfoBarEntry info(Id(kRestoredAutoSave),
|
||||
tr("File was restored from auto-saved copy. "
|
||||
"Select Save to confirm or Revert to Saved to discard changes."));
|
||||
Utils::InfoBarEntry info(Id(kRestoredAutoSave),
|
||||
tr("File was restored from auto-saved copy. "
|
||||
"Select Save to confirm or Revert to Saved to discard changes."));
|
||||
infoBar()->addInfo(info);
|
||||
}
|
||||
|
||||
@@ -314,10 +313,10 @@ void IDocument::setWriteWarning(bool has)
|
||||
d->hasWriteWarning = has;
|
||||
}
|
||||
|
||||
InfoBar *IDocument::infoBar()
|
||||
Utils::InfoBar *IDocument::infoBar()
|
||||
{
|
||||
if (!d->infoBar)
|
||||
d->infoBar = new InfoBar;
|
||||
d->infoBar = new Utils::InfoBar;
|
||||
return d->infoBar;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,12 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace Utils { class FilePath; }
|
||||
namespace Utils {
|
||||
class FilePath;
|
||||
class InfoBar;
|
||||
} // namespace Utils
|
||||
|
||||
namespace Core {
|
||||
class InfoBar;
|
||||
|
||||
namespace Internal {
|
||||
class IDocumentPrivate;
|
||||
@@ -130,7 +132,7 @@ public:
|
||||
bool hasWriteWarning() const;
|
||||
void setWriteWarning(bool has);
|
||||
|
||||
InfoBar *infoBar();
|
||||
Utils::InfoBar *infoBar();
|
||||
|
||||
signals:
|
||||
// For meta data changes: file name, modified state, ...
|
||||
|
||||
@@ -1,361 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "infobar.h"
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/theme/theme.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QSettings>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QToolButton>
|
||||
#include <QComboBox>
|
||||
|
||||
static const char C_SUPPRESSED_WARNINGS[] = "SuppressedWarnings";
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
namespace Core {
|
||||
|
||||
QSet<Id> InfoBar::globallySuppressed;
|
||||
QSettings *InfoBar::m_settings = nullptr;
|
||||
Utils::Theme *InfoBar::m_theme = nullptr;
|
||||
|
||||
InfoBarEntry::InfoBarEntry(Id _id, const QString &_infoText, GlobalSuppression _globalSuppression)
|
||||
: m_id(_id)
|
||||
, m_infoText(_infoText)
|
||||
, m_globalSuppression(_globalSuppression)
|
||||
{
|
||||
}
|
||||
|
||||
void InfoBarEntry::setCustomButtonInfo(const QString &_buttonText, CallBack callBack)
|
||||
{
|
||||
m_buttonText = _buttonText;
|
||||
m_buttonCallBack = callBack;
|
||||
}
|
||||
|
||||
void InfoBarEntry::setCancelButtonInfo(CallBack callBack)
|
||||
{
|
||||
m_useCancelButton = true;
|
||||
m_cancelButtonCallBack = callBack;
|
||||
}
|
||||
|
||||
void InfoBarEntry::setCancelButtonInfo(const QString &_cancelButtonText, CallBack callBack)
|
||||
{
|
||||
m_useCancelButton = true;
|
||||
m_cancelButtonText = _cancelButtonText;
|
||||
m_cancelButtonCallBack = callBack;
|
||||
}
|
||||
|
||||
void InfoBarEntry::setComboInfo(const QStringList &list, InfoBarEntry::ComboCallBack callBack)
|
||||
{
|
||||
m_comboCallBack = callBack;
|
||||
m_comboInfo = list;
|
||||
}
|
||||
|
||||
void InfoBarEntry::removeCancelButton()
|
||||
{
|
||||
m_useCancelButton = false;
|
||||
m_cancelButtonText.clear();
|
||||
m_cancelButtonCallBack = nullptr;
|
||||
}
|
||||
|
||||
void InfoBarEntry::setDetailsWidgetCreator(const InfoBarEntry::DetailsWidgetCreator &creator)
|
||||
{
|
||||
m_detailsWidgetCreator = creator;
|
||||
}
|
||||
|
||||
void InfoBar::addInfo(const InfoBarEntry &info)
|
||||
{
|
||||
m_infoBarEntries << info;
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void InfoBar::removeInfo(Id id)
|
||||
{
|
||||
const int size = m_infoBarEntries.size();
|
||||
Utils::erase(m_infoBarEntries, Utils::equal(&InfoBarEntry::m_id, id));
|
||||
if (size != m_infoBarEntries.size())
|
||||
emit changed();
|
||||
}
|
||||
|
||||
bool InfoBar::containsInfo(Id id) const
|
||||
{
|
||||
return Utils::anyOf(m_infoBarEntries, Utils::equal(&InfoBarEntry::m_id, id));
|
||||
}
|
||||
|
||||
// Remove and suppress id
|
||||
void InfoBar::suppressInfo(Id id)
|
||||
{
|
||||
removeInfo(id);
|
||||
m_suppressed << id;
|
||||
}
|
||||
|
||||
// Info cannot be added more than once, or if it is suppressed
|
||||
bool InfoBar::canInfoBeAdded(Id id) const
|
||||
{
|
||||
return !containsInfo(id) && !m_suppressed.contains(id) && !globallySuppressed.contains(id);
|
||||
}
|
||||
|
||||
void InfoBar::unsuppressInfo(Id id)
|
||||
{
|
||||
m_suppressed.remove(id);
|
||||
}
|
||||
|
||||
void InfoBar::clear()
|
||||
{
|
||||
if (!m_infoBarEntries.isEmpty()) {
|
||||
m_infoBarEntries.clear();
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
void InfoBar::globallySuppressInfo(Id id)
|
||||
{
|
||||
globallySuppressed.insert(id);
|
||||
writeGloballySuppressedToSettings();
|
||||
}
|
||||
|
||||
void InfoBar::globallyUnsuppressInfo(Id id)
|
||||
{
|
||||
globallySuppressed.remove(id);
|
||||
writeGloballySuppressedToSettings();
|
||||
}
|
||||
|
||||
void InfoBar::initialize(QSettings *settings, Theme *theme)
|
||||
{
|
||||
m_settings = settings;
|
||||
m_theme = theme;
|
||||
|
||||
if (QTC_GUARD(m_settings)) {
|
||||
const QStringList list = m_settings->value(QLatin1String(C_SUPPRESSED_WARNINGS)).toStringList();
|
||||
globallySuppressed = Utils::transform<QSet>(list, Id::fromString);
|
||||
}
|
||||
}
|
||||
|
||||
void InfoBar::clearGloballySuppressed()
|
||||
{
|
||||
globallySuppressed.clear();
|
||||
if (m_settings)
|
||||
m_settings->setValue(QLatin1String(C_SUPPRESSED_WARNINGS), QStringList());
|
||||
}
|
||||
|
||||
bool InfoBar::anyGloballySuppressed()
|
||||
{
|
||||
return !globallySuppressed.isEmpty();
|
||||
}
|
||||
|
||||
void InfoBar::writeGloballySuppressedToSettings()
|
||||
{
|
||||
if (!m_settings)
|
||||
return;
|
||||
const QStringList list = Utils::transform<QList>(globallySuppressed, &Id::toString);
|
||||
m_settings->setValue(QLatin1String(C_SUPPRESSED_WARNINGS), list);
|
||||
}
|
||||
|
||||
|
||||
InfoBarDisplay::InfoBarDisplay(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void InfoBarDisplay::setTarget(QBoxLayout *layout, int index)
|
||||
{
|
||||
m_boxLayout = layout;
|
||||
m_boxIndex = index;
|
||||
}
|
||||
|
||||
void InfoBarDisplay::setInfoBar(InfoBar *infoBar)
|
||||
{
|
||||
if (m_infoBar == infoBar)
|
||||
return;
|
||||
|
||||
if (m_infoBar)
|
||||
m_infoBar->disconnect(this);
|
||||
m_infoBar = infoBar;
|
||||
if (m_infoBar) {
|
||||
connect(m_infoBar, &InfoBar::changed, this, &InfoBarDisplay::update);
|
||||
connect(m_infoBar, &QObject::destroyed, this, &InfoBarDisplay::infoBarDestroyed);
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
void InfoBarDisplay::setStyle(QFrame::Shadow style)
|
||||
{
|
||||
m_style = style;
|
||||
update();
|
||||
}
|
||||
|
||||
InfoBar *InfoBarDisplay::infoBar() const
|
||||
{
|
||||
return m_infoBar;
|
||||
}
|
||||
|
||||
void InfoBarDisplay::infoBarDestroyed()
|
||||
{
|
||||
m_infoBar = nullptr;
|
||||
// Calling update() here causes a complicated crash on shutdown.
|
||||
// So instead we rely on the view now being either destroyed (in which case it
|
||||
// will delete the widgets itself) or setInfoBar() being called explicitly.
|
||||
}
|
||||
|
||||
void InfoBarDisplay::update()
|
||||
{
|
||||
for (QWidget *widget : m_infoWidgets) {
|
||||
widget->disconnect(this); // We want no destroyed() signal now
|
||||
delete widget;
|
||||
}
|
||||
m_infoWidgets.clear();
|
||||
|
||||
if (!m_infoBar)
|
||||
return;
|
||||
|
||||
for (const InfoBarEntry &info : m_infoBar->m_infoBarEntries) {
|
||||
QFrame *infoWidget = new QFrame;
|
||||
|
||||
QPalette pal;
|
||||
if (QTC_GUARD(InfoBar::m_theme)) {
|
||||
pal.setColor(QPalette::Window, InfoBar::m_theme->color(Theme::InfoBarBackground));
|
||||
pal.setColor(QPalette::WindowText, InfoBar::m_theme->color(Theme::InfoBarText));
|
||||
}
|
||||
|
||||
infoWidget->setPalette(pal);
|
||||
infoWidget->setFrameStyle(QFrame::Panel | m_style);
|
||||
infoWidget->setLineWidth(1);
|
||||
infoWidget->setAutoFillBackground(true);
|
||||
|
||||
auto hbox = new QHBoxLayout;
|
||||
hbox->setContentsMargins(2, 2, 2, 2);
|
||||
|
||||
auto vbox = new QVBoxLayout(infoWidget);
|
||||
vbox->setContentsMargins(0, 0, 0, 0);
|
||||
vbox->addLayout(hbox);
|
||||
|
||||
QLabel *infoWidgetLabel = new QLabel(info.m_infoText);
|
||||
infoWidgetLabel->setWordWrap(true);
|
||||
hbox->addWidget(infoWidgetLabel, 1);
|
||||
|
||||
if (info.m_detailsWidgetCreator) {
|
||||
if (m_isShowingDetailsWidget) {
|
||||
QWidget *detailsWidget = info.m_detailsWidgetCreator();
|
||||
vbox->addWidget(detailsWidget);
|
||||
}
|
||||
|
||||
auto showDetailsButton = new QToolButton;
|
||||
showDetailsButton->setCheckable(true);
|
||||
showDetailsButton->setChecked(m_isShowingDetailsWidget);
|
||||
showDetailsButton->setText(tr("&Show Details"));
|
||||
connect(showDetailsButton, &QToolButton::clicked, [this, vbox, info] (bool) {
|
||||
QWidget *detailsWidget = vbox->count() == 2 ? vbox->itemAt(1)->widget() : nullptr;
|
||||
if (!detailsWidget) {
|
||||
detailsWidget = info.m_detailsWidgetCreator();
|
||||
vbox->addWidget(detailsWidget);
|
||||
}
|
||||
|
||||
m_isShowingDetailsWidget = !m_isShowingDetailsWidget;
|
||||
detailsWidget->setVisible(m_isShowingDetailsWidget);
|
||||
});
|
||||
|
||||
hbox->addWidget(showDetailsButton);
|
||||
} else {
|
||||
m_isShowingDetailsWidget = false;
|
||||
}
|
||||
|
||||
if (!info.m_comboInfo.isEmpty()) {
|
||||
auto cb = new QComboBox();
|
||||
cb->addItems(info.m_comboInfo);
|
||||
connect(cb, &QComboBox::currentTextChanged, [info](const QString &text) {
|
||||
info.m_comboCallBack(text);
|
||||
});
|
||||
|
||||
hbox->addWidget(cb);
|
||||
}
|
||||
|
||||
if (!info.m_buttonText.isEmpty()) {
|
||||
auto infoWidgetButton = new QToolButton;
|
||||
infoWidgetButton->setText(info.m_buttonText);
|
||||
connect(infoWidgetButton, &QAbstractButton::clicked, [info]() { info.m_buttonCallBack(); });
|
||||
|
||||
hbox->addWidget(infoWidgetButton);
|
||||
}
|
||||
|
||||
const Id id = info.m_id;
|
||||
QToolButton *infoWidgetSuppressButton = nullptr;
|
||||
if (info.m_globalSuppression == InfoBarEntry::GlobalSuppression::Enabled) {
|
||||
infoWidgetSuppressButton = new QToolButton;
|
||||
infoWidgetSuppressButton->setText(tr("Do Not Show Again"));
|
||||
connect(infoWidgetSuppressButton, &QAbstractButton::clicked, this, [this, id] {
|
||||
m_infoBar->removeInfo(id);
|
||||
InfoBar::globallySuppressInfo(id);
|
||||
});
|
||||
}
|
||||
|
||||
QToolButton *infoWidgetCloseButton = nullptr;
|
||||
if (info.m_useCancelButton) {
|
||||
infoWidgetCloseButton = new QToolButton;
|
||||
// need to connect to cancelObjectbefore connecting to cancelButtonClicked,
|
||||
// because the latter removes the button and with it any connect
|
||||
if (info.m_cancelButtonCallBack)
|
||||
connect(infoWidgetCloseButton, &QAbstractButton::clicked, info.m_cancelButtonCallBack);
|
||||
connect(infoWidgetCloseButton, &QAbstractButton::clicked, this, [this, id] {
|
||||
m_infoBar->suppressInfo(id);
|
||||
});
|
||||
}
|
||||
|
||||
if (info.m_cancelButtonText.isEmpty()) {
|
||||
if (infoWidgetCloseButton) {
|
||||
infoWidgetCloseButton->setAutoRaise(true);
|
||||
infoWidgetCloseButton->setIcon(Utils::Icons::CLOSE_FOREGROUND.icon());
|
||||
infoWidgetCloseButton->setToolTip(tr("Close"));
|
||||
}
|
||||
|
||||
if (infoWidgetSuppressButton)
|
||||
hbox->addWidget(infoWidgetSuppressButton);
|
||||
|
||||
if (infoWidgetCloseButton)
|
||||
hbox->addWidget(infoWidgetCloseButton);
|
||||
} else {
|
||||
infoWidgetCloseButton->setText(info.m_cancelButtonText);
|
||||
hbox->addWidget(infoWidgetCloseButton);
|
||||
if (infoWidgetSuppressButton)
|
||||
hbox->addWidget(infoWidgetSuppressButton);
|
||||
}
|
||||
|
||||
connect(infoWidget, &QObject::destroyed, this, &InfoBarDisplay::widgetDestroyed);
|
||||
m_boxLayout->insertWidget(m_boxIndex, infoWidget);
|
||||
m_infoWidgets << infoWidget;
|
||||
}
|
||||
}
|
||||
|
||||
void InfoBarDisplay::widgetDestroyed()
|
||||
{
|
||||
m_infoWidgets.removeOne(static_cast<QWidget *>(sender()));
|
||||
}
|
||||
|
||||
} // namespace Core
|
||||
@@ -1,148 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core_global.h"
|
||||
#include <coreplugin/id.h>
|
||||
|
||||
#include <QFrame>
|
||||
#include <QObject>
|
||||
#include <QSet>
|
||||
|
||||
#include <functional>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QBoxLayout;
|
||||
class QSettings;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Utils { class Theme; }
|
||||
|
||||
namespace Core {
|
||||
|
||||
class InfoBar;
|
||||
class InfoBarDisplay;
|
||||
|
||||
class CORE_EXPORT InfoBarEntry
|
||||
{
|
||||
public:
|
||||
enum class GlobalSuppression
|
||||
{
|
||||
Disabled,
|
||||
Enabled
|
||||
};
|
||||
|
||||
InfoBarEntry(Id _id, const QString &_infoText, GlobalSuppression _globalSuppression = GlobalSuppression::Disabled);
|
||||
|
||||
using CallBack = std::function<void()>;
|
||||
void setCustomButtonInfo(const QString &_buttonText, CallBack callBack);
|
||||
void setCancelButtonInfo(CallBack callBack);
|
||||
void setCancelButtonInfo(const QString &_cancelButtonText, CallBack callBack);
|
||||
using ComboCallBack = std::function<void(const QString &)>;
|
||||
void setComboInfo(const QStringList &list, ComboCallBack callBack);
|
||||
void removeCancelButton();
|
||||
|
||||
using DetailsWidgetCreator = std::function<QWidget*()>;
|
||||
void setDetailsWidgetCreator(const DetailsWidgetCreator &creator);
|
||||
|
||||
private:
|
||||
Id m_id;
|
||||
QString m_infoText;
|
||||
QString m_buttonText;
|
||||
CallBack m_buttonCallBack;
|
||||
QString m_cancelButtonText;
|
||||
CallBack m_cancelButtonCallBack;
|
||||
GlobalSuppression m_globalSuppression;
|
||||
DetailsWidgetCreator m_detailsWidgetCreator;
|
||||
bool m_useCancelButton = true;
|
||||
ComboCallBack m_comboCallBack;
|
||||
QStringList m_comboInfo;
|
||||
friend class InfoBar;
|
||||
friend class InfoBarDisplay;
|
||||
};
|
||||
|
||||
class CORE_EXPORT InfoBar : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
void addInfo(const InfoBarEntry &info);
|
||||
void removeInfo(Id id);
|
||||
bool containsInfo(Id id) const;
|
||||
void suppressInfo(Id id);
|
||||
bool canInfoBeAdded(Id id) const;
|
||||
void unsuppressInfo(Id id);
|
||||
void clear();
|
||||
static void globallySuppressInfo(Id id);
|
||||
static void globallyUnsuppressInfo(Id id);
|
||||
static void clearGloballySuppressed();
|
||||
static bool anyGloballySuppressed();
|
||||
|
||||
static void initialize(QSettings *settings, Utils::Theme *theme);
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
|
||||
private:
|
||||
static void writeGloballySuppressedToSettings();
|
||||
|
||||
private:
|
||||
QList<InfoBarEntry> m_infoBarEntries;
|
||||
QSet<Id> m_suppressed;
|
||||
|
||||
static QSet<Id> globallySuppressed;
|
||||
static QSettings *m_settings;
|
||||
static Utils::Theme *m_theme;
|
||||
|
||||
friend class InfoBarDisplay;
|
||||
};
|
||||
|
||||
class CORE_EXPORT InfoBarDisplay : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
InfoBarDisplay(QObject *parent = nullptr);
|
||||
void setTarget(QBoxLayout *layout, int index);
|
||||
void setInfoBar(InfoBar *infoBar);
|
||||
void setStyle(QFrame::Shadow style);
|
||||
|
||||
InfoBar *infoBar() const;
|
||||
|
||||
private:
|
||||
void update();
|
||||
void infoBarDestroyed();
|
||||
void widgetDestroyed();
|
||||
|
||||
QList<QWidget *> m_infoWidgets;
|
||||
InfoBar *m_infoBar = nullptr;
|
||||
QBoxLayout *m_boxLayout = nullptr;
|
||||
QFrame::Shadow m_style = QFrame::Raised;
|
||||
int m_boxIndex = 0;
|
||||
bool m_isShowingDetailsWidget = false;
|
||||
};
|
||||
|
||||
} // namespace Core
|
||||
@@ -41,12 +41,15 @@ class QPrinter;
|
||||
class QToolButton;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Utils {
|
||||
class InfoBar;
|
||||
}
|
||||
|
||||
namespace Core {
|
||||
|
||||
class EditorManager;
|
||||
class ExternalToolManager;
|
||||
class IDocument;
|
||||
class InfoBar;
|
||||
class JsExpander;
|
||||
class MessageManager;
|
||||
class ModeManager;
|
||||
@@ -94,7 +97,7 @@ public:
|
||||
virtual QPrinter *printer() const;
|
||||
IContext * currentContextObject() const;
|
||||
QStatusBar *statusBar() const;
|
||||
InfoBar *infoBar() const;
|
||||
Utils::InfoBar *infoBar() const;
|
||||
|
||||
void updateAdditionalContexts(const Context &remove, const Context &add,
|
||||
ICore::ContextPriority priority);
|
||||
|
||||
@@ -28,17 +28,17 @@
|
||||
#include "icore.h"
|
||||
#include "documentmanager.h"
|
||||
#include "idocument.h"
|
||||
#include "infobar.h"
|
||||
|
||||
#include <coreplugin/dialogs/addtovcsdialog.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
|
||||
#include <vcsbase/vcsbaseconstants.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/infobar.h>
|
||||
#include <utils/optional.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <vcsbase/vcsbaseconstants.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QString>
|
||||
@@ -296,12 +296,12 @@ IVersionControl* VcsManager::findVersionControlForDirectory(const QString &input
|
||||
}
|
||||
return versionControl;
|
||||
} else {
|
||||
InfoBar *infoBar = curDocument ? curDocument->infoBar() : nullptr;
|
||||
Utils::InfoBar *infoBar = curDocument ? curDocument->infoBar() : nullptr;
|
||||
if (infoBar && infoBar->canInfoBeAdded(vcsWarning)) {
|
||||
InfoBarEntry info(vcsWarning,
|
||||
tr("%1 repository was detected but %1 is not configured.")
|
||||
.arg(versionControl->displayName()),
|
||||
InfoBarEntry::GlobalSuppression::Enabled);
|
||||
Utils::InfoBarEntry info(vcsWarning,
|
||||
tr("%1 repository was detected but %1 is not configured.")
|
||||
.arg(versionControl->displayName()),
|
||||
Utils::InfoBarEntry::GlobalSuppression::Enabled);
|
||||
d->m_unconfiguredVcs = versionControl;
|
||||
info.setCustomButtonInfo(ICore::msgShowOptionsDialog(), []() {
|
||||
QTC_ASSERT(d->m_unconfiguredVcs, return);
|
||||
|
||||
Reference in New Issue
Block a user