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)));
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-13 14:08:11 +02:00
|
|
|
QList<QDeclarativeDebugObjectReference > QmlJSLiveTextPreview::objectReferencesForOffset(quint32 offset) const
|
|
|
|
|
{
|
|
|
|
|
QList<QDeclarativeDebugObjectReference > result;
|
|
|
|
|
QHashIterator<QmlJS::AST::UiObjectMember*, QList<QDeclarativeDebugObjectReference > > iter(m_debugIds);
|
|
|
|
|
while(iter.hasNext()) {
|
|
|
|
|
iter.next();
|
|
|
|
|
QmlJS::AST::UiObjectMember *member = iter.key();
|
|
|
|
|
if (member->firstSourceLocation().offset == offset) {
|
|
|
|
|
result = iter.value();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-12 17:18:05 +02:00
|
|
|
void QmlJSLiveTextPreview::changeSelectedElements(QList<int> offsets, const QString &wordAtCursor)
|
2010-07-08 11:34:51 +02:00
|
|
|
{
|
2010-07-13 14:08:11 +02:00
|
|
|
if (!m_currentEditor || !m_previousDoc)
|
2010-07-08 11:34:51 +02:00
|
|
|
return;
|
|
|
|
|
|
2010-07-13 14:08:11 +02:00
|
|
|
if (m_debugIds.isEmpty())
|
|
|
|
|
m_debugIds = m_initialTable.value(m_previousDoc->fileName());
|
|
|
|
|
|
2010-07-08 11:34:51 +02:00
|
|
|
ClientProxy *clientProxy = ClientProxy::instance();
|
|
|
|
|
|
2010-07-12 17:18:05 +02:00
|
|
|
QDeclarativeDebugObjectReference objectRefUnderCursor;
|
2010-07-08 11:34:51 +02:00
|
|
|
|
|
|
|
|
QList<QDeclarativeDebugObjectReference> refs = clientProxy->objectReferences();
|
|
|
|
|
foreach (const QDeclarativeDebugObjectReference &ref, refs) {
|
|
|
|
|
if (ref.idString() == wordAtCursor) {
|
2010-07-12 17:18:05 +02:00
|
|
|
objectRefUnderCursor = ref;
|
2010-07-08 11:34:51 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-12 17:18:05 +02:00
|
|
|
QList<QDeclarativeDebugObjectReference> selectedReferences;
|
2010-07-13 14:08:11 +02:00
|
|
|
bool containsReference = false;
|
2010-07-08 11:34:51 +02:00
|
|
|
|
2010-07-12 17:18:05 +02:00
|
|
|
foreach(int offset, offsets) {
|
|
|
|
|
if (offset >= 0) {
|
2010-07-13 14:08:11 +02:00
|
|
|
QList<QDeclarativeDebugObjectReference> list = objectReferencesForOffset(offset);
|
|
|
|
|
|
2010-07-13 16:13:26 +02:00
|
|
|
if (!containsReference && objectRefUnderCursor.debugId() != -1) {
|
2010-07-13 14:08:11 +02:00
|
|
|
foreach(const QDeclarativeDebugObjectReference &ref, list) {
|
|
|
|
|
if (ref.debugId() == objectRefUnderCursor.debugId()) {
|
|
|
|
|
containsReference = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
selectedReferences << list;
|
2010-07-12 17:18:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!containsReference && objectRefUnderCursor.debugId() != -1)
|
|
|
|
|
selectedReferences << objectRefUnderCursor;
|
|
|
|
|
|
|
|
|
|
if (!selectedReferences.isEmpty())
|
|
|
|
|
emit selectedItemsChanged(selectedReferences);
|
2010-07-08 11:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlJSLiveTextPreview::setEditor(Core::IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
if (!m_currentEditor.isNull()) {
|
2010-07-12 17:18:05 +02:00
|
|
|
disconnect(m_currentEditor.data(), SIGNAL(selectedElementsChanged(QList<int>, QString)), this, SLOT(changeSelectedElements(QList<int>, QString)));
|
2010-07-08 11:34:51 +02:00
|
|
|
m_currentEditor.clear();
|
|
|
|
|
m_previousDoc.clear();
|
2010-07-13 14:08:11 +02:00
|
|
|
m_debugIds.clear();
|
2010-07-08 11:34:51 +02:00
|
|
|
}
|
2010-07-13 14:08:11 +02:00
|
|
|
|
2010-07-08 11:34:51 +02:00
|
|
|
if (editor) {
|
|
|
|
|
m_currentEditor = qobject_cast<QmlJSEditor::Internal::QmlJSTextEditor*>(editor->widget());
|
|
|
|
|
if (m_currentEditor) {
|
2010-07-12 17:18:05 +02:00
|
|
|
connect(m_currentEditor.data(), SIGNAL(selectedElementsChanged(QList<int>, QString)), SLOT(changeSelectedElements(QList<int>, QString)));
|
2010-07-08 11:34:51 +02:00
|
|
|
m_previousDoc = m_snapshot.document(editor->file()->fileName());
|
2010-07-13 14:08:11 +02:00
|
|
|
m_debugIds = m_initialTable.value(editor->file()->fileName());
|
2010-07-08 11:34:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlJSLiveTextPreview::documentChanged(QmlJS::Document::Ptr doc)
|
2010-07-12 17:18:05 +02:00
|
|
|
{
|
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-13 15:01:53 +02:00
|
|
|
if (doc && m_previousDoc && doc->fileName() == m_previousDoc->fileName() && doc->qmlProgram() && m_previousDoc->qmlProgram()) {
|
2010-07-13 14:08:11 +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-13 14:08:11 +02:00
|
|
|
m_debugIds = delta(m_previousDoc, doc, m_debugIds);
|
|
|
|
|
|
2010-07-08 11:34:51 +02:00
|
|
|
m_previousDoc = doc;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlJSInspector
|