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:
Nikolai Kosjar
2016-10-13 13:11:07 +02:00
parent 3016c6c96f
commit dd647b4236
9 changed files with 58 additions and 50 deletions

View File

@@ -68,11 +68,6 @@ void InfoBarEntry::setCancelButtonInfo(const QString &_cancelButtonText, CallBac
m_cancelButtonCallBack = callBack; m_cancelButtonCallBack = callBack;
} }
void InfoBarEntry::setSuppressionButtonInfo(InfoBarEntry::CallBack callback)
{
m_suppressionButtonCallBack = callback;
}
void InfoBarEntry::setShowDefaultCancelButton(bool yesno) void InfoBarEntry::setShowDefaultCancelButton(bool yesno)
{ {
m_showDefaultCancelButton = yesno; m_showDefaultCancelButton = yesno;
@@ -282,9 +277,7 @@ void InfoBarDisplay::update()
if (info.globalSuppression == InfoBarEntry::GlobalSuppressionEnabled) { if (info.globalSuppression == InfoBarEntry::GlobalSuppressionEnabled) {
infoWidgetSuppressButton = new QToolButton; infoWidgetSuppressButton = new QToolButton;
infoWidgetSuppressButton->setText(tr("Do Not Show Again")); infoWidgetSuppressButton->setText(tr("Do Not Show Again"));
connect(infoWidgetSuppressButton, &QAbstractButton::clicked, this, [this, info, id] { connect(infoWidgetSuppressButton, &QAbstractButton::clicked, this, [this, id] {
if (info.m_suppressionButtonCallBack)
info.m_suppressionButtonCallBack();
m_infoBar->removeInfo(id); m_infoBar->removeInfo(id);
InfoBar::globallySuppressInfo(id); InfoBar::globallySuppressInfo(id);
}); });

View File

@@ -58,7 +58,6 @@ public:
void setCustomButtonInfo(const QString &_buttonText, CallBack callBack); void setCustomButtonInfo(const QString &_buttonText, CallBack callBack);
void setCancelButtonInfo(CallBack callBack); void setCancelButtonInfo(CallBack callBack);
void setCancelButtonInfo(const QString &_cancelButtonText, CallBack callBack); void setCancelButtonInfo(const QString &_cancelButtonText, CallBack callBack);
void setSuppressionButtonInfo(CallBack callback);
void setShowDefaultCancelButton(bool yesno); void setShowDefaultCancelButton(bool yesno);
using DetailsWidgetCreator = std::function<QWidget*()>; using DetailsWidgetCreator = std::function<QWidget*()>;
@@ -71,7 +70,6 @@ private:
CallBack m_buttonCallBack; CallBack m_buttonCallBack;
QString cancelButtonText; QString cancelButtonText;
CallBack m_cancelButtonCallBack; CallBack m_cancelButtonCallBack;
CallBack m_suppressionButtonCallBack;
GlobalSuppressionMode globalSuppression; GlobalSuppressionMode globalSuppression;
DetailsWidgetCreator m_detailsWidgetCreator; DetailsWidgetCreator m_detailsWidgetCreator;
bool m_showDefaultCancelButton = true; bool m_showDefaultCancelButton = true;

View File

@@ -56,6 +56,7 @@
#include <cpptools/cpptoolsconstants.h> #include <cpptools/cpptoolsconstants.h>
#include <cpptools/cpptoolsplugin.h> #include <cpptools/cpptoolsplugin.h>
#include <cpptools/cpptoolsreuse.h> #include <cpptools/cpptoolsreuse.h>
#include <cpptools/cpptoolssettings.h>
#include <cpptools/cppworkingcopy.h> #include <cpptools/cppworkingcopy.h>
#include <cpptools/symbolfinder.h> #include <cpptools/symbolfinder.h>
#include <cpptools/refactoringengineinterface.h> #include <cpptools/refactoringengineinterface.h>
@@ -130,7 +131,7 @@ public:
QScopedPointer<FollowSymbolUnderCursor> m_followSymbolUnderCursor; QScopedPointer<FollowSymbolUnderCursor> m_followSymbolUnderCursor;
QToolButton *m_preprocessorButton = nullptr; QToolButton *m_preprocessorButton = nullptr;
QToolButton *m_headerErrorsIndicatorButton = nullptr; QAction *m_headerErrorsIndicatorAction = nullptr;
CppSelectionChanger m_cppSelectionChanger; CppSelectionChanger m_cppSelectionChanger;
@@ -229,15 +230,20 @@ void CppEditorWidget::finalizeInitialization()
connect(cmd, &Command::keySequenceChanged, this, &CppEditorWidget::updatePreprocessorButtonTooltip); connect(cmd, &Command::keySequenceChanged, this, &CppEditorWidget::updatePreprocessorButtonTooltip);
updatePreprocessorButtonTooltip(); updatePreprocessorButtonTooltip();
connect(d->m_preprocessorButton, &QAbstractButton::clicked, this, &CppEditorWidget::showPreProcessorWidget); 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_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()); insertExtraToolBarWidget(TextEditorWidget::Left, d->m_cppEditorOutline->widget());
} }
@@ -252,6 +258,10 @@ void CppEditorWidget::finalizeInitializationAfterDuplication(TextEditorWidget *o
d->m_cppEditorOutline->update(); d->m_cppEditorOutline->update();
const Id selectionKind = CodeWarningsSelection; const Id selectionKind = CodeWarningsSelection;
setExtraSelections(selectionKind, cppEditorWidget->extraSelections(selectionKind)); setExtraSelections(selectionKind, cppEditorWidget->extraSelections(selectionKind));
d->m_headerErrorDiagnosticWidgetCreator
= cppEditorWidget->d->m_headerErrorDiagnosticWidgetCreator;
updateHeaderErrorWidgets();
} }
CppEditorWidget::~CppEditorWidget() CppEditorWidget::~CppEditorWidget()
@@ -329,13 +339,14 @@ void CppEditorWidget::updateHeaderErrorWidgets()
infoBar->removeInfo(id); infoBar->removeInfo(id);
if (d->m_headerErrorDiagnosticWidgetCreator) { if (d->m_headerErrorDiagnosticWidgetCreator) {
if (infoBar->canInfoBeAdded(id)) { if (CppToolsSettings::instance()->showHeaderErrorInfoBar()) {
addHeaderErrorInfoBarEntryAndHideIndicator(); addHeaderErrorInfoBarEntry();
d->m_headerErrorsIndicatorAction->setVisible(false);
} else { } else {
d->m_headerErrorsIndicatorButton->setEnabled(true); d->m_headerErrorsIndicatorAction->setVisible(true);
} }
} else { } 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 renameUsages(); // Rename non-local symbol or macro
} }
void CppEditorWidget::addHeaderErrorInfoBarEntryAndHideIndicator() const void CppEditorWidget::addHeaderErrorInfoBarEntry() const
{ {
InfoBarEntry info(Constants::ERRORS_IN_HEADER_FILES, InfoBarEntry info(Constants::ERRORS_IN_HEADER_FILES,
tr("<b>Warning</b>: The code model could not parse an included file, " tr("<b>Warning</b>: The code model could not parse an included file, "
"which might lead to slow or incorrect code completion and " "which might lead to slow or incorrect code completion and "
"highlighting, for example."), "highlighting, for example."));
InfoBarEntry::GlobalSuppressionEnabled);
info.setDetailsWidgetCreator(d->m_headerErrorDiagnosticWidgetCreator); info.setDetailsWidgetCreator(d->m_headerErrorDiagnosticWidgetCreator);
info.setShowDefaultCancelButton(false); info.setShowDefaultCancelButton(false);
info.setSuppressionButtonInfo([this](){ info.setCustomButtonInfo("Minimize", [](){
d->m_headerErrorsIndicatorButton->setEnabled(true); CppToolsSettings::instance()->setShowHeaderErrorInfoBar(false);
}); });
InfoBar *infoBar = textDocument()->infoBar(); InfoBar *infoBar = textDocument()->infoBar();
infoBar->addInfo(info); infoBar->addInfo(info);
d->m_headerErrorsIndicatorButton->setEnabled(false);
} }
namespace { 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 Internal
} // namespace CppEditor } // namespace CppEditor

View File

@@ -31,10 +31,6 @@
#include <QScopedPointer> #include <QScopedPointer>
namespace Core {
class InfoBarEntry;
}
namespace CppTools { namespace CppTools {
class CppEditorOutline; class CppEditorOutline;
class RefactoringEngineInterface; class RefactoringEngineInterface;
@@ -91,7 +87,6 @@ public:
void switchDeclarationDefinition(bool inNextSplit); void switchDeclarationDefinition(bool inNextSplit);
void showPreProcessorWidget(); void showPreProcessorWidget();
void showHeaderErrorInfoBar();
void findUsages(); void findUsages();
void renameSymbolUnderCursor(); void renameSymbolUnderCursor();
@@ -150,7 +145,7 @@ private:
void renameSymbolUnderCursorClang(); void renameSymbolUnderCursorClang();
void renameSymbolUnderCursorBuiltin(); void renameSymbolUnderCursorBuiltin();
void addHeaderErrorInfoBarEntryAndHideIndicator() const; void addHeaderErrorInfoBarEntry() const;
CppTools::ProjectPart *projectPart() const; CppTools::ProjectPart *projectPart() const;

View File

@@ -49,6 +49,7 @@ const char CPPTOOLS_SETTINGSGROUP[] = "CppTools";
const char LOWERCASE_CPPFILES_KEY[] = "LowerCaseFiles"; const char LOWERCASE_CPPFILES_KEY[] = "LowerCaseFiles";
enum { lowerCaseFilesDefault = 1 }; enum { lowerCaseFilesDefault = 1 };
const char CPPTOOLS_SORT_EDITOR_DOCUMENT_OUTLINE[] = "SortedMethodOverview"; 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_MODEL_MANAGER_PCH_USAGE[] = "PCHUsage";
const char CPPTOOLS_SKIP_INDEXING_BIG_FILES[] = "SkipIndexingBigFiles"; const char CPPTOOLS_SKIP_INDEXING_BIG_FILES[] = "SkipIndexingBigFiles";
const char CPPTOOLS_INDEXER_FILE_SIZE_LIMIT[] = "IndexerFileSizeLimit"; const char CPPTOOLS_INDEXER_FILE_SIZE_LIMIT[] = "IndexerFileSizeLimit";

View File

@@ -267,3 +267,21 @@ void CppToolsSettings::setSortedEditorDocumentOutline(bool sorted)
ICore::settings()->setValue(sortEditorDocumentOutlineKey(), sorted); ICore::settings()->setValue(sortEditorDocumentOutlineKey(), sorted);
emit editorDocumentOutlineSortingChanged(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);
}

View File

@@ -63,8 +63,12 @@ public:
bool sortedEditorDocumentOutline() const; bool sortedEditorDocumentOutline() const;
void setSortedEditorDocumentOutline(bool sorted); void setSortedEditorDocumentOutline(bool sorted);
bool showHeaderErrorInfoBar() const;
void setShowHeaderErrorInfoBar(bool show);
signals: signals:
void editorDocumentOutlineSortingChanged(bool isSorted); void editorDocumentOutlineSortingChanged(bool isSorted);
void showHeaderErrorInfoBarChanged(bool isShown);
private: private:
Internal::CppToolsSettingsPrivate *d; Internal::CppToolsSettingsPrivate *d;

View File

@@ -7035,7 +7035,7 @@ QWidget *BaseTextEditor::toolBar()
return editorWidget()->d->m_toolBar; return editorWidget()->d->m_toolBar;
} }
void TextEditorWidget::insertExtraToolBarWidget(TextEditorWidget::Side side, QAction * TextEditorWidget::insertExtraToolBarWidget(TextEditorWidget::Side side,
QWidget *widget) QWidget *widget)
{ {
if (widget->sizePolicy().horizontalPolicy() & QSizePolicy::ExpandFlag) { if (widget->sizePolicy().horizontalPolicy() & QSizePolicy::ExpandFlag) {
@@ -7045,9 +7045,9 @@ void TextEditorWidget::insertExtraToolBarWidget(TextEditorWidget::Side side,
} }
if (side == Right) if (side == Right)
d->m_toolBar->insertWidget(d->m_cursorPositionLabelAction, widget); return d->m_toolBar->insertWidget(d->m_cursorPositionLabelAction, widget);
else 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) void TextEditorWidget::keepAutoCompletionHighlight(bool keepHighlight)

View File

@@ -322,7 +322,7 @@ public:
bool isMissingSyntaxDefinition() const; bool isMissingSyntaxDefinition() const;
enum Side { Left, Right }; 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 // keep the auto completion even if the focus is lost
void keepAutoCompletionHighlight(bool keepHighlight); void keepAutoCompletionHighlight(bool keepHighlight);