Commit 5a971334 authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

qmlsjeditor: activate context pane

parent bc753969
......@@ -41,6 +41,7 @@
#include <qmljs/qmljsdocument.h>
#include <qmljs/qmljslink.h>
#include <qmljs/qmljsscopebuilder.h>
#include <qmljs/qmljsicontextpane.h>
#include <qmljs/parser/qmljsastvisitor_p.h>
#include <qmljs/parser/qmljsast_p.h>
#include <qmljs/parser/qmljsengine_p.h>
......@@ -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>("QmlJSEditor::Internal::SemanticInfo");
......@@ -643,6 +645,10 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) :
baseTextDocument()->setSyntaxHighlighter(new Highlighter(document()));
m_modelManager = ExtensionSystem::PluginManager::instance()->getObject<ModelManagerInterface>();
m_contextPane = ExtensionSystem::PluginManager::instance()->getObject<QmlJS::IContextPane>();
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<QKeyEvent*>(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;
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment