diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index 536deb0bf7a..09f64f55f27 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -610,7 +611,8 @@ QString QmlJSEditorEditable::preferredMode() const QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) : TextEditor::BaseTextEditor(parent), m_methodCombo(0), - m_modelManager(0) + m_modelManager(0), + m_contextPane(0) { qRegisterMetaType("QmlJSEditor::Internal::SemanticInfo"); @@ -643,6 +645,10 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) : baseTextDocument()->setSyntaxHighlighter(new Highlighter(document())); m_modelManager = ExtensionSystem::PluginManager::instance()->getObject(); + m_contextPane = ExtensionSystem::PluginManager::instance()->getObject(); + if (m_contextPane) + connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(onCursorPositionChanged())); + m_oldCurserPosition = -1; if (m_modelManager) { m_semanticHighlighter->setModelManager(m_modelManager); @@ -1073,6 +1079,29 @@ void QmlJSTextEditor::contextMenuEvent(QContextMenuEvent *e) menu->deleteLater(); } +bool QmlJSTextEditor::event(QEvent *e) +{ + switch (e->type()) { + case QEvent::ShortcutOverride: + if (static_cast(e)->key() == Qt::Key_Escape && m_contextPane) { + m_contextPane->apply(editableInterface(), m_semanticInfo.document, 0, false); + } + break; + default: + break; + } + + return BaseTextEditor::event(e); +} + + +void QmlJSTextEditor::wheelEvent(QWheelEvent *event) +{ + BaseTextEditor::wheelEvent(event); + if (m_contextPane) + m_contextPane->apply(editableInterface(), m_semanticInfo.document, m_semanticInfo.declaringMember(position()), true); +} + void QmlJSTextEditor::unCommentSelection() { Utils::unCommentSelection(this); @@ -1295,6 +1324,9 @@ void QmlJSTextEditor::updateSemanticInfo(const SemanticInfo &semanticInfo) FindIdDeclarations updateIds; m_semanticInfo.idLocations = updateIds(doc); + if (m_contextPane) { + m_contextPane->setEnabled(doc->isParsedCorrectly()); + } if (doc->isParsedCorrectly()) { FindDeclarations findDeclarations; m_semanticInfo.declarations = findDeclarations(doc->ast()); @@ -1308,6 +1340,13 @@ void QmlJSTextEditor::updateSemanticInfo(const SemanticInfo &semanticInfo) m_methodCombo->clear(); m_methodCombo->addItems(items); updateMethodBoxIndex(); + if (m_contextPane) { + Node *newNode = m_semanticInfo.declaringMember(position()); + if (newNode) { + m_contextPane->apply(editableInterface(), doc, newNode, true); + m_oldCurserPosition = position(); + } + } } // update warning/error extra selections @@ -1317,6 +1356,17 @@ void QmlJSTextEditor::updateSemanticInfo(const SemanticInfo &semanticInfo) setExtraSelections(CodeWarningsSelection, selections); } +void QmlJSTextEditor::onCursorPositionChanged() +{ + if (m_contextPane) { + Node *newNode = m_semanticInfo.declaringMember(position()); + Node *oldNode = m_semanticInfo.declaringMember(m_oldCurserPosition); + if (oldNode != newNode) + m_contextPane->apply(editableInterface(), m_semanticInfo.document, newNode, false); + m_oldCurserPosition = position(); + } +} + SemanticHighlighter::Source QmlJSTextEditor::currentSource(bool force) { int line = 0, column = 0; diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h index 6d561053ce0..472243ada02 100644 --- a/src/plugins/qmljseditor/qmljseditor.h +++ b/src/plugins/qmljseditor/qmljseditor.h @@ -49,6 +49,7 @@ class ICore; namespace QmlJS { class ModelManagerInterface; + class IContextPane; } namespace QmlJSEditor { @@ -237,9 +238,12 @@ private slots: void semanticRehighlight(); void forceSemanticRehighlight(); void updateSemanticInfo(const QmlJSEditor::Internal::SemanticInfo &semanticInfo); + void onCursorPositionChanged(); protected: void contextMenuEvent(QContextMenuEvent *e); + bool event(QEvent *e); + void wheelEvent(QWheelEvent *event); TextEditor::BaseTextEditorEditable *createEditableInterface(); void createToolBar(QmlJSEditorEditable *editable); TextEditor::BaseTextEditor::Link findLinkAt(const QTextCursor &cursor, bool resolveTarget = true); @@ -273,6 +277,9 @@ private: SemanticHighlighter *m_semanticHighlighter; SemanticInfo m_semanticInfo; + + QmlJS::IContextPane *m_contextPane; + int m_oldCurserPosition; }; } // namespace Internal