forked from qt-creator/qt-creator
MinimizableInfoBars: Remove last hardcoded things
Change-Id: I6ec1e290056d97136077c0ddbc161669c7225eba Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -85,6 +85,16 @@ InfoBarEntry::InfoBarEntry(Id _id, const QString &_infoText, GlobalSuppression _
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Id InfoBarEntry::id() const
|
||||||
|
{
|
||||||
|
return m_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString InfoBarEntry::text() const
|
||||||
|
{
|
||||||
|
return m_infoText;
|
||||||
|
}
|
||||||
|
|
||||||
void InfoBarEntry::addCustomButton(const QString &buttonText,
|
void InfoBarEntry::addCustomButton(const QString &buttonText,
|
||||||
CallBack callBack,
|
CallBack callBack,
|
||||||
const QString &tooltip)
|
const QString &tooltip)
|
||||||
|
@@ -54,8 +54,12 @@ public:
|
|||||||
Enabled
|
Enabled
|
||||||
};
|
};
|
||||||
|
|
||||||
|
InfoBarEntry() = default;
|
||||||
InfoBarEntry(Id _id, const QString &_infoText, GlobalSuppression _globalSuppression = GlobalSuppression::Disabled);
|
InfoBarEntry(Id _id, const QString &_infoText, GlobalSuppression _globalSuppression = GlobalSuppression::Disabled);
|
||||||
|
|
||||||
|
Id id() const;
|
||||||
|
QString text() const;
|
||||||
|
|
||||||
using CallBack = std::function<void()>;
|
using CallBack = std::function<void()>;
|
||||||
void addCustomButton(const QString &_buttonText, CallBack callBack, const QString &tooltip = {});
|
void addCustomButton(const QString &_buttonText, CallBack callBack, const QString &tooltip = {});
|
||||||
void setCancelButtonInfo(CallBack callBack);
|
void setCancelButtonInfo(CallBack callBack);
|
||||||
|
@@ -55,6 +55,8 @@
|
|||||||
|
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
|
|
||||||
|
const char NO_PROJECT_CONFIGURATION[] = "NoProject";
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
CppEditor::CppModelManager *mm()
|
CppEditor::CppModelManager *mm()
|
||||||
@@ -129,6 +131,10 @@ CppEditorDocument::CppEditorDocument()
|
|||||||
this, &CppEditorDocument::reparseWithPreferredParseContext);
|
this, &CppEditorDocument::reparseWithPreferredParseContext);
|
||||||
|
|
||||||
m_minimizableInfoBars.setSettingsGroup(Constants::CPPEDITOR_SETTINGSGROUP);
|
m_minimizableInfoBars.setSettingsGroup(Constants::CPPEDITOR_SETTINGSGROUP);
|
||||||
|
m_minimizableInfoBars.setPossibleInfoBarEntries(
|
||||||
|
{{NO_PROJECT_CONFIGURATION,
|
||||||
|
tr("<b>Warning</b>: This file is not part of any project. "
|
||||||
|
"The code model might have issues parsing this file properly.")}});
|
||||||
|
|
||||||
// See also onFilePathChanged() for more initialization
|
// See also onFilePathChanged() for more initialization
|
||||||
}
|
}
|
||||||
@@ -420,7 +426,7 @@ BaseEditorDocumentProcessor *CppEditorDocument::processor()
|
|||||||
[this] (const ProjectPartInfo &info)
|
[this] (const ProjectPartInfo &info)
|
||||||
{
|
{
|
||||||
const bool hasProjectPart = !(info.hints & ProjectPartInfo::IsFallbackMatch);
|
const bool hasProjectPart = !(info.hints & ProjectPartInfo::IsFallbackMatch);
|
||||||
m_minimizableInfoBars.processHasProjectPart(hasProjectPart);
|
m_minimizableInfoBars.setInfoVisible(NO_PROJECT_CONFIGURATION, !hasProjectPart);
|
||||||
m_parseContextModel.update(info);
|
m_parseContextModel.update(info);
|
||||||
const bool isAmbiguous = info.hints & ProjectPartInfo::IsAmbiguousMatch;
|
const bool isAmbiguous = info.hints & ProjectPartInfo::IsAmbiguousMatch;
|
||||||
const bool isProjectFile = info.hints & ProjectPartInfo::IsFromProjectMatch;
|
const bool isProjectFile = info.hints & ProjectPartInfo::IsFromProjectMatch;
|
||||||
|
@@ -32,7 +32,6 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
const char NO_PROJECT_CONFIGURATION[] = "NoProject";
|
|
||||||
const char SETTINGS_PREFIX[] = "ShowInfoBarFor";
|
const char SETTINGS_PREFIX[] = "ShowInfoBarFor";
|
||||||
const bool kShowInInfoBarDefault = true;
|
const bool kShowInInfoBarDefault = true;
|
||||||
|
|
||||||
@@ -45,6 +44,17 @@ namespace Internal {
|
|||||||
MinimizableInfoBars::MinimizableInfoBars(InfoBar &infoBar)
|
MinimizableInfoBars::MinimizableInfoBars(InfoBar &infoBar)
|
||||||
: m_infoBar(infoBar)
|
: m_infoBar(infoBar)
|
||||||
{
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void MinimizableInfoBars::setPossibleInfoBarEntries(const QList<Utils::InfoBarEntry> &entries)
|
||||||
|
{
|
||||||
|
QTC_CHECK(m_actions.isEmpty());
|
||||||
|
m_infoEntries.clear();
|
||||||
|
m_isInfoVisible.clear();
|
||||||
|
for (const Utils::InfoBarEntry &entry : entries) {
|
||||||
|
m_infoEntries.insert(entry.id(), entry);
|
||||||
|
m_isInfoVisible.insert(entry.id(), false);
|
||||||
|
}
|
||||||
createActions();
|
createActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,15 +65,19 @@ void MinimizableInfoBars::setSettingsGroup(const QString &settingsGroup)
|
|||||||
|
|
||||||
void MinimizableInfoBars::createActions()
|
void MinimizableInfoBars::createActions()
|
||||||
{
|
{
|
||||||
|
QTC_CHECK(m_actions.isEmpty());
|
||||||
|
for (const Utils::InfoBarEntry &entry : qAsConst(m_infoEntries)) {
|
||||||
|
const Id id = entry.id();
|
||||||
auto action = new QAction(this);
|
auto action = new QAction(this);
|
||||||
action->setToolTip(tr("File is not part of any project."));
|
action->setToolTip(entry.text());
|
||||||
action->setIcon(Icons::WARNING_TOOLBAR.pixmap());
|
action->setIcon(Icons::WARNING_TOOLBAR.pixmap());
|
||||||
connect(action, &QAction::triggered, this, [this]() {
|
connect(action, &QAction::triggered, this, [this, id]() {
|
||||||
setShowInInfoBar(NO_PROJECT_CONFIGURATION, true);
|
setShowInInfoBar(id, true);
|
||||||
updateNoProjectConfiguration();
|
updateInfo(id);
|
||||||
});
|
});
|
||||||
action->setVisible(!showInInfoBar(NO_PROJECT_CONFIGURATION));
|
action->setVisible(!showInInfoBar(id));
|
||||||
m_actions.insert(NO_PROJECT_CONFIGURATION, action);
|
m_actions.insert(id, action);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MinimizableInfoBars::settingsKey(const Id &id) const
|
QString MinimizableInfoBars::settingsKey(const Id &id) const
|
||||||
@@ -87,21 +101,21 @@ void MinimizableInfoBars::createShowInfoBarActions(const ActionCreator &actionCr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MinimizableInfoBars::processHasProjectPart(bool hasProjectPart)
|
void MinimizableInfoBars::setInfoVisible(const Id &id, bool visible)
|
||||||
{
|
{
|
||||||
m_hasProjectPart = hasProjectPart;
|
QTC_CHECK(m_isInfoVisible.contains(id));
|
||||||
updateNoProjectConfiguration();
|
m_isInfoVisible.insert(id, visible);
|
||||||
|
updateInfo(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MinimizableInfoBars::updateNoProjectConfiguration()
|
void MinimizableInfoBars::updateInfo(const Id &id)
|
||||||
{
|
{
|
||||||
const Id id(NO_PROJECT_CONFIGURATION);
|
|
||||||
m_infoBar.removeInfo(id);
|
m_infoBar.removeInfo(id);
|
||||||
|
|
||||||
bool show = false;
|
bool show = false;
|
||||||
if (!m_hasProjectPart) {
|
if (m_isInfoVisible.value(id)) {
|
||||||
if (showInInfoBar(id))
|
if (showInInfoBar(id))
|
||||||
addNoProjectConfigurationEntry(id);
|
showInfoBar(id);
|
||||||
else
|
else
|
||||||
show = true;
|
show = true;
|
||||||
}
|
}
|
||||||
@@ -111,35 +125,24 @@ void MinimizableInfoBars::updateNoProjectConfiguration()
|
|||||||
action->setVisible(show);
|
action->setVisible(show);
|
||||||
}
|
}
|
||||||
|
|
||||||
static InfoBarEntry createMinimizableInfo(const Id &id,
|
void MinimizableInfoBars::showInfoBar(const Id &id)
|
||||||
const QString &text,
|
|
||||||
QObject *guard,
|
|
||||||
std::function<void()> minimizer)
|
|
||||||
{
|
{
|
||||||
QTC_CHECK(minimizer);
|
const InfoBarEntry entry = m_infoEntries.value(id);
|
||||||
|
InfoBarEntry info(entry);
|
||||||
InfoBarEntry info(id, text);
|
|
||||||
info.removeCancelButton();
|
info.removeCancelButton();
|
||||||
// The minimizer() might delete the "Minimize" button immediately and as
|
// The minimizer() might delete the "Minimize" button immediately and as
|
||||||
// result invalid reads will happen in QToolButton::mouseReleaseEvent().
|
// result invalid reads will happen in QToolButton::mouseReleaseEvent().
|
||||||
// Avoid this by running the minimizer in the next event loop iteration.
|
// Avoid this by running the minimizer in the next event loop iteration.
|
||||||
info.addCustomButton(MinimizableInfoBars::tr("Minimize"), [guard, minimizer] {
|
info.addCustomButton(MinimizableInfoBars::tr("Minimize"), [this, id] {
|
||||||
QMetaObject::invokeMethod(
|
QMetaObject::invokeMethod(
|
||||||
guard, [minimizer] { minimizer(); }, Qt::QueuedConnection);
|
this,
|
||||||
});
|
[id, this] {
|
||||||
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MinimizableInfoBars::addNoProjectConfigurationEntry(const Id &id)
|
|
||||||
{
|
|
||||||
const QString text = tr("<b>Warning</b>: This file is not part of any project. "
|
|
||||||
"The code model might have issues parsing this file properly.");
|
|
||||||
|
|
||||||
m_infoBar.addInfo(createMinimizableInfo(id, text, this, [this, id]() {
|
|
||||||
setShowInInfoBar(id, false);
|
setShowInInfoBar(id, false);
|
||||||
updateNoProjectConfiguration();
|
updateInfo(id);
|
||||||
}));
|
},
|
||||||
|
Qt::QueuedConnection);
|
||||||
|
});
|
||||||
|
m_infoBar.addInfo(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MinimizableInfoBars::showInInfoBar(const Id &id) const
|
bool MinimizableInfoBars::showInInfoBar(const Id &id) const
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <utils/id.h>
|
#include <utils/id.h>
|
||||||
|
#include <utils/infobar.h>
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
@@ -33,10 +34,6 @@
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
namespace Utils {
|
|
||||||
class InfoBar;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace CppEditor {
|
namespace CppEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -51,9 +48,11 @@ public:
|
|||||||
explicit MinimizableInfoBars(Utils::InfoBar &infoBar);
|
explicit MinimizableInfoBars(Utils::InfoBar &infoBar);
|
||||||
|
|
||||||
void setSettingsGroup(const QString &settingsGroup);
|
void setSettingsGroup(const QString &settingsGroup);
|
||||||
|
void setPossibleInfoBarEntries(const QList<Utils::InfoBarEntry> &entries);
|
||||||
|
|
||||||
void createShowInfoBarActions(const ActionCreator &actionCreator) const;
|
void createShowInfoBarActions(const ActionCreator &actionCreator) const;
|
||||||
|
|
||||||
void processHasProjectPart(bool hasProjectPart);
|
void setInfoVisible(const Utils::Id &id, bool visible);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createActions();
|
void createActions();
|
||||||
@@ -62,16 +61,16 @@ private:
|
|||||||
bool showInInfoBar(const Utils::Id &id) const;
|
bool showInInfoBar(const Utils::Id &id) const;
|
||||||
void setShowInInfoBar(const Utils::Id &id, bool show);
|
void setShowInInfoBar(const Utils::Id &id, bool show);
|
||||||
|
|
||||||
void updateNoProjectConfiguration();
|
void updateInfo(const Utils::Id &id);
|
||||||
|
|
||||||
void addNoProjectConfigurationEntry(const Utils::Id &id);
|
void showInfoBar(const Utils::Id &id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Utils::InfoBar &m_infoBar;
|
Utils::InfoBar &m_infoBar;
|
||||||
QString m_settingsGroup;
|
QString m_settingsGroup;
|
||||||
QHash<Utils::Id, QAction *> m_actions;
|
QHash<Utils::Id, QAction *> m_actions;
|
||||||
|
QHash<Utils::Id, bool> m_isInfoVisible;
|
||||||
bool m_hasProjectPart = true;
|
QHash<Utils::Id, Utils::InfoBarEntry> m_infoEntries;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
Reference in New Issue
Block a user