diff --git a/src/plugins/coreplugin/infobar.cpp b/src/plugins/coreplugin/infobar.cpp index 9fcc7ce18ae..7c301af8a30 100644 --- a/src/plugins/coreplugin/infobar.cpp +++ b/src/plugins/coreplugin/infobar.cpp @@ -68,11 +68,6 @@ void InfoBarEntry::setCancelButtonInfo(const QString &_cancelButtonText, CallBac m_cancelButtonCallBack = callBack; } -void InfoBarEntry::setSuppressionButtonInfo(InfoBarEntry::CallBack callback) -{ - m_suppressionButtonCallBack = callback; -} - void InfoBarEntry::setShowDefaultCancelButton(bool yesno) { m_showDefaultCancelButton = yesno; @@ -282,9 +277,7 @@ void InfoBarDisplay::update() if (info.globalSuppression == InfoBarEntry::GlobalSuppressionEnabled) { infoWidgetSuppressButton = new QToolButton; infoWidgetSuppressButton->setText(tr("Do Not Show Again")); - connect(infoWidgetSuppressButton, &QAbstractButton::clicked, this, [this, info, id] { - if (info.m_suppressionButtonCallBack) - info.m_suppressionButtonCallBack(); + connect(infoWidgetSuppressButton, &QAbstractButton::clicked, this, [this, id] { m_infoBar->removeInfo(id); InfoBar::globallySuppressInfo(id); }); diff --git a/src/plugins/coreplugin/infobar.h b/src/plugins/coreplugin/infobar.h index e832e570055..c5d1120fc33 100644 --- a/src/plugins/coreplugin/infobar.h +++ b/src/plugins/coreplugin/infobar.h @@ -58,7 +58,6 @@ public: void setCustomButtonInfo(const QString &_buttonText, CallBack callBack); void setCancelButtonInfo(CallBack callBack); void setCancelButtonInfo(const QString &_cancelButtonText, CallBack callBack); - void setSuppressionButtonInfo(CallBack callback); void setShowDefaultCancelButton(bool yesno); using DetailsWidgetCreator = std::function; @@ -71,7 +70,6 @@ private: CallBack m_buttonCallBack; QString cancelButtonText; CallBack m_cancelButtonCallBack; - CallBack m_suppressionButtonCallBack; GlobalSuppressionMode globalSuppression; DetailsWidgetCreator m_detailsWidgetCreator; bool m_showDefaultCancelButton = true; diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index 0492635d1a6..4b861658fc0 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -130,7 +131,7 @@ public: QScopedPointer m_followSymbolUnderCursor; QToolButton *m_preprocessorButton = nullptr; - QToolButton *m_headerErrorsIndicatorButton = nullptr; + QAction *m_headerErrorsIndicatorAction = nullptr; CppSelectionChanger m_cppSelectionChanger; @@ -229,15 +230,20 @@ void CppEditorWidget::finalizeInitialization() connect(cmd, &Command::keySequenceChanged, this, &CppEditorWidget::updatePreprocessorButtonTooltip); updatePreprocessorButtonTooltip(); connect(d->m_preprocessorButton, &QAbstractButton::clicked, this, &CppEditorWidget::showPreProcessorWidget); - - d->m_headerErrorsIndicatorButton = new QToolButton(this); - d->m_headerErrorsIndicatorButton->setIcon(Utils::Icons::WARNING_TOOLBAR.pixmap()); - connect(d->m_headerErrorsIndicatorButton, &QAbstractButton::clicked, - this, &CppEditorWidget::showHeaderErrorInfoBar); - d->m_headerErrorsIndicatorButton->setEnabled(false); - insertExtraToolBarWidget(TextEditorWidget::Left, d->m_preprocessorButton); - insertExtraToolBarWidget(TextEditorWidget::Left, d->m_headerErrorsIndicatorButton); + + auto *headerErrorsIndicatorButton = new QToolButton(this); + headerErrorsIndicatorButton->setToolTip(tr("Show First Error in Included Files")); + headerErrorsIndicatorButton->setIcon(Utils::Icons::WARNING_TOOLBAR.pixmap()); + connect(headerErrorsIndicatorButton, &QAbstractButton::clicked, []() { + CppToolsSettings::instance()->setShowHeaderErrorInfoBar(true); + }); + d->m_headerErrorsIndicatorAction = insertExtraToolBarWidget(TextEditorWidget::Left, + headerErrorsIndicatorButton); + d->m_headerErrorsIndicatorAction->setVisible(false); + connect(CppToolsSettings::instance(), &CppToolsSettings::showHeaderErrorInfoBarChanged, + this, &CppEditorWidget::updateHeaderErrorWidgets); + insertExtraToolBarWidget(TextEditorWidget::Left, d->m_cppEditorOutline->widget()); } @@ -252,6 +258,10 @@ void CppEditorWidget::finalizeInitializationAfterDuplication(TextEditorWidget *o d->m_cppEditorOutline->update(); const Id selectionKind = CodeWarningsSelection; setExtraSelections(selectionKind, cppEditorWidget->extraSelections(selectionKind)); + + d->m_headerErrorDiagnosticWidgetCreator + = cppEditorWidget->d->m_headerErrorDiagnosticWidgetCreator; + updateHeaderErrorWidgets(); } CppEditorWidget::~CppEditorWidget() @@ -329,13 +339,14 @@ void CppEditorWidget::updateHeaderErrorWidgets() infoBar->removeInfo(id); if (d->m_headerErrorDiagnosticWidgetCreator) { - if (infoBar->canInfoBeAdded(id)) { - addHeaderErrorInfoBarEntryAndHideIndicator(); + if (CppToolsSettings::instance()->showHeaderErrorInfoBar()) { + addHeaderErrorInfoBarEntry(); + d->m_headerErrorsIndicatorAction->setVisible(false); } else { - d->m_headerErrorsIndicatorButton->setEnabled(true); + d->m_headerErrorsIndicatorAction->setVisible(true); } } else { - d->m_headerErrorsIndicatorButton->setEnabled(false); + d->m_headerErrorsIndicatorAction->setVisible(false); } } @@ -434,23 +445,20 @@ void CppEditorWidget::renameSymbolUnderCursorBuiltin() renameUsages(); // Rename non-local symbol or macro } -void CppEditorWidget::addHeaderErrorInfoBarEntryAndHideIndicator() const +void CppEditorWidget::addHeaderErrorInfoBarEntry() const { InfoBarEntry info(Constants::ERRORS_IN_HEADER_FILES, tr("Warning: The code model could not parse an included file, " "which might lead to slow or incorrect code completion and " - "highlighting, for example."), - InfoBarEntry::GlobalSuppressionEnabled); + "highlighting, for example.")); info.setDetailsWidgetCreator(d->m_headerErrorDiagnosticWidgetCreator); info.setShowDefaultCancelButton(false); - info.setSuppressionButtonInfo([this](){ - d->m_headerErrorsIndicatorButton->setEnabled(true); + info.setCustomButtonInfo("Minimize", [](){ + CppToolsSettings::instance()->setShowHeaderErrorInfoBar(false); }); InfoBar *infoBar = textDocument()->infoBar(); infoBar->addInfo(info); - - d->m_headerErrorsIndicatorButton->setEnabled(false); } namespace { @@ -1024,14 +1032,5 @@ void CppEditorWidget::showPreProcessorWidget() } } -void CppEditorWidget::showHeaderErrorInfoBar() -{ - const Id id(Constants::ERRORS_IN_HEADER_FILES); - QTC_CHECK(!textDocument()->infoBar()->canInfoBeAdded(id)); - - InfoBar::globallyUnsuppressInfo(id); - addHeaderErrorInfoBarEntryAndHideIndicator(); -} - } // namespace Internal } // namespace CppEditor diff --git a/src/plugins/cppeditor/cppeditor.h b/src/plugins/cppeditor/cppeditor.h index cce22cebcd4..9475710480d 100644 --- a/src/plugins/cppeditor/cppeditor.h +++ b/src/plugins/cppeditor/cppeditor.h @@ -31,10 +31,6 @@ #include -namespace Core { -class InfoBarEntry; -} - namespace CppTools { class CppEditorOutline; class RefactoringEngineInterface; @@ -91,7 +87,6 @@ public: void switchDeclarationDefinition(bool inNextSplit); void showPreProcessorWidget(); - void showHeaderErrorInfoBar(); void findUsages(); void renameSymbolUnderCursor(); @@ -150,7 +145,7 @@ private: void renameSymbolUnderCursorClang(); void renameSymbolUnderCursorBuiltin(); - void addHeaderErrorInfoBarEntryAndHideIndicator() const; + void addHeaderErrorInfoBarEntry() const; CppTools::ProjectPart *projectPart() const; diff --git a/src/plugins/cpptools/cpptoolsconstants.h b/src/plugins/cpptools/cpptoolsconstants.h index b82ecad14e2..11a5f1a1abf 100644 --- a/src/plugins/cpptools/cpptoolsconstants.h +++ b/src/plugins/cpptools/cpptoolsconstants.h @@ -49,6 +49,7 @@ const char CPPTOOLS_SETTINGSGROUP[] = "CppTools"; const char LOWERCASE_CPPFILES_KEY[] = "LowerCaseFiles"; enum { lowerCaseFilesDefault = 1 }; const char CPPTOOLS_SORT_EDITOR_DOCUMENT_OUTLINE[] = "SortedMethodOverview"; +const char CPPTOOLS_SHOW_INFO_BAR_FOR_HEADER_ERRORS[] = "ShowInfoBarForHeaderErrors"; const char CPPTOOLS_MODEL_MANAGER_PCH_USAGE[] = "PCHUsage"; const char CPPTOOLS_SKIP_INDEXING_BIG_FILES[] = "SkipIndexingBigFiles"; const char CPPTOOLS_INDEXER_FILE_SIZE_LIMIT[] = "IndexerFileSizeLimit"; diff --git a/src/plugins/cpptools/cpptoolssettings.cpp b/src/plugins/cpptools/cpptoolssettings.cpp index 0b122520df1..fbfbce7a4dc 100644 --- a/src/plugins/cpptools/cpptoolssettings.cpp +++ b/src/plugins/cpptools/cpptoolssettings.cpp @@ -267,3 +267,21 @@ void CppToolsSettings::setSortedEditorDocumentOutline(bool sorted) ICore::settings()->setValue(sortEditorDocumentOutlineKey(), sorted); emit editorDocumentOutlineSortingChanged(sorted); } + +static QString showHeaderErrorInfoBarKey() +{ + return QLatin1String(CppTools::Constants::CPPTOOLS_SETTINGSGROUP) + + QLatin1Char('/') + + QLatin1String(CppTools::Constants::CPPTOOLS_SHOW_INFO_BAR_FOR_HEADER_ERRORS); +} + +bool CppToolsSettings::showHeaderErrorInfoBar() const +{ + return ICore::settings()->value(showHeaderErrorInfoBarKey(), true).toBool(); +} + +void CppToolsSettings::setShowHeaderErrorInfoBar(bool show) +{ + ICore::settings()->setValue(showHeaderErrorInfoBarKey(), show); + emit showHeaderErrorInfoBarChanged(show); +} diff --git a/src/plugins/cpptools/cpptoolssettings.h b/src/plugins/cpptools/cpptoolssettings.h index e36956be1a2..a118d700042 100644 --- a/src/plugins/cpptools/cpptoolssettings.h +++ b/src/plugins/cpptools/cpptoolssettings.h @@ -63,8 +63,12 @@ public: bool sortedEditorDocumentOutline() const; void setSortedEditorDocumentOutline(bool sorted); + bool showHeaderErrorInfoBar() const; + void setShowHeaderErrorInfoBar(bool show); + signals: void editorDocumentOutlineSortingChanged(bool isSorted); + void showHeaderErrorInfoBarChanged(bool isShown); private: Internal::CppToolsSettingsPrivate *d; diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index db9efb356a2..5b1f0f6d7ac 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -7035,8 +7035,8 @@ QWidget *BaseTextEditor::toolBar() return editorWidget()->d->m_toolBar; } -void TextEditorWidget::insertExtraToolBarWidget(TextEditorWidget::Side side, - QWidget *widget) +QAction * TextEditorWidget::insertExtraToolBarWidget(TextEditorWidget::Side side, + QWidget *widget) { if (widget->sizePolicy().horizontalPolicy() & QSizePolicy::ExpandFlag) { if (d->m_stretchWidget) @@ -7045,9 +7045,9 @@ void TextEditorWidget::insertExtraToolBarWidget(TextEditorWidget::Side side, } if (side == Right) - d->m_toolBar->insertWidget(d->m_cursorPositionLabelAction, widget); + return d->m_toolBar->insertWidget(d->m_cursorPositionLabelAction, widget); else - d->m_toolBar->insertWidget(d->m_toolBar->actions().first(), widget); + return d->m_toolBar->insertWidget(d->m_toolBar->actions().first(), widget); } void TextEditorWidget::keepAutoCompletionHighlight(bool keepHighlight) diff --git a/src/plugins/texteditor/texteditor.h b/src/plugins/texteditor/texteditor.h index 60038d73ed9..2cd60da3806 100644 --- a/src/plugins/texteditor/texteditor.h +++ b/src/plugins/texteditor/texteditor.h @@ -322,7 +322,7 @@ public: bool isMissingSyntaxDefinition() const; enum Side { Left, Right }; - void insertExtraToolBarWidget(Side side, QWidget *widget); + QAction *insertExtraToolBarWidget(Side side, QWidget *widget); // keep the auto completion even if the focus is lost void keepAutoCompletionHighlight(bool keepHighlight);