diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2013-05-02 11:42:33 +0200 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@digia.com> | 2013-05-15 15:05:58 +0200 |
commit | 033ad8875ba4d310e3ecf73c94f1a9846472bba3 (patch) | |
tree | 8e752ccff80258570eb6bbc5edae8a03d798d703 /src | |
parent | dc4822d1233aee3802c047c5462c2b94cfdbd782 (diff) | |
download | qt-creator-033ad8875ba4d310e3ecf73c94f1a9846472bba3.tar.gz |
C++: handle file type changes for choosing highlighters.
If the file type (mime type) of an editor changes, it might need a
different kind of highlighter/highlighting-support.
Change-Id: I470dbf69e71856c9593d201416c4d4bd2958aaec
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/cppeditor/cppeditor.cpp | 7 | ||||
-rw-r--r-- | src/plugins/cpptools/cpptoolseditorsupport.cpp | 25 | ||||
-rw-r--r-- | src/plugins/cpptools/cpptoolseditorsupport.h | 2 | ||||
-rw-r--r-- | src/plugins/texteditor/basetextdocument.cpp | 5 | ||||
-rw-r--r-- | src/plugins/texteditor/basetextdocument.h | 1 |
5 files changed, 26 insertions, 14 deletions
diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index 6000d938de..03435f493a 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -1166,7 +1166,7 @@ void CPPEditorWidget::finishHighlightSymbolUsages() if (editorRevision() != m_highlightRevision) return; // outdated - else if (m_highlighter.isCanceled()) + if (m_highlighter.isCanceled()) return; // aborted TextEditor::SyntaxHighlighter *highlighter = baseTextDocument()->syntaxHighlighter(); @@ -1174,11 +1174,6 @@ void CPPEditorWidget::finishHighlightSymbolUsages() TextEditor::SemanticHighlighter::clearExtraAdditionalFormatsUntilEnd( highlighter, m_highlighter); - - if (m_modelManager) - m_modelManager->setExtraDiagnostics(m_lastSemanticInfo.doc->fileName(), - QLatin1String("CppEditor.SemanticsDiagnostics"), - m_lastSemanticInfo.doc->diagnosticMessages()); } void CPPEditorWidget::switchDeclarationDefinition(bool inNextSplit) diff --git a/src/plugins/cpptools/cpptoolseditorsupport.cpp b/src/plugins/cpptools/cpptoolseditorsupport.cpp index 01001fee76..45d970d475 100644 --- a/src/plugins/cpptools/cpptoolseditorsupport.cpp +++ b/src/plugins/cpptools/cpptoolseditorsupport.cpp @@ -115,16 +115,10 @@ CppEditorSupport::CppEditorSupport(CppModelManager *modelManager, BaseTextEditor , m_cachedContentsEditorRevision(-1) , m_initialized(false) , m_lastHighlightRevision(0) - , m_highlightingSupport(modelManager->highlightingSupport(textEditor)) { connect(m_modelManager, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)), this, SLOT(onDocumentUpdated(CPlusPlus::Document::Ptr))); - if (m_highlightingSupport && m_highlightingSupport->requiresSemanticInfo()) { - connect(this, SIGNAL(semanticInfoUpdated(CppTools::SemanticInfo)), - this, SLOT(startHighlighting())); - } - m_updateDocumentTimer = new QTimer(this); m_updateDocumentTimer->setSingleShot(true); m_updateDocumentTimer->setInterval(m_updateDocumentInterval); @@ -139,7 +133,8 @@ CppEditorSupport::CppEditorSupport(CppModelManager *modelManager, BaseTextEditor connect(m_textEditor, SIGNAL(contentsChanged()), this, SLOT(updateDocument())); connect(this, SIGNAL(diagnosticsChanged()), this, SLOT(onDiagnosticsChanged())); - updateDocument(); + connect(m_textEditor->document(), SIGNAL(mimeTypeChanged()), + this, SLOT(onMimeTypeChanged())); } CppEditorSupport::~CppEditorSupport() @@ -486,3 +481,19 @@ void CppEditorSupport::recalculateSemanticInfoDetached_helper(QFutureInterface<v TLDProc tldProc(future); recalculateSemanticInfoNow(source, true, &tldProc); } + +void CppEditorSupport::onMimeTypeChanged() +{ + m_highlighter.cancel(); + m_highlighter.waitForFinished(); + + m_highlightingSupport.reset(m_modelManager->highlightingSupport(m_textEditor)); + + disconnect(this, SIGNAL(semanticInfoUpdated(CppTools::SemanticInfo)), + this, SLOT(startHighlighting())); + if (m_highlightingSupport && m_highlightingSupport->requiresSemanticInfo()) + connect(this, SIGNAL(semanticInfoUpdated(CppTools::SemanticInfo)), + this, SLOT(startHighlighting())); + + updateDocumentNow(); +} diff --git a/src/plugins/cpptools/cpptoolseditorsupport.h b/src/plugins/cpptools/cpptoolseditorsupport.h index 2a027eabf0..a63ee7e6e5 100644 --- a/src/plugins/cpptools/cpptoolseditorsupport.h +++ b/src/plugins/cpptools/cpptoolseditorsupport.h @@ -119,6 +119,8 @@ signals: void highlighterStarted(QFuture<TextEditor::HighlightingResult> *, unsigned revision); private slots: + void onMimeTypeChanged(); + void updateDocument(); void updateDocumentNow(); diff --git a/src/plugins/texteditor/basetextdocument.cpp b/src/plugins/texteditor/basetextdocument.cpp index 7e4d2c34b6..f21f0185a1 100644 --- a/src/plugins/texteditor/basetextdocument.cpp +++ b/src/plugins/texteditor/basetextdocument.cpp @@ -113,7 +113,10 @@ QString BaseTextDocument::mimeType() const void BaseTextDocument::setMimeType(const QString &mt) { - d->m_mimeType = mt; + if (d->m_mimeType != mt) { + d->m_mimeType = mt; + emit mimeTypeChanged(); + } } void BaseTextDocument::setTypingSettings(const TypingSettings &typingSettings) diff --git a/src/plugins/texteditor/basetextdocument.h b/src/plugins/texteditor/basetextdocument.h index 61284e17b1..3e9e90688b 100644 --- a/src/plugins/texteditor/basetextdocument.h +++ b/src/plugins/texteditor/basetextdocument.h @@ -105,6 +105,7 @@ public: signals: void titleChanged(QString title); + void mimeTypeChanged(); private: void cleanWhitespace(QTextCursor &cursor, bool cleanIndentation, bool inEntireDocument); |