diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index 62bdd051573b91d81945fc7dcd865e43d7b6446c..4af64c3da6c8fb602d9c84f2164897e388add4ce 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -60,6 +60,7 @@ #include <texteditor/texteditorconstants.h> #include <texteditor/texteditorsettings.h> #include <texteditor/syntaxhighlighter.h> +#include <texteditor/refactoroverlay.h> #include <qmldesigner/qmldesignerconstants.h> #include <utils/changeset.h> #include <utils/uncommentselection.h> @@ -702,6 +703,11 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) : m_updateOutlineIndexTimer->setSingleShot(true); connect(m_updateOutlineIndexTimer, SIGNAL(timeout()), this, SLOT(updateOutlineIndexNow())); + m_curserPositionTimer = new QTimer(this); + m_curserPositionTimer->setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL); + m_curserPositionTimer->setSingleShot(true); + connect(m_curserPositionTimer, SIGNAL(timeout()), this, SLOT(updateCursorPositionNow())); + baseTextDocument()->setSyntaxHighlighter(new Highlighter(document())); m_modelManager = ExtensionSystem::PluginManager::instance()->getObject<ModelManagerInterface>(); @@ -720,6 +726,9 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) : connect(m_semanticHighlighter, SIGNAL(changed(QmlJSEditor::Internal::SemanticInfo)), this, SLOT(updateSemanticInfo(QmlJSEditor::Internal::SemanticInfo))); + connect(this, SIGNAL(refactorMarkerClicked(TextEditor::Internal::RefactorMarker)), + SLOT(onRefactorMarkerClicked(TextEditor::Internal::RefactorMarker))); + setRequestMarkEnabled(true); } @@ -931,6 +940,46 @@ void QmlJSTextEditor::updateOutlineIndexNow() updateUses(); } +static UiQualifiedId *qualifiedTypeNameId(UiObjectMember *m) +{ + if (UiObjectDefinition *def = cast<UiObjectDefinition *>(m)) + return def->qualifiedTypeNameId; + else if (UiObjectBinding *binding = cast<UiObjectBinding *>(m)) + return binding->qualifiedTypeNameId; + return 0; +} + +void QmlJSTextEditor::updateCursorPositionNow() +{ + if (m_contextPane && document() && !semanticInfo().document.isNull() && + document()->revision() == semanticInfo().document->editorRevision()) { + Node *oldNode = m_semanticInfo.declaringMemberNoProperties(m_oldCursorPosition); + Node *newNode = m_semanticInfo.declaringMemberNoProperties(position()); + if (oldNode != newNode && + m_contextPane->isAvailable(editableInterface(), m_semanticInfo.document, m_semanticInfo.snapshot, newNode)) { + QList<TextEditor::Internal::RefactorMarker> markers; + if (UiObjectMember *m = newNode->uiObjectMemberCast()) { + const int start = m->firstSourceLocation().begin(); + for (UiQualifiedId *q = qualifiedTypeNameId(m); q; q = q->next) { + if (! q->next) { + const int end = q->identifierToken.end(); + TextEditor::Internal::RefactorMarker marker; + QTextCursor tc(document()); + tc.setPosition(end); + marker.cursor = tc; + marker.tooltip = tr("Show Qt Quick Helper"); + markers.append(marker); + } + } + } + setRefactorMarkers(markers); + } + if (oldNode != newNode) + m_contextPane->apply(editableInterface(), m_semanticInfo.document, m_semanticInfo.snapshot, newNode, false); + m_oldCursorPosition = position(); + } +} + void QmlJSTextEditor::updateUses() { m_updateUsesTimer->start(); @@ -1661,15 +1710,14 @@ void QmlJSTextEditor::updateSemanticInfo(const SemanticInfo &semanticInfo) setExtraSelections(CodeWarningsSelection, selections); } +void QmlJSTextEditor::onRefactorMarkerClicked(const TextEditor::Internal::RefactorMarker &) +{ + showContextPane(); +} + void QmlJSTextEditor::onCursorPositionChanged() { - if (m_contextPane) { - Node *newNode = m_semanticInfo.declaringMemberNoProperties(position()); - Node *oldNode = m_semanticInfo.declaringMemberNoProperties(m_oldCursorPosition); - if (oldNode != newNode) - m_contextPane->apply(editableInterface(), m_semanticInfo.document, m_semanticInfo.snapshot, newNode, false); - m_oldCursorPosition = position(); - } + m_curserPositionTimer->start(); } QModelIndex QmlJSTextEditor::indexForPosition(unsigned cursorPosition, const QModelIndex &rootIndex) const diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h index 79f03fd61370ff0904ef907f352c96365b69d8f2..5f9765a7a117776f051fe43ee4780b5000dcbef4 100644 --- a/src/plugins/qmljseditor/qmljseditor.h +++ b/src/plugins/qmljseditor/qmljseditor.h @@ -243,6 +243,7 @@ private slots: void jumpToOutlineElement(int index); void updateOutlineNow(); void updateOutlineIndexNow(); + void updateCursorPositionNow(); void updateFileName(); void updateUses(); @@ -255,6 +256,7 @@ private slots: void forceSemanticRehighlight(); void updateSemanticInfo(const QmlJSEditor::Internal::SemanticInfo &semanticInfo); void onCursorPositionChanged(); + void onRefactorMarkerClicked(const TextEditor::Internal::RefactorMarker &marker); protected: void contextMenuEvent(QContextMenuEvent *e); @@ -292,6 +294,7 @@ private: QTimer *m_semanticRehighlightTimer; QTimer *m_updateOutlineTimer; QTimer *m_updateOutlineIndexTimer; + QTimer *m_curserPositionTimer; QComboBox *m_outlineCombo; QmlOutlineModel *m_outlineModel; QModelIndex m_outlineModelIndex; diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index c15b78d16eb82f601b67f2af5826ef4220452796..ecd0494fce0f78534450d9318b709223d491d5d5 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -359,7 +359,7 @@ public: void setRefactorMarkers(const Internal::RefactorMarkers &markers); signals: - void refactorMarkerClicked(const Internal::RefactorMarker &marker); + void refactorMarkerClicked(const TextEditor::Internal::RefactorMarker &marker); public: