From 74610a9137f7df2436ab65d953a3377c608f1187 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Fri, 9 Jul 2010 15:51:40 +0200 Subject: [PATCH] QmlDesigner: change interface for context pane --- src/libs/qmljs/qmljsicontextpane.h | 2 +- .../components/propertyeditor/contextpanewidget.h | 4 ++-- src/plugins/qmldesigner/qmlcontextpane.cpp | 14 +++++++++++++- src/plugins/qmljseditor/qmljseditor.cpp | 10 ++++++---- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/libs/qmljs/qmljsicontextpane.h b/src/libs/qmljs/qmljsicontextpane.h index bc00d56bbc0..34b42f1269f 100644 --- a/src/libs/qmljs/qmljsicontextpane.h +++ b/src/libs/qmljs/qmljsicontextpane.h @@ -52,7 +52,7 @@ class QMLJS_EXPORT IContextPane : public QObject public: IContextPane(QObject *parent = 0) : QObject(parent) {} virtual ~IContextPane() {} - virtual void apply(TextEditor::BaseTextEditorEditable *editor, Document::Ptr doc, AST::Node *node, bool update) = 0; + virtual void apply(TextEditor::BaseTextEditorEditable *editor, Document::Ptr doc, const QmlJS::Snapshot &snapshot, AST::Node *node, bool update) = 0; virtual void setEnabled(bool) = 0; }; diff --git a/src/plugins/qmldesigner/components/propertyeditor/contextpanewidget.h b/src/plugins/qmldesigner/components/propertyeditor/contextpanewidget.h index ce600a5399e..7097d6a5e13 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/contextpanewidget.h +++ b/src/plugins/qmldesigner/components/propertyeditor/contextpanewidget.h @@ -22,8 +22,8 @@ class ContextPaneWidget : public QFrame public: explicit ContextPaneWidget(QWidget *parent = 0); ~ContextPaneWidget(); - void activate(const QPoint &pos, const QPoint &alternative); - void rePosition(const QPoint &pos, const QPoint &alternative); + void activate(const QPoint &pos, const QPoint &alternative, const QPoint &alternative2); + void rePosition(const QPoint &pos, const QPoint &alternative , const QPoint &alternative3); void deactivate(); BauhausColorDialog *colorDialog(); void setProperties(QmlJS::PropertyReader *propertyReader); diff --git a/src/plugins/qmldesigner/qmlcontextpane.cpp b/src/plugins/qmldesigner/qmlcontextpane.cpp index 88c65ab9a1b..a6fc9de9e2c 100644 --- a/src/plugins/qmldesigner/qmlcontextpane.cpp +++ b/src/plugins/qmldesigner/qmlcontextpane.cpp @@ -8,6 +8,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -62,7 +65,7 @@ QmlContextPane::~QmlContextPane() m_widget.clear(); } -void QmlContextPane::apply(TextEditor::BaseTextEditorEditable *editor, Document::Ptr doc, Node *node, bool update) +void QmlContextPane::apply(TextEditor::BaseTextEditorEditable *editor, Document::Ptr doc, const QmlJS::Snapshot &snapshot, AST::Node *node, bool update) { if (!Internal::BauhausPlugin::pluginInstance()->settings().enableContextPane) return; @@ -73,6 +76,15 @@ void QmlContextPane::apply(TextEditor::BaseTextEditorEditable *editor, Document: if (update && editor != m_editor) return; //do not update for different editor + LookupContext::Ptr lookupContext = LookupContext::create(doc, snapshot, QList()); + const Interpreter::ObjectValue *scopeObject = doc->bind()->findQmlObject(node); + + QStringList prototypes; + while (scopeObject) { + prototypes.append(scopeObject->className()); + scopeObject = scopeObject->prototype(lookupContext->context()); + } + setEnabled(doc->isParsedCorrectly()); m_editor = editor; contextWidget()->setParent(editor->widget()->parentWidget()); diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index a9a74a85fcc..1d51d1be336 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -1085,7 +1085,7 @@ 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); + m_contextPane->apply(editableInterface(), m_semanticInfo.document, m_semanticInfo.snapshot, 0, false); } break; default: @@ -1100,7 +1100,7 @@ void QmlJSTextEditor::wheelEvent(QWheelEvent *event) { BaseTextEditor::wheelEvent(event); if (m_contextPane) - m_contextPane->apply(editableInterface(), m_semanticInfo.document, m_semanticInfo.declaringMember(position()), true); + m_contextPane->apply(editableInterface(), m_semanticInfo.document, m_semanticInfo.snapshot, m_semanticInfo.declaringMember(position()), true); } void QmlJSTextEditor::unCommentSelection() @@ -1344,7 +1344,7 @@ void QmlJSTextEditor::updateSemanticInfo(const SemanticInfo &semanticInfo) if (m_contextPane) { Node *newNode = m_semanticInfo.declaringMember(position()); if (newNode) { - m_contextPane->apply(editableInterface(), doc, newNode, true); + m_contextPane->apply(editableInterface(), doc, m_semanticInfo.snapshot, newNode, true); m_oldCurserPosition = position(); } } @@ -1361,11 +1361,13 @@ void QmlJSTextEditor::updateSemanticInfo(const SemanticInfo &semanticInfo) 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_contextPane->apply(editableInterface(), m_semanticInfo.document, m_semanticInfo.snapshot, newNode, false); m_oldCurserPosition = position(); } }