forked from qt-creator/qt-creator
MinimizableInfoBars: Move toolbar visibility handling
Remove some coupling between CppEditorWidget and MinimizableInfoBars by handing the visibility of the toolbar buttons solely within MinimizableInfoBars. Change-Id: I5abf59187ea9b37fd13c91d63b2c82a1caa67275 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -424,7 +424,6 @@ public:
|
||||
QAction *m_parseContextAction = nullptr;
|
||||
ParseContextWidget *m_parseContextWidget = nullptr;
|
||||
QToolButton *m_preprocessorButton = nullptr;
|
||||
MinimizableInfoBars::Actions m_showInfoBarActions;
|
||||
|
||||
CppLocalRenaming m_localRenaming;
|
||||
CppUseSelectionsUpdater m_useSelectionsUpdater;
|
||||
@@ -555,11 +554,8 @@ void CppEditorWidget::finalizeInitialization()
|
||||
}
|
||||
|
||||
// Toolbar: Actions to show minimized info bars
|
||||
d->m_showInfoBarActions = MinimizableInfoBars::createShowInfoBarActions([this](QWidget *w) {
|
||||
return this->insertExtraToolBarWidget(TextEditorWidget::Left, w);
|
||||
});
|
||||
connect(&cppEditorDocument()->minimizableInfoBars(), &MinimizableInfoBars::showAction,
|
||||
this, &CppEditorWidget::onShowInfoBarAction);
|
||||
d->m_cppEditorDocument->minimizableInfoBars().createShowInfoBarActions(
|
||||
[this](QWidget *w) { return this->insertExtraToolBarWidget(TextEditorWidget::Left, w); });
|
||||
|
||||
d->m_outlineTimer.setInterval(5000);
|
||||
d->m_outlineTimer.setSingleShot(true);
|
||||
@@ -672,13 +668,6 @@ void CppEditorWidget::onIfdefedOutBlocksUpdated(unsigned revision,
|
||||
textDocument()->setIfdefedOutBlocks(ifdefedOutBlocks);
|
||||
}
|
||||
|
||||
void CppEditorWidget::onShowInfoBarAction(const Id &id, bool show)
|
||||
{
|
||||
QAction *action = d->m_showInfoBarActions.value(id);
|
||||
QTC_ASSERT(action, return);
|
||||
action->setVisible(show);
|
||||
}
|
||||
|
||||
static QString getDocumentLine(QTextDocument *document, int line)
|
||||
{
|
||||
if (document)
|
||||
|
||||
@@ -136,8 +136,6 @@ private:
|
||||
void onIfdefedOutBlocksUpdated(unsigned revision,
|
||||
const QList<TextEditor::BlockRange> ifdefedOutBlocks);
|
||||
|
||||
void onShowInfoBarAction(const Utils::Id &id, bool show);
|
||||
|
||||
void updateSemanticInfo(const SemanticInfo &semanticInfo,
|
||||
bool updateUseSelectionSynchronously = false);
|
||||
void updatePreprocessorButtonTooltip();
|
||||
|
||||
@@ -47,26 +47,33 @@ MinimizableInfoBars::MinimizableInfoBars(InfoBar &infoBar, QObject *parent)
|
||||
{
|
||||
connect(settings(), &CppToolsSettings::showNoProjectInfoBarChanged,
|
||||
this, &MinimizableInfoBars::updateNoProjectConfiguration);
|
||||
createActions();
|
||||
}
|
||||
|
||||
MinimizableInfoBars::Actions MinimizableInfoBars::createShowInfoBarActions(
|
||||
const ActionCreator &actionCreator)
|
||||
void MinimizableInfoBars::createActions()
|
||||
{
|
||||
Actions result;
|
||||
QTC_ASSERT(actionCreator, return result);
|
||||
|
||||
// No project configuration available
|
||||
auto *button = new QToolButton();
|
||||
button->setToolTip(tr("File is not part of any project."));
|
||||
button->setIcon(Utils::Icons::WARNING_TOOLBAR.pixmap());
|
||||
connect(button, &QAbstractButton::clicked, []() {
|
||||
settings()->setShowNoProjectInfoBar(true);
|
||||
});
|
||||
QAction *action = actionCreator(button);
|
||||
auto action = new QAction(this);
|
||||
action->setToolTip(tr("File is not part of any project."));
|
||||
action->setIcon(Icons::WARNING_TOOLBAR.pixmap());
|
||||
connect(action, &QAction::triggered, []() { settings()->setShowNoProjectInfoBar(true); });
|
||||
action->setVisible(!settings()->showNoProjectInfoBar());
|
||||
result.insert(Constants::NO_PROJECT_CONFIGURATION, action);
|
||||
m_actions.insert(Constants::NO_PROJECT_CONFIGURATION, action);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void MinimizableInfoBars::createShowInfoBarActions(const ActionCreator &actionCreator) const
|
||||
{
|
||||
QTC_ASSERT(actionCreator, return );
|
||||
|
||||
for (QAction *action : m_actions) {
|
||||
auto *button = new QToolButton();
|
||||
button->setDefaultAction(action);
|
||||
QAction *toolbarAction = actionCreator(button);
|
||||
connect(action, &QAction::changed, toolbarAction, [action, toolbarAction] {
|
||||
toolbarAction->setVisible(action->isVisible());
|
||||
});
|
||||
toolbarAction->setVisible(action->isVisible());
|
||||
}
|
||||
}
|
||||
|
||||
void MinimizableInfoBars::processHasProjectPart(bool hasProjectPart)
|
||||
@@ -88,7 +95,9 @@ void MinimizableInfoBars::updateNoProjectConfiguration()
|
||||
show = true;
|
||||
}
|
||||
|
||||
emit showAction(id, show);
|
||||
QAction *action = m_actions.value(id);
|
||||
if (QTC_GUARD(action))
|
||||
action->setVisible(show);
|
||||
}
|
||||
|
||||
static InfoBarEntry createMinimizableInfo(const Id &id,
|
||||
|
||||
@@ -46,25 +46,24 @@ class MinimizableInfoBars : public QObject
|
||||
|
||||
public:
|
||||
using ActionCreator = std::function<QAction *(QWidget *widget)>;
|
||||
using Actions = QHash<Utils::Id, QAction *>;
|
||||
|
||||
static Actions createShowInfoBarActions(const ActionCreator &actionCreator);
|
||||
|
||||
public:
|
||||
explicit MinimizableInfoBars(Utils::InfoBar &infoBar, QObject *parent = nullptr);
|
||||
|
||||
void createShowInfoBarActions(const ActionCreator &actionCreator) const;
|
||||
|
||||
void processHasProjectPart(bool hasProjectPart);
|
||||
|
||||
signals:
|
||||
void showAction(const Utils::Id &id, bool show);
|
||||
|
||||
private:
|
||||
void createActions();
|
||||
|
||||
void updateNoProjectConfiguration();
|
||||
|
||||
void addNoProjectConfigurationEntry(const Utils::Id &id);
|
||||
|
||||
private:
|
||||
Utils::InfoBar &m_infoBar;
|
||||
QHash<Utils::Id, QAction *> m_actions;
|
||||
|
||||
bool m_hasProjectPart = true;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user