summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2019-02-06 10:21:26 +0100
committerDavid Schulz <david.schulz@qt.io>2019-02-07 12:51:12 +0000
commit1dd462ac4d7f356052f5daf9110e548941ab2e65 (patch)
treebab1d382acb0c368f7864690090489a434f17b31
parentbf6dfa0db9c41f5a9f3d9f170f7517522ce8560b (diff)
downloadqt-creator-1dd462ac4d7f356052f5daf9110e548941ab2e65.tar.gz
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 <christian.stenger@qt.io>
-rw-r--r--src/plugins/texteditor/texteditor.cpp68
-rw-r--r--src/plugins/texteditor/texteditor.h1
2 files changed, 28 insertions, 41 deletions
diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp
index 409fc6dc24..7a301e3899 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<ClipboardAssistProvider> m_clipboardAssistProvider;
- bool m_isMissingSyntaxDefinition = false;
-
QScopedPointer<AutoCompleter> 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<TextEditorWidget>(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<TextEditorWidget>(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 5cf1ecbd1a..d792a1b12c 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<BlockRange> &blocks);
- bool isMissingSyntaxDefinition() const;
enum Side { Left, Right };
QAction *insertExtraToolBarWidget(Side side, QWidget *widget);