From 1dd462ac4d7f356052f5daf9110e548941ab2e65 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 6 Feb 2019 10:21:26 +0100 Subject: [PATCH] TextEditor: update the infobar after setting up the highlighter removes the need of public function and member carrying the information whether a highlight definition was found. Change-Id: I8a0f24c9b376c01246116b502f5bbc06b3c65d21 Reviewed-by: Christian Stenger --- src/plugins/texteditor/texteditor.cpp | 68 +++++++++++---------------- src/plugins/texteditor/texteditor.h | 1 - 2 files changed, 28 insertions(+), 41 deletions(-) diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 409fc6dc24d..7a301e38998 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -611,6 +611,7 @@ public: void updateCodeFoldingVisible(); void reconfigure(); + void updateSyntaxInfoBar(bool showInfo); public: TextEditorWidget *q; @@ -768,8 +769,6 @@ public: QScopedPointer m_clipboardAssistProvider; - bool m_isMissingSyntaxDefinition = false; - QScopedPointer m_autoCompleter; CommentDefinition m_commentDefinition; @@ -904,33 +903,6 @@ void TextEditorWidgetPrivate::showTextMarksToolTip(const QPoint &pos, } // namespace Internal -/*! - * Test if syntax highlighter is available (or unneeded) for \a widget. - * If not found, show a warning with a link to the relevant settings page. - */ -static void updateEditorInfoBar(TextEditorWidget *widget) -{ - Id id(Constants::INFO_SYNTAX_DEFINITION); - InfoBar *infoBar = widget->textDocument()->infoBar(); - if (!widget->isMissingSyntaxDefinition()) { - infoBar->removeInfo(id); - } else if (infoBar->canInfoBeAdded(id)) { - InfoBarEntry info(id, - BaseTextEditor::tr("A highlight definition was not found for this file. " - "Would you like to update highlight definition files?"), - InfoBarEntry::GlobalSuppressionEnabled); - info.setCustomButtonInfo(BaseTextEditor::tr("Update Definitions"), [id, widget]() { - widget->textDocument()->infoBar()->removeInfo(id); - Highlighter::updateDefinitions([widget = QPointer(widget)]() { - if (widget) - widget->configureGenericHighlighter(); - }); - }); - - infoBar->addInfo(info); - } -} - QString TextEditorWidget::plainTextFromSelection(const QTextCursor &cursor) const { // Copy the selected text as plain text @@ -3301,6 +3273,30 @@ void TextEditorWidgetPrivate::reconfigure() q->configureGenericHighlighter(); } +void TextEditorWidgetPrivate::updateSyntaxInfoBar(bool showInfo) +{ + Id id(Constants::INFO_SYNTAX_DEFINITION); + InfoBar *infoBar = m_document->infoBar(); + + if (showInfo) { + InfoBarEntry info(id, + BaseTextEditor::tr( + "A highlight definition was not found for this file. " + "Would you like to update highlight definition files?"), + InfoBarEntry::GlobalSuppressionEnabled); + info.setCustomButtonInfo(BaseTextEditor::tr("Update Definitions"), [&]() { + m_document->infoBar()->removeInfo(id); + Highlighter::updateDefinitions([widget = QPointer(q)]() { + if (widget) + widget->configureGenericHighlighter(); + }); + }); + infoBar->addInfo(info); + } else { + infoBar->removeInfo(id); + } +} + bool TextEditorWidget::codeFoldingVisible() const { return d->m_codeFoldingVisible; @@ -8514,20 +8510,17 @@ void TextEditorWidget::configureGenericHighlighter() if (definition.isValid()) { highlighter->setDefinition(definition); - d->m_isMissingSyntaxDefinition = false; d->m_commentDefinition.singleLine = definition.singleLineCommentMarker(); d->m_commentDefinition.multiLineStart = definition.multiLineCommentMarker().first; d->m_commentDefinition.multiLineEnd = definition.multiLineCommentMarker().second; setCodeFoldingSupported(true); - } else { - d->m_isMissingSyntaxDefinition = - !TextEditorSettings::highlighterSettings().isIgnoredFilePattern(fileName); } - textDocument()->setFontSettings(TextEditorSettings::fontSettings()); + d->updateSyntaxInfoBar(!definition.isValid() + && !TextEditorSettings::highlighterSettings().isIgnoredFilePattern(fileName)); - updateEditorInfoBar(this); + textDocument()->setFontSettings(TextEditorSettings::fontSettings()); } int TextEditorWidget::blockNumberForVisibleRow(int row) const @@ -8562,11 +8555,6 @@ HighlightScrollBarController *TextEditorWidget::highlightScrollBarController() c return d->m_highlightScrollBarController; } -bool TextEditorWidget::isMissingSyntaxDefinition() const -{ - return d->m_isMissingSyntaxDefinition; -} - // The remnants of PlainTextEditor. void TextEditorWidget::setupGenericHighlighter() { diff --git a/src/plugins/texteditor/texteditor.h b/src/plugins/texteditor/texteditor.h index 5cf1ecbd1a3..d792a1b12c7 100644 --- a/src/plugins/texteditor/texteditor.h +++ b/src/plugins/texteditor/texteditor.h @@ -332,7 +332,6 @@ public: // the blocks list must be sorted void setIfdefedOutBlocks(const QList &blocks); - bool isMissingSyntaxDefinition() const; enum Side { Left, Right }; QAction *insertExtraToolBarWidget(Side side, QWidget *widget);