From f808377344bb74237afeb75afb61fb8b4f89e782 Mon Sep 17 00:00:00 2001 From: Roberto Raggi <roberto.raggi@nokia.com> Date: Thu, 14 Jan 2010 16:30:48 +0100 Subject: [PATCH] Improved highlighting of QML ids. --- src/plugins/qmleditor/qmleditor.cpp | 33 ++++++++++++++++++++++++++--- src/plugins/qmleditor/qmleditor.h | 6 ++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/plugins/qmleditor/qmleditor.cpp b/src/plugins/qmleditor/qmleditor.cpp index 8598e36d2f8..14bf8236a87 100644 --- a/src/plugins/qmleditor/qmleditor.cpp +++ b/src/plugins/qmleditor/qmleditor.cpp @@ -68,7 +68,8 @@ #include <QtGui/QToolBar> enum { - UPDATE_DOCUMENT_DEFAULT_INTERVAL = 250 + UPDATE_DOCUMENT_DEFAULT_INTERVAL = 250, + UPDATE_USES_DEFAULT_INTERVAL = 150 }; using namespace Qml; @@ -311,6 +312,7 @@ QmlTextEditor::QmlTextEditor(QWidget *parent) : m_modelManager(0), m_typeSystem(0) { + m_idsRevision = -1; setParenthesesMatchingEnabled(true); setMarksVisible(true); setCodeFoldingSupported(true); @@ -320,10 +322,15 @@ QmlTextEditor::QmlTextEditor(QWidget *parent) : m_updateDocumentTimer = new QTimer(this); m_updateDocumentTimer->setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL); m_updateDocumentTimer->setSingleShot(true); - connect(m_updateDocumentTimer, SIGNAL(timeout()), this, SLOT(updateDocumentNow())); + m_updateUsesTimer = new QTimer(this); + m_updateUsesTimer->setInterval(UPDATE_USES_DEFAULT_INTERVAL); + m_updateUsesTimer->setSingleShot(true); + connect(m_updateUsesTimer, SIGNAL(timeout()), this, SLOT(updateUsesNow())); + connect(this, SIGNAL(textChanged()), this, SLOT(updateDocument())); + connect(this, SIGNAL(textChanged()), this, SLOT(updateUses())); baseTextDocument()->setSyntaxHighlighter(new QmlHighlighter); @@ -385,6 +392,7 @@ void QmlTextEditor::onDocumentUpdated(QmlEditor::QmlDocument::Ptr doc) m_document = doc; FindIdDeclarations updateIds; + m_idsRevision = document()->revision(); m_ids = updateIds(doc->program()); if (doc->isParsedCorrectly()) { @@ -463,6 +471,22 @@ void QmlTextEditor::updateMethodBoxIndex() } m_methodCombo->setCurrentIndex(currentSymbolIndex); + updateUses(); +} + +void QmlTextEditor::updateUses() +{ + m_updateUsesTimer->start(); +} + +void QmlTextEditor::updateUsesNow() +{ + if (document()->revision() != m_idsRevision) { + updateUses(); + return; + } + + m_updateUsesTimer->stop(); QList<QTextEdit::ExtraSelection> selections; foreach (const AST::SourceLocation &loc, m_ids.value(wordUnderCursor())) { @@ -470,7 +494,7 @@ void QmlTextEditor::updateMethodBoxIndex() continue; QTextEdit::ExtraSelection sel; - sel.format.setBackground(Qt::yellow); + sel.format = m_occurrencesFormat; sel.cursor = textCursor(); sel.cursor.setPosition(loc.begin()); sel.cursor.setPosition(loc.end(), QTextCursor::KeepAnchor); @@ -538,6 +562,9 @@ void QmlTextEditor::setFontSettings(const TextEditor::FontSettings &fs) << QLatin1String(TextEditor::Constants::C_VISUAL_WHITESPACE); } + m_occurrencesFormat = fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_OCCURRENCES)); + m_occurrencesFormat.clearForeground(); + highlighter->setFormats(fs.toTextCharFormats(categories)); highlighter->rehighlight(); } diff --git a/src/plugins/qmleditor/qmleditor.h b/src/plugins/qmleditor/qmleditor.h index 9a5b2ef6c57..edd3c8db205 100644 --- a/src/plugins/qmleditor/qmleditor.h +++ b/src/plugins/qmleditor/qmleditor.h @@ -123,6 +123,9 @@ private slots: void updateMethodBoxToolTip(); void updateFileName(); + void updateUses(); + void updateUsesNow(); + // refactoring ops void renameIdUnderCursor(); @@ -148,13 +151,16 @@ private: const Context m_context; QTimer *m_updateDocumentTimer; + QTimer *m_updateUsesTimer; QComboBox *m_methodCombo; QList<Declaration> m_declarations; QMap<QString, QList<QmlJS::AST::SourceLocation> > m_ids; // ### use QMultiMap + int m_idsRevision; QList<QmlJS::DiagnosticMessage> m_diagnosticMessages; QmlDocument::Ptr m_document; QmlModelManagerInterface *m_modelManager; Qml::QmlTypeSystem *m_typeSystem; + QTextCharFormat m_occurrencesFormat; }; } // namespace Internal -- GitLab