void QmlJSLiveTextPreview::associateEditor(Core::IEditor *editor) { if (editor->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID) { QmlJSEditor::QmlJSTextEditorWidget* qmljsEditor = qobject_cast<QmlJSEditor::QmlJSTextEditorWidget*>(editor->widget()); if (qmljsEditor && !m_editors.contains(qmljsEditor)) { qmljsEditor->setUpdateSelectedElements(true); m_editors << qmljsEditor; connect(qmljsEditor, SIGNAL(selectedElementsChanged(QList<int>,QString)), SLOT(changeSelectedElements(QList<int>,QString))); } } }
void QmlJSLiveTextPreview::unassociateEditor(Core::IEditor *oldEditor) { if (oldEditor && oldEditor->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID) { QmlJSEditor::QmlJSTextEditorWidget* qmljsEditor = qobject_cast<QmlJSEditor::QmlJSTextEditorWidget*>(oldEditor->widget()); if (qmljsEditor && m_editors.contains(qmljsEditor)) { m_editors.removeOne(qmljsEditor); qmljsEditor->setUpdateSelectedElements(false); disconnect(qmljsEditor, SIGNAL(selectedElementsChanged(QList<int>,QString)), this, SLOT(changeSelectedElements(QList<int>,QString))); } } }
void HoverHandler::identifyMatch(TextEditor::ITextEditor *editor, int pos) { reset(); if (!m_modelManager) return; QmlJSEditor::QmlJSTextEditorWidget *qmlEditor = qobject_cast<QmlJSEditor::QmlJSTextEditorWidget *>(editor->widget()); if (!qmlEditor) return; if (matchDiagnosticMessage(qmlEditor, pos)) return; const QmlJSEditor::SemanticInfo &semanticInfo = qmlEditor->semanticInfo(); if (! semanticInfo.isValid() || semanticInfo.revision() != qmlEditor->editorRevision()) return; QList<AST::Node *> rangePath = semanticInfo.rangePath(pos); const Document::Ptr qmlDocument = semanticInfo.document; ScopeChain scopeChain = semanticInfo.scopeChain(rangePath); QList<AST::Node *> astPath = semanticInfo.astPath(pos); QTC_ASSERT(!astPath.isEmpty(), return); AST::Node *node = astPath.last(); if (rangePath.isEmpty()) { // Is the cursor on an import? The ast path will have an UiImport // member in the last or second to last position! AST::UiImport *import = 0; if (astPath.size() >= 1) import = AST::cast<AST::UiImport *>(astPath.last()); if (!import && astPath.size() >= 2) import = AST::cast<AST::UiImport *>(astPath.at(astPath.size() - 2)); if (import) handleImport(scopeChain, import); return; } if (matchColorItem(scopeChain, qmlDocument, rangePath, pos)) return; handleOrdinaryMatch(scopeChain, node); TextEditor::HelpItem helpItem = qmlHelpItem(scopeChain, node); if (!helpItem.helpId().isEmpty()) setLastHelpItemIdentified(helpItem); }
void HoverHandler::identifyMatch(TextEditor::ITextEditor *editor, int pos) { reset(); if (!m_modelManager) return; QmlJSEditor::QmlJSTextEditorWidget *qmlEditor = qobject_cast<QmlJSEditor::QmlJSTextEditorWidget *>(editor->widget()); if (!qmlEditor) return; if (matchDiagnosticMessage(qmlEditor, pos)) return; const QmlJSEditor::SemanticInfo &semanticInfo = qmlEditor->semanticInfo(); if (! semanticInfo.isValid() || semanticInfo.revision() != qmlEditor->editorRevision()) return; QList<AST::Node *> astPath = semanticInfo.rangePath(pos); const Document::Ptr qmlDocument = semanticInfo.document; ScopeChain scopeChain = semanticInfo.scopeChain(astPath); AST::Node *node = semanticInfo.nodeUnderCursor(pos); if (astPath.isEmpty()) { if (AST::UiImport *import = AST::cast<AST::UiImport *>(node)) handleImport(scopeChain, import); return; } if (matchColorItem(scopeChain, qmlDocument, astPath, pos)) return; handleOrdinaryMatch(scopeChain, node); TextEditor::HelpItem helpItem = qmlHelpItem(scopeChain, node); if (!helpItem.helpId().isEmpty()) setLastHelpItemIdentified(helpItem); }
Core::IEditor *QmlJSEditorFactory::createEditor(QWidget *parent) { QmlJSEditor::QmlJSTextEditorWidget *rc = new QmlJSEditor::QmlJSTextEditorWidget(parent); QmlJSEditorPlugin::instance()->initializeEditor(rc); return rc->editor(); }