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>
This commit is contained in:
David Schulz
2019-02-06 10:21:26 +01:00
parent bf6dfa0db9
commit 1dd462ac4d
2 changed files with 28 additions and 41 deletions

View File

@@ -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()
{

View File

@@ -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);