forked from qt-creator/qt-creator
MinimizableInfoBars: Consolidate IDs
For the info bar and the settings. Reduces the information that we need to know and pass on. Change-Id: Ia1c352dc0ed9375534fbbf2c3c0bc879725fa3d5 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -32,8 +32,8 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
const char NO_PROJECT_CONFIGURATION[] = "CppEditor.NoProjectConfiguration";
|
const char NO_PROJECT_CONFIGURATION[] = "NoProject";
|
||||||
const char CPPEDITOR_SHOW_INFO_BAR_FOR_FOR_NO_PROJECT[] = "ShowInfoBarForNoProject";
|
const char SETTINGS_PREFIX[] = "ShowInfoBarFor";
|
||||||
const bool kShowInInfoBarDefault = true;
|
const bool kShowInInfoBarDefault = true;
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
@@ -58,15 +58,18 @@ void MinimizableInfoBars::createActions()
|
|||||||
auto action = new QAction(this);
|
auto action = new QAction(this);
|
||||||
action->setToolTip(tr("File is not part of any project."));
|
action->setToolTip(tr("File is not part of any project."));
|
||||||
action->setIcon(Icons::WARNING_TOOLBAR.pixmap());
|
action->setIcon(Icons::WARNING_TOOLBAR.pixmap());
|
||||||
connect(action, &QAction::triggered, this, [this]() { setShowNoProjectInfoBar(true); });
|
connect(action, &QAction::triggered, this, [this]() {
|
||||||
action->setVisible(!showNoProjectInfoBar());
|
setShowInInfoBar(NO_PROJECT_CONFIGURATION, true);
|
||||||
|
updateNoProjectConfiguration();
|
||||||
|
});
|
||||||
|
action->setVisible(!showInInfoBar(NO_PROJECT_CONFIGURATION));
|
||||||
m_actions.insert(NO_PROJECT_CONFIGURATION, action);
|
m_actions.insert(NO_PROJECT_CONFIGURATION, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MinimizableInfoBars::settingsKey(const QString &id) const
|
QString MinimizableInfoBars::settingsKey(const Id &id) const
|
||||||
{
|
{
|
||||||
QTC_CHECK(!m_settingsGroup.isEmpty());
|
QTC_CHECK(!m_settingsGroup.isEmpty());
|
||||||
return m_settingsGroup + '/' + id;
|
return m_settingsGroup + '/' + SETTINGS_PREFIX + id.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MinimizableInfoBars::createShowInfoBarActions(const ActionCreator &actionCreator) const
|
void MinimizableInfoBars::createShowInfoBarActions(const ActionCreator &actionCreator) const
|
||||||
@@ -97,7 +100,7 @@ void MinimizableInfoBars::updateNoProjectConfiguration()
|
|||||||
|
|
||||||
bool show = false;
|
bool show = false;
|
||||||
if (!m_hasProjectPart) {
|
if (!m_hasProjectPart) {
|
||||||
if (showNoProjectInfoBar())
|
if (showInInfoBar(id))
|
||||||
addNoProjectConfigurationEntry(id);
|
addNoProjectConfigurationEntry(id);
|
||||||
else
|
else
|
||||||
show = true;
|
show = true;
|
||||||
@@ -133,23 +136,20 @@ void MinimizableInfoBars::addNoProjectConfigurationEntry(const Id &id)
|
|||||||
const QString text = tr("<b>Warning</b>: This file is not part of any project. "
|
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.");
|
"The code model might have issues parsing this file properly.");
|
||||||
|
|
||||||
m_infoBar.addInfo(
|
m_infoBar.addInfo(createMinimizableInfo(id, text, this, [this, id]() {
|
||||||
createMinimizableInfo(id, text, this, [this]() { setShowNoProjectInfoBar(false); }));
|
setShowInInfoBar(id, false);
|
||||||
}
|
|
||||||
|
|
||||||
bool MinimizableInfoBars::showNoProjectInfoBar() const
|
|
||||||
{
|
|
||||||
return ICore::settings()
|
|
||||||
->value(settingsKey(CPPEDITOR_SHOW_INFO_BAR_FOR_FOR_NO_PROJECT), kShowInInfoBarDefault)
|
|
||||||
.toBool();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MinimizableInfoBars::setShowNoProjectInfoBar(bool show)
|
|
||||||
{
|
|
||||||
ICore::settings()->setValueWithDefault(settingsKey(CPPEDITOR_SHOW_INFO_BAR_FOR_FOR_NO_PROJECT),
|
|
||||||
show,
|
|
||||||
kShowInInfoBarDefault);
|
|
||||||
updateNoProjectConfiguration();
|
updateNoProjectConfiguration();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MinimizableInfoBars::showInInfoBar(const Id &id) const
|
||||||
|
{
|
||||||
|
return ICore::settings()->value(settingsKey(id), kShowInInfoBarDefault).toBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MinimizableInfoBars::setShowInInfoBar(const Id &id, bool show)
|
||||||
|
{
|
||||||
|
ICore::settings()->setValueWithDefault(settingsKey(id), show, kShowInInfoBarDefault);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -58,11 +58,9 @@ public:
|
|||||||
private:
|
private:
|
||||||
void createActions();
|
void createActions();
|
||||||
|
|
||||||
QString settingsKey(const QString &id) const;
|
QString settingsKey(const Utils::Id &id) const;
|
||||||
bool showHeaderErrorInfoBar() const;
|
bool showInInfoBar(const Utils::Id &id) const;
|
||||||
void setShowHeaderErrorInfoBar(bool show);
|
void setShowInInfoBar(const Utils::Id &id, bool show);
|
||||||
bool showNoProjectInfoBar() const;
|
|
||||||
void setShowNoProjectInfoBar(bool show);
|
|
||||||
|
|
||||||
void updateNoProjectConfiguration();
|
void updateNoProjectConfiguration();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user