diff options
author | David Schulz <david.schulz@qt.io> | 2019-02-07 08:50:16 +0100 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2019-02-11 12:45:04 +0000 |
commit | 82466375b91cf0767f48de1ad17bae1ddd94dcef (patch) | |
tree | 349cf1980df3a5b0506441078afba4d729c0b975 /src/plugins/texteditor/texteditor.cpp | |
parent | 0a974cb59f9b14050e0492615ecb0a40940615c5 (diff) | |
download | qt-creator-82466375b91cf0767f48de1ad17bae1ddd94dcef.tar.gz |
TextEditor: Show info when multiple highlight definitions are available
Show an editor info bar when multiple highlight definitions can be found
for a single file or mime type. Add a combo box to the info that allows
the user to choose between them.
Change-Id: I07278d065e19d4e04fba24a6d789c8b6c9f55d60
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Diffstat (limited to 'src/plugins/texteditor/texteditor.cpp')
-rw-r--r-- | src/plugins/texteditor/texteditor.cpp | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 6cf1b70136..51a7da5e31 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -611,7 +611,7 @@ public: void updateCodeFoldingVisible(); void reconfigure(); - void updateSyntaxInfoBar(bool showInfo); + void updateSyntaxInfoBar(const Highlighter::Definitions &definitions, const QString &fileName); void configureGenericHighlighter(const KSyntaxHighlighting::Definition &definition); public: @@ -3274,27 +3274,43 @@ void TextEditorWidgetPrivate::reconfigure() q->configureGenericHighlighter(); } -void TextEditorWidgetPrivate::updateSyntaxInfoBar(bool showInfo) +void TextEditorWidgetPrivate::updateSyntaxInfoBar(const Highlighter::Definitions &definitions, + const QString &fileName) { - Id id(Constants::INFO_SYNTAX_DEFINITION); + Id missing(Constants::INFO_MISSING_SYNTAX_DEFINITION); + Id multiple(Constants::INFO_MULTIPLE_SYNTAX_DEFINITIONS); 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?"), + if (definitions.isEmpty() && infoBar->canInfoBeAdded(missing) + && !TextEditorSettings::highlighterSettings().isIgnoredFilePattern(fileName)) { + InfoBarEntry info(missing, + 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); + info.setCustomButtonInfo(BaseTextEditor::tr("Update Definitions"), [missing, this]() { + m_document->infoBar()->removeInfo(missing); Highlighter::updateDefinitions([widget = QPointer<TextEditorWidget>(q)]() { if (widget) widget->configureGenericHighlighter(); }); }); + + infoBar->removeInfo(multiple); + infoBar->addInfo(info); + } else if (definitions.size() > 1) { + InfoBarEntry info(multiple, + BaseTextEditor::tr("More than one highlight definition was found for this file. " + "Which one should be used to highlight this file?")); + info.setComboInfo(Utils::transform(definitions, &Highlighter::Definition::name), + [this](const QString &definition) { + this->configureGenericHighlighter(Highlighter::definitionForName(definition)); + }); + + infoBar->removeInfo(missing); infoBar->addInfo(info); } else { - infoBar->removeInfo(id); + infoBar->removeInfo(multiple); + infoBar->removeInfo(missing); } } @@ -8514,11 +8530,10 @@ QString TextEditorWidget::textAt(int from, int to) const void TextEditorWidget::configureGenericHighlighter() { - const Highlighter::Definition definition = Highlighter::definitionForDocument(textDocument()); - d->configureGenericHighlighter(definition); - d->updateSyntaxInfoBar(!definition.isValid() - && !TextEditorSettings::highlighterSettings().isIgnoredFilePattern( - textDocument()->filePath().fileName())); + const Highlighter::Definitions definitions = Highlighter::definitionsForDocument(textDocument()); + d->configureGenericHighlighter(definitions.isEmpty() ? Highlighter::Definition() + : definitions.first()); + d->updateSyntaxInfoBar(definitions, textDocument()->filePath().fileName()); } int TextEditorWidget::blockNumberForVisibleRow(int row) const |