2010-07-08 11:34:51 +02:00
|
|
|
#include <typeinfo>
|
|
|
|
|
|
|
|
|
|
#include "qmljsclientproxy.h"
|
|
|
|
|
#include "qmljslivetextpreview.h"
|
|
|
|
|
#include "qmljsdelta.h"
|
|
|
|
|
#include "qmljsprivateapi.h"
|
|
|
|
|
|
|
|
|
|
#include <qmljseditor/qmljseditorconstants.h>
|
|
|
|
|
#include <qmljseditor/qmljseditor.h>
|
|
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
|
|
|
|
#include <coreplugin/uniqueidmanager.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
|
|
|
|
|
#include <debugger/debuggerconstants.h>
|
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
using namespace QmlJS::AST;
|
|
|
|
|
|
|
|
|
|
namespace QmlJSInspector {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
QmlJSLiveTextPreview::QmlJSLiveTextPreview(QObject *parent) :
|
|
|
|
|
QObject(parent)
|
|
|
|
|
{
|
|
|
|
|
Core::EditorManager *editorManager = Core::EditorManager::instance();
|
|
|
|
|
connect(editorManager->instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
|
|
|
|
|
SLOT(setEditor(Core::IEditor*)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QmlJS::ModelManagerInterface *QmlJSLiveTextPreview::modelManager()
|
|
|
|
|
{
|
|
|
|
|
return ExtensionSystem::PluginManager::instance()->getObject<QmlJS::ModelManagerInterface>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlJSLiveTextPreview::updateDocuments()
|
|
|
|
|
{
|
|
|
|
|
if (!modelManager())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_snapshot = modelManager()->snapshot();
|
2010-07-08 16:51:25 +02:00
|
|
|
setEditor(Core::EditorManager::instance()->currentEditor());
|
2010-07-08 11:34:51 +02:00
|
|
|
|
|
|
|
|
// initial update
|
|
|
|
|
foreach (QmlJS::Document::Ptr doc, m_snapshot) {
|
|
|
|
|
documentChanged(doc);
|
|
|
|
|
}
|
|
|
|
|
connect(modelManager(), SIGNAL(documentChangedOnDisk(QmlJS::Document::Ptr)),
|
|
|
|
|
SLOT(documentChanged(QmlJS::Document::Ptr)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlJSLiveTextPreview::changeSelectedElement(int offset, const QString &wordAtCursor)
|
|
|
|
|
{
|
|
|
|
|
if (!m_currentEditor)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ClientProxy *clientProxy = ClientProxy::instance();
|
|
|
|
|
QUrl url = QUrl::fromLocalFile(m_currentEditor.data()->file()->fileName());
|
|
|
|
|
QmlJS::Document::Ptr doc = modelManager()->snapshot().document(m_currentEditor.data()->file()->fileName());
|
2010-07-09 17:02:36 +02:00
|
|
|
//ScriptBindingParser info(doc, clientProxy->objectReferences(url));
|
2010-07-08 11:34:51 +02:00
|
|
|
|
|
|
|
|
QDeclarativeDebugObjectReference objectRef;
|
|
|
|
|
|
|
|
|
|
QList<QDeclarativeDebugObjectReference> refs = clientProxy->objectReferences();
|
|
|
|
|
foreach (const QDeclarativeDebugObjectReference &ref, refs) {
|
|
|
|
|
if (ref.idString() == wordAtCursor) {
|
|
|
|
|
objectRef = ref;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-09 17:02:36 +02:00
|
|
|
/* FIXME
|
2010-07-08 11:34:51 +02:00
|
|
|
if (objectRef.debugId() == -1 && offset >= 0) {
|
|
|
|
|
objectRef = info.objectReferenceForOffset(offset);
|
2010-07-09 17:02:36 +02:00
|
|
|
}*/
|
2010-07-08 11:34:51 +02:00
|
|
|
|
|
|
|
|
if (objectRef.debugId() != -1)
|
|
|
|
|
emit selectedItemsChanged(QList<QDeclarativeDebugObjectReference>() << objectRef);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlJSLiveTextPreview::setEditor(Core::IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
if (!m_currentEditor.isNull()) {
|
|
|
|
|
disconnect(m_currentEditor.data(), SIGNAL(selectedElementChanged(int, QString)), this, SLOT(changeSelectedElement(int, QString)));
|
|
|
|
|
m_currentEditor.clear();
|
|
|
|
|
m_previousDoc.clear();
|
|
|
|
|
}
|
|
|
|
|
if (editor) {
|
|
|
|
|
m_currentEditor = qobject_cast<QmlJSEditor::Internal::QmlJSTextEditor*>(editor->widget());
|
|
|
|
|
if (m_currentEditor) {
|
|
|
|
|
connect(m_currentEditor.data(), SIGNAL(selectedElementChanged(int, QString)), SLOT(changeSelectedElement(int, QString)));
|
|
|
|
|
m_previousDoc = m_snapshot.document(editor->file()->fileName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-09 17:02:36 +02:00
|
|
|
|
2010-07-08 11:34:51 +02:00
|
|
|
void QmlJSLiveTextPreview::documentChanged(QmlJS::Document::Ptr doc)
|
2010-07-09 17:02:36 +02:00
|
|
|
{
|
|
|
|
|
/* FIXME
|
2010-07-08 11:34:51 +02:00
|
|
|
Core::ICore *core = Core::ICore::instance();
|
|
|
|
|
const int dbgcontext = core->uniqueIDManager()->uniqueIdentifier(Debugger::Constants::C_DEBUGMODE);
|
|
|
|
|
|
2010-07-08 16:51:25 +02:00
|
|
|
if (!core->hasContext(dbgcontext))
|
2010-07-08 11:34:51 +02:00
|
|
|
return;
|
2010-07-09 17:02:36 +02:00
|
|
|
*/
|
2010-07-08 11:34:51 +02:00
|
|
|
|
2010-07-08 16:51:25 +02:00
|
|
|
if (doc && m_previousDoc && doc->fileName() == m_previousDoc->fileName()) {
|
2010-07-09 17:02:36 +02:00
|
|
|
|
|
|
|
|
if (m_debugIds.isEmpty())
|
|
|
|
|
m_debugIds = m_initialTable.value(doc->fileName());
|
2010-07-08 11:34:51 +02:00
|
|
|
Delta delta;
|
2010-07-09 17:02:36 +02:00
|
|
|
m_debugIds = delta(m_previousDoc, doc, m_debugIds);
|
2010-07-08 11:34:51 +02:00
|
|
|
m_previousDoc = doc;
|
2010-07-09 17:02:36 +02:00
|
|
|
|
2010-07-08 11:34:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-09 17:02:36 +02:00
|
|
|
|
2010-07-08 11:34:51 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlJSInspector
|