summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@qt.io>2016-10-13 13:11:07 +0200
committerNikolai Kosjar <nikolai.kosjar@qt.io>2016-10-14 09:01:17 +0000
commitdd647b4236c5d818462f69dae1721e03b0dfca84 (patch)
tree2507fc5c164f714317442c1a28d2c5350a27ef52
parent3016c6c96f092cf3968e4d622be67b63a163ba5a (diff)
downloadqt-creator-dd647b4236c5d818462f69dae1721e03b0dfca84.tar.gz
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>
-rw-r--r--src/plugins/coreplugin/infobar.cpp9
-rw-r--r--src/plugins/coreplugin/infobar.h2
-rw-r--r--src/plugins/cppeditor/cppeditor.cpp55
-rw-r--r--src/plugins/cppeditor/cppeditor.h7
-rw-r--r--src/plugins/cpptools/cpptoolsconstants.h1
-rw-r--r--src/plugins/cpptools/cpptoolssettings.cpp18
-rw-r--r--src/plugins/cpptools/cpptoolssettings.h4
-rw-r--r--src/plugins/texteditor/texteditor.cpp8
-rw-r--r--src/plugins/texteditor/texteditor.h2
9 files changed, 57 insertions, 49 deletions
diff --git a/src/plugins/coreplugin/infobar.cpp b/src/plugins/coreplugin/infobar.cpp
index 9fcc7ce18a..7c301af8a3 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 e832e57005..c5d1120fc3 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<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;
diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp
index 0492635d1a..4b861658fc 100644
--- a/src/plugins/cppeditor/cppeditor.cpp
+++ b/src/plugins/cppeditor/cppeditor.cpp
@@ -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);
+ insertExtraToolBarWidget(TextEditorWidget::Left, d->m_preprocessorButton);
- 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);
+ 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_preprocessorButton);
- insertExtraToolBarWidget(TextEditorWidget::Left, d->m_headerErrorsIndicatorButton);
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
diff --git a/src/plugins/cppeditor/cppeditor.h b/src/plugins/cppeditor/cppeditor.h
index cce22cebcd..9475710480 100644
--- a/src/plugins/cppeditor/cppeditor.h
+++ b/src/plugins/cppeditor/cppeditor.h
@@ -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;
diff --git a/src/plugins/cpptools/cpptoolsconstants.h b/src/plugins/cpptools/cpptoolsconstants.h
index b82ecad14e..11a5f1a1ab 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 0b122520df..fbfbce7a4d 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 e36956be1a..a118d70004 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 db9efb356a..5b1f0f6d7a 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 60038d73ed..2cd60da380 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);