From dcad56568e39bf6a705f6dd948e0cea1ed1efc5c Mon Sep 17 00:00:00 2001 From: Daniel Teske Date: Fri, 5 Dec 2014 15:47:49 +0100 Subject: [PATCH] CMake: Fix syntax highlighting for cmake files The newest kate definition files for cmake contain no mimetype for the cmake definitions, which lead to us not finding the right definition. Instead add a method to find the definition based on the name, which is not as generic, but we know which one we want for cmake anyway. Task-number: QTCREATORBUG-13588 Change-Id: Ib57fe531a225310c32ca1ef909a31bd7f52c612f Reviewed-by: Guilhem Vallat Reviewed-by: Eike Ziller Reviewed-by: David Schulz --- src/plugins/cmakeprojectmanager/cmakeeditor.cpp | 2 +- src/plugins/texteditor/texteditor.cpp | 14 ++++++++++++++ src/plugins/texteditor/texteditor.h | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp index 873c5b5debe..fa19445743d 100644 --- a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp @@ -276,7 +276,7 @@ CMakeEditorFactory::CMakeEditorFactory(CMakeSettingsPage *settingsPage) setEditorCreator([]() { return new CMakeEditor; }); setEditorWidgetCreator([]() { return new CMakeEditorWidget; }); setDocumentCreator([]() { return new CMakeDocument; }); - setGenericSyntaxHighlighter(QLatin1String(Constants::CMAKEMIMETYPE)); + setGenericSyntaxHighlighterByName(QLatin1String("CMake")); setCommentStyle(Utils::CommentDefinition::HashStyle); setCodeFoldingSupported(true); diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 0de6b93ee08..51a61203dfb 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -7377,6 +7377,20 @@ void TextEditorFactory::setGenericSyntaxHighlighter(const QString &mimeType) }; } +void TextEditorFactory::setGenericSyntaxHighlighterByName(const QString &name) +{ + d->m_syntaxHighlighterCreator = [this, name]() -> SyntaxHighlighter * { + TextEditor::Highlighter *highlighter = new TextEditor::Highlighter(); + QString definitionId = Manager::instance()->definitionIdByName(name); + if (!definitionId.isEmpty()) { + const QSharedPointer &definition = Manager::instance()->definition(definitionId); + if (!definition.isNull() && definition->isValid()) + highlighter->setDefaultContext(definition->initialContext()); + } + return highlighter; + }; +} + void TextEditorFactory::setAutoCompleterCreator(const AutoCompleterCreator &creator) { d->m_autoCompleterCreator = creator; diff --git a/src/plugins/texteditor/texteditor.h b/src/plugins/texteditor/texteditor.h index c364df2ff13..caee57de046 100644 --- a/src/plugins/texteditor/texteditor.h +++ b/src/plugins/texteditor/texteditor.h @@ -667,6 +667,7 @@ public: void setIndenterCreator(const IndenterCreator &creator); void setSyntaxHighlighterCreator(const SyntaxHighLighterCreator &creator); void setGenericSyntaxHighlighter(const QString &mimeType); + void setGenericSyntaxHighlighterByName(const QString &name); void setAutoCompleterCreator(const AutoCompleterCreator &creator); void setEditorActionHandlers(Core::Id contextId, uint optionalActions);