forked from qt-creator/qt-creator
CppEditor: Clean up header error indicator
* Show/hide the error indicator button instead of enabling/disabling it. * Use "Minimize" instead of "Do Not Show Again" in the info bar button and use a custom setting to save this. The current info bar API does not signal addition/removal of global suppression ids which would be needed to update all editor widgets properly. We are the only client and it feels wrong to add this API there at the moment. * Remove not needed code anymore. Change-Id: I2bb872522b7410434f060cc359a3b62dfed0af4d Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
@@ -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<QWidget*()>;
|
||||
@@ -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;
|
||||
|
@@ -56,6 +56,7 @@
|
||||
#include <cpptools/cpptoolsconstants.h>
|
||||
#include <cpptools/cpptoolsplugin.h>
|
||||
#include <cpptools/cpptoolsreuse.h>
|
||||
#include <cpptools/cpptoolssettings.h>
|
||||
#include <cpptools/cppworkingcopy.h>
|
||||
#include <cpptools/symbolfinder.h>
|
||||
#include <cpptools/refactoringengineinterface.h>
|
||||
@@ -130,7 +131,7 @@ public:
|
||||
QScopedPointer<FollowSymbolUnderCursor> 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("<b>Warning</b>: 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
|
||||
|
@@ -31,10 +31,6 @@
|
||||
|
||||
#include <QScopedPointer>
|
||||
|
||||
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;
|
||||
|
||||
|
@@ -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";
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -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)
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user