diff --git a/src/libs/qmljs/qmljsicontextpane.h b/src/libs/qmljs/qmljsicontextpane.h index 8f9cd7271ad..1f32cc1c122 100644 --- a/src/libs/qmljs/qmljsicontextpane.h +++ b/src/libs/qmljs/qmljsicontextpane.h @@ -37,7 +37,7 @@ #include #include -namespace TextEditor { class BaseTextEditor; } +namespace TextEditor { class BaseTextEditorWidget; } namespace QmlJS { @@ -50,9 +50,9 @@ class QMLJS_EXPORT IContextPane : public QObject public: IContextPane(QObject *parent = 0) : QObject(parent) {} virtual ~IContextPane() {} - virtual void apply(TextEditor::BaseTextEditor *editor, Document::Ptr document, const ScopeChain *scopeChain, AST::Node *node, bool update, bool force = false) = 0; + virtual void apply(TextEditor::BaseTextEditorWidget *editorWidget, Document::Ptr document, const ScopeChain *scopeChain, AST::Node *node, bool update, bool force = false) = 0; virtual void setEnabled(bool) = 0; - virtual bool isAvailable(TextEditor::BaseTextEditor *editor, Document::Ptr document, AST::Node *node) = 0; + virtual bool isAvailable(TextEditor::BaseTextEditorWidget *editorWidget, Document::Ptr document, AST::Node *node) = 0; virtual QWidget* widget() = 0; signals: void closed(); diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index 75bed88a6ba..084b9e96443 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -306,9 +306,9 @@ void QmlJSEditorWidget::updateContextPane() Node *oldNode = info.declaringMemberNoProperties(m_oldCursorPosition); Node *newNode = info.declaringMemberNoProperties(position()); if (oldNode != newNode && m_oldCursorPosition != -1) - m_contextPane->apply(editor(), info.document, 0, newNode, false); + m_contextPane->apply(this, info.document, 0, newNode, false); - if (m_contextPane->isAvailable(editor(), info.document, newNode) && + if (m_contextPane->isAvailable(this, info.document, newNode) && !m_contextPane->widget()->isVisible()) { QList markers = removeMarkersOfType(refactorMarkers()); if (UiObjectMember *m = newNode->uiObjectMemberCast()) { @@ -663,7 +663,7 @@ void QmlJSEditorWidget::showContextPane() if (m_contextPane && info.isValid()) { Node *newNode = info.declaringMemberNoProperties(position()); ScopeChain scopeChain = info.scopeChain(info.rangePath(position())); - m_contextPane->apply(editor(), info.document, + m_contextPane->apply(this, info.document, &scopeChain, newNode, false, true); m_oldCursorPosition = position(); @@ -716,7 +716,7 @@ void QmlJSEditorWidget::contextMenuEvent(QContextMenuEvent *e) menu->addMenu(refactoringMenu); if (action->objectName() == QLatin1String(Constants::SHOW_QT_QUICK_HELPER)) { bool enabled = m_contextPane->isAvailable( - editor(), m_qmlJsEditorDocument->semanticInfo().document, + this, m_qmlJsEditorDocument->semanticInfo().document, m_qmlJsEditorDocument->semanticInfo().declaringMemberNoProperties(position())); action->setEnabled(enabled); } @@ -760,7 +760,7 @@ void QmlJSEditorWidget::wheelEvent(QWheelEvent *event) BaseTextEditorWidget::wheelEvent(event); if (visible) - m_contextPane->apply(editor(), m_qmlJsEditorDocument->semanticInfo().document, 0, + m_contextPane->apply(this, m_qmlJsEditorDocument->semanticInfo().document, 0, m_qmlJsEditorDocument->semanticInfo().declaringMemberNoProperties(m_oldCursorPosition), false, true); } @@ -792,7 +792,7 @@ void QmlJSEditorWidget::semanticInfoUpdated(const SemanticInfo &semanticInfo) if (m_contextPane) { Node *newNode = semanticInfo.declaringMemberNoProperties(position()); if (newNode) { - m_contextPane->apply(editor(), semanticInfo.document, 0, newNode, true); + m_contextPane->apply(this, semanticInfo.document, 0, newNode, true); m_contextPaneTimer.start(); //update text marker } } @@ -834,7 +834,7 @@ bool QmlJSEditorWidget::hideContextPane() { bool b = (m_contextPane) && m_contextPane->widget()->isVisible(); if (b) - m_contextPane->apply(editor(), m_qmlJsEditorDocument->semanticInfo().document, 0, 0, false); + m_contextPane->apply(this, m_qmlJsEditorDocument->semanticInfo().document, 0, 0, false); return b; } @@ -845,7 +845,7 @@ IAssistInterface *QmlJSEditorWidget::createAssistInterface( if (assistKind == TextEditor::Completion) { return new QmlJSCompletionAssistInterface(document(), position(), - editor()->document()->filePath(), + textDocument()->filePath(), reason, m_qmlJsEditorDocument->semanticInfo()); } else if (assistKind == TextEditor::QuickFix) { diff --git a/src/plugins/qmljseditor/quicktoolbar.cpp b/src/plugins/qmljseditor/quicktoolbar.cpp index f4a39733c09..45d13bb49e7 100644 --- a/src/plugins/qmljseditor/quicktoolbar.cpp +++ b/src/plugins/qmljseditor/quicktoolbar.cpp @@ -79,7 +79,7 @@ static inline const ObjectValue * getPropertyChangesTarget(Node *node, const Sco QuickToolBar::QuickToolBar(QObject *parent) : ::QmlJS::IContextPane(parent) - , m_editor(0) + , m_editorWidget(0) , m_blockWriting(false) { m_node = 0; @@ -115,7 +115,7 @@ QuickToolBar::~QuickToolBar() m_widget = 0; } -void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr document, const ScopeChain *scopeChain, AST::Node *node, bool update, bool force) +void QuickToolBar::apply(TextEditor::BaseTextEditorWidget *editorWidget, Document::Ptr document, const ScopeChain *scopeChain, AST::Node *node, bool update, bool force) { if (!QuickToolBarSettings::get().enableContextPane && !force && !update) { contextWidget()->hide(); @@ -125,7 +125,7 @@ void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr docum if (document.isNull()) return; - if (update && editor != m_editor) + if (update && editorWidget != m_editorWidget) return; //do not update for different editor m_blockWriting = true; @@ -155,9 +155,9 @@ void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr docum } setEnabled(document->isParsedCorrectly()); - m_editor = editor; - contextWidget()->setParent(editor->widget()->parentWidget()); - contextWidget()->colorDialog()->setParent(editor->widget()->parentWidget()); + m_editorWidget = editorWidget; + contextWidget()->setParent(editorWidget->parentWidget()); + contextWidget()->colorDialog()->setParent(editorWidget->parentWidget()); if (cast(node) || cast(node)) { UiObjectDefinition *objectDefinition = cast(node); @@ -192,12 +192,12 @@ void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr docum int column1; int line2; int column2; - m_editor->convertPosition(offset, &line1, &column1); //get line - m_editor->convertPosition(end, &line2, &column2); //get line + m_editorWidget->convertPosition(offset, &line1, &column1); //get line + m_editorWidget->convertPosition(end, &line2, &column2); //get line QRegion reg; if (line1 > -1 && line2 > -1) - reg = m_editor->editorWidget()->translatedLineRegion(line1 - 1, line2); + reg = m_editorWidget->translatedLineRegion(line1 - 1, line2); QRect rect; rect.setHeight(widget()->height() + 10); @@ -208,16 +208,15 @@ void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr docum if (contextWidget()->acceptsType(m_prototypes)) { m_node = 0; PropertyReader propertyReader(document, initializer); - QTextCursor tc = editor->textCursor(); - QPlainTextEdit *editorWidget = editor->editorWidget(); + QTextCursor tc = m_editorWidget->textCursor(); tc.setPosition(offset); - QPoint p1 = editorWidget->mapToParent(editorWidget->viewport()->mapToParent(editorWidget->cursorRect(tc).topLeft()) - QPoint(0, contextWidget()->height() + 10)); + QPoint p1 = m_editorWidget->mapToParent(m_editorWidget->viewport()->mapToParent(m_editorWidget->cursorRect(tc).topLeft()) - QPoint(0, contextWidget()->height() + 10)); tc.setPosition(end); - QPoint p2 = editorWidget->mapToParent(editorWidget->viewport()->mapToParent(editorWidget->cursorRect(tc).bottomLeft()) + QPoint(0, 10)); + QPoint p2 = m_editorWidget->mapToParent(m_editorWidget->viewport()->mapToParent(m_editorWidget->cursorRect(tc).bottomLeft()) + QPoint(0, 10)); QPoint offset = QPoint(10, 0); if (reg.boundingRect().width() < 400) offset = QPoint(400 - reg.boundingRect().width() + 10 ,0); - QPoint p3 = editorWidget->mapToParent(editorWidget->viewport()->mapToParent(reg.boundingRect().topRight()) + offset); + QPoint p3 = m_editorWidget->mapToParent(m_editorWidget->viewport()->mapToParent(reg.boundingRect().topRight()) + offset); p2.setX(p1.x()); contextWidget()->setIsPropertyChanges(isPropertyChanges); if (!update) @@ -246,7 +245,7 @@ void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr docum } -bool QuickToolBar::isAvailable(TextEditor::BaseTextEditor *, Document::Ptr document, AST::Node *node) +bool QuickToolBar::isAvailable(TextEditor::BaseTextEditorWidget *, Document::Ptr document, AST::Node *node) { if (document.isNull()) return false; @@ -319,12 +318,12 @@ void QuickToolBar::setProperty(const QString &propertyName, const QVariant &valu int changeSetPos = changeSet.operationList().last().pos1; int changeSetLength = changeSet.operationList().last().text.length(); - QTextCursor tc = m_editor->editorWidget()->textCursor(); + QTextCursor tc = m_editorWidget->textCursor(); tc.beginEditBlock(); changeSet.apply(&tc); - m_editor->convertPosition(changeSetPos, &line, &column); //get line - m_editor->convertPosition(changeSetPos + changeSetLength, &endLine, &column); //get line + m_editorWidget->convertPosition(changeSetPos, &line, &column); //get line + m_editorWidget->convertPosition(changeSetPos + changeSetLength, &endLine, &column); //get line indentLines(line, endLine); tc.endEditBlock(); @@ -348,7 +347,7 @@ void QuickToolBar::removeProperty(const QString &propertyName) Utils::ChangeSet changeSet; Rewriter rewriter(m_doc->source(), &changeSet, m_propertyOrder); rewriter.removeBindingByName(initializer, propertyName); - QTextCursor tc(m_editor->editorWidget()->document()); + QTextCursor tc(m_editorWidget->document()); changeSet.apply(&tc); } } @@ -388,7 +387,7 @@ void QuickToolBar::onPropertyRemovedAndChange(const QString &remove, const QStri if (!m_doc) return; - QTextCursor tc = m_editor->textCursor(); + QTextCursor tc = m_editorWidget->textCursor(); tc.beginEditBlock(); if (removeFirst) { @@ -424,13 +423,13 @@ void QuickToolBar::onEnabledChanged(bool b) void QuickToolBar::indentLines(int startLine, int endLine) { if (startLine > 0) { - TextEditor::TabSettings tabSettings = m_editor->textDocument()->tabSettings(); + TextEditor::TabSettings tabSettings = m_editorWidget->textDocument()->tabSettings(); for (int i = startLine; i <= endLine; i++) { - QTextBlock start = m_editor->qdocument()->findBlockByNumber(i); + QTextBlock start = m_editorWidget->document()->findBlockByNumber(i); if (start.isValid()) { QmlJSEditor::Internal::Indenter indenterMy; - indenterMy.indentBlock(m_editor->qdocument(), start, QChar::Null, tabSettings); + indenterMy.indentBlock(m_editorWidget->document(), start, QChar::Null, tabSettings); } } } diff --git a/src/plugins/qmljseditor/quicktoolbar.h b/src/plugins/qmljseditor/quicktoolbar.h index 46e10abb815..38c28d73ad7 100644 --- a/src/plugins/qmljseditor/quicktoolbar.h +++ b/src/plugins/qmljseditor/quicktoolbar.h @@ -34,8 +34,6 @@ #include -namespace TextEditor { class BaseTextEditor; } - namespace QmlEditorWidgets { class ContextPaneWidget; } namespace QmlJSEditor { @@ -47,8 +45,8 @@ class QuickToolBar : public QmlJS::IContextPane public: QuickToolBar(QObject *parent = 0); ~QuickToolBar(); - void apply(TextEditor::BaseTextEditor *editor, QmlJS::Document::Ptr document, const QmlJS::ScopeChain *scopeChain, QmlJS::AST::Node *node, bool update, bool force = false); - bool isAvailable(TextEditor::BaseTextEditor *editor, QmlJS::Document::Ptr document, QmlJS::AST::Node *node); + void apply(TextEditor::BaseTextEditorWidget *widget, QmlJS::Document::Ptr document, const QmlJS::ScopeChain *scopeChain, QmlJS::AST::Node *node, bool update, bool force = false); + bool isAvailable(TextEditor::BaseTextEditorWidget *widget, QmlJS::Document::Ptr document, QmlJS::AST::Node *node); void setProperty(const QString &propertyName, const QVariant &value); void removeProperty(const QString &propertyName); void setEnabled(bool); @@ -68,7 +66,7 @@ private: QPointer m_widget; QmlJS::Document::Ptr m_doc; QmlJS::AST::Node *m_node; - TextEditor::BaseTextEditor *m_editor; + TextEditor::BaseTextEditorWidget *m_editorWidget; bool m_blockWriting; QStringList m_propertyOrder; QStringList m_prototypes;