qmlinspectoradapter.cpp 21.2 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11 12
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
Eike Ziller's avatar
Eike Ziller committed
13 14
** conditions see http://www.qt.io/licensing.  For further information
** use the contact form at http://www.qt.io/contact-us.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18 19 20 21 22 23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hjk's avatar
hjk committed
24 25 26
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
27 28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
30 31 32 33 34 35

#include "qmlinspectoradapter.h"

#include "qmladapter.h"
#include "qmlinspectoragent.h"
#include "qmllivetextpreview.h"
36 37 38 39
#include <debugger/debuggeractions.h>
#include <debugger/debuggercore.h>
#include <debugger/debuggerstringutils.h>
#include <debugger/debuggerengine.h>
40 41 42 43

#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/icore.h>
#include <qmldebug/declarativeenginedebugclient.h>
44
#include <qmldebug/declarativeenginedebugclientv2.h>
45 46 47 48 49 50 51 52
#include <qmldebug/declarativetoolsclient.h>
#include <qmldebug/qmlenginedebugclient.h>
#include <qmldebug/qmltoolsclient.h>
#include <qmljseditor/qmljseditorconstants.h>
#include <qmljs/qmljsmodelmanagerinterface.h>
#include <utils/qtcassert.h>
#include <utils/savedaction.h>

Friedemann Kleint's avatar
Friedemann Kleint committed
53 54
#include <QFileInfo>

55 56 57 58 59 60 61 62 63
using namespace QmlDebug;

namespace Debugger {
namespace Internal {
/*!
 * QmlInspectorAdapter manages the clients for the inspector, and the
 * integration with the text editor.
 */
QmlInspectorAdapter::QmlInspectorAdapter(QmlAdapter *debugAdapter,
64
                                         DebuggerEngine *engine,
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
                                         QObject *parent)
    : QObject(parent)
    , m_debugAdapter(debugAdapter)
    , m_engine(engine)
    , m_engineClient(0)
    , m_toolsClient(0)
    , m_agent(new QmlInspectorAgent(engine, this))
    , m_targetToSync(NoTarget)
    , m_debugIdToSelect(-1)
    , m_currentSelectedDebugId(-1)
    , m_listeningToEditorManager(false)
    , m_toolsClientConnected(false)
    , m_inspectorToolsContext("Debugger.QmlInspector")
    , m_selectAction(new QAction(this))
    , m_zoomAction(new QAction(this))
hjk's avatar
hjk committed
80 81
    , m_showAppOnTopAction(action(ShowAppOnTop))
    , m_updateOnSaveAction(action(QmlUpdateOnSave))
82
    , m_engineClientConnected(false)
83
{
84 85 86 87
    if (!m_engine->isMasterEngine())
        m_engine = m_engine->masterEngine();
    connect(m_engine, SIGNAL(stateChanged(Debugger::DebuggerState)),
            SLOT(onEngineStateChanged(Debugger::DebuggerState)));
Kai Koehne's avatar
Kai Koehne committed
88 89
    connect(m_agent, SIGNAL(objectFetched(QmlDebug::ObjectReference)),
            SLOT(onObjectFetched(QmlDebug::ObjectReference)));
Aurindam Jana's avatar
Aurindam Jana committed
90 91
    connect(m_agent, SIGNAL(jumpToObjectDefinition(QmlDebug::FileReference,int)),
            SLOT(jumpToObjectDefinitionInEditor(QmlDebug::FileReference,int)));
92 93 94 95

    QmlDebugConnection *connection = m_debugAdapter->connection();
    DeclarativeEngineDebugClient *engineClient1
            = new DeclarativeEngineDebugClient(connection);
96 97 98 99
    connect(engineClient1, SIGNAL(newState(QmlDebug::QmlDebugClient::State)),
            this, SLOT(clientStateChanged(QmlDebug::QmlDebugClient::State)));
    connect(engineClient1, SIGNAL(newState(QmlDebug::QmlDebugClient::State)),
            this, SLOT(engineClientStateChanged(QmlDebug::QmlDebugClient::State)));
100 101

    QmlEngineDebugClient *engineClient2 = new QmlEngineDebugClient(connection);
102 103 104 105
    connect(engineClient2, SIGNAL(newState(QmlDebug::QmlDebugClient::State)),
            this, SLOT(clientStateChanged(QmlDebug::QmlDebugClient::State)));
    connect(engineClient2, SIGNAL(newState(QmlDebug::QmlDebugClient::State)),
            this, SLOT(engineClientStateChanged(QmlDebug::QmlDebugClient::State)));
106

107 108
    DeclarativeEngineDebugClientV2 *engineClient3
            = new DeclarativeEngineDebugClientV2(connection);
109 110 111 112
    connect(engineClient3, SIGNAL(newState(QmlDebug::QmlDebugClient::State)),
            this, SLOT(clientStateChanged(QmlDebug::QmlDebugClient::State)));
    connect(engineClient3, SIGNAL(newState(QmlDebug::QmlDebugClient::State)),
            this, SLOT(engineClientStateChanged(QmlDebug::QmlDebugClient::State)));
113

114 115
    m_engineClients.insert(engineClient1->name(), engineClient1);
    m_engineClients.insert(engineClient2->name(), engineClient2);
116
    m_engineClients.insert(engineClient3->name(), engineClient3);
117

118
    if (engineClient1->state() == QmlDebugClient::Enabled)
119
        setActiveEngineClient(engineClient1);
120
    if (engineClient2->state() == QmlDebugClient::Enabled)
121
        setActiveEngineClient(engineClient2);
122
    if (engineClient3->state() == QmlDebugClient::Enabled)
123
        setActiveEngineClient(engineClient3);
124 125

    DeclarativeToolsClient *toolsClient1 = new DeclarativeToolsClient(connection);
126 127 128 129
    connect(toolsClient1, SIGNAL(newState(QmlDebug::QmlDebugClient::State)),
            this, SLOT(clientStateChanged(QmlDebug::QmlDebugClient::State)));
    connect(toolsClient1, SIGNAL(newState(QmlDebug::QmlDebugClient::State)),
            this, SLOT(toolsClientStateChanged(QmlDebug::QmlDebugClient::State)));
130 131

    QmlToolsClient *toolsClient2 = new QmlToolsClient(connection);
132 133 134 135
    connect(toolsClient2, SIGNAL(newState(QmlDebug::QmlDebugClient::State)),
            this, SLOT(clientStateChanged(QmlDebug::QmlDebugClient::State)));
    connect(toolsClient2, SIGNAL(newState(QmlDebug::QmlDebugClient::State)),
            this, SLOT(toolsClientStateChanged(QmlDebug::QmlDebugClient::State)));
136 137

    // toolbar
138 139
    m_selectAction->setObjectName(QLatin1String("QML Select Action"));
    m_zoomAction->setObjectName(QLatin1String("QML Zoom Action"));
140 141
    m_selectAction->setCheckable(true);
    m_zoomAction->setCheckable(true);
142 143 144 145 146 147
    m_showAppOnTopAction->setCheckable(true);
    m_updateOnSaveAction->setCheckable(true);
    m_selectAction->setEnabled(false);
    m_zoomAction->setEnabled(false);
    m_showAppOnTopAction->setEnabled(false);
    m_updateOnSaveAction->setEnabled(false);
148 149 150 151 152

    connect(m_selectAction, SIGNAL(triggered(bool)),
            SLOT(onSelectActionTriggered(bool)));
    connect(m_zoomAction, SIGNAL(triggered(bool)),
            SLOT(onZoomActionTriggered(bool)));
153 154 155 156
    connect(m_showAppOnTopAction, SIGNAL(triggered(bool)),
            SLOT(onShowAppOnTopChanged(bool)));
    connect(m_updateOnSaveAction, SIGNAL(triggered(bool)),
            SLOT(onUpdateOnSaveChanged(bool)));
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
}

QmlInspectorAdapter::~QmlInspectorAdapter()
{
}

BaseEngineDebugClient *QmlInspectorAdapter::engineClient() const
{
    return m_engineClient;
}

BaseToolsClient *QmlInspectorAdapter::toolsClient() const
{
    return m_toolsClient;
}

QmlInspectorAgent *QmlInspectorAdapter::agent() const
{
    return m_agent;
}

int QmlInspectorAdapter::currentSelectedDebugId() const
{
    return m_currentSelectedDebugId;
}

QString QmlInspectorAdapter::currentSelectedDisplayName() const
{
    return m_currentSelectedDebugName;
}

188
void QmlInspectorAdapter::clientStateChanged(QmlDebugClient::State state)
189 190 191 192 193
{
    QString serviceName;
    float version = 0;
    if (QmlDebugClient *client = qobject_cast<QmlDebugClient*>(sender())) {
        serviceName = client->name();
194
        version = client->remoteVersion();
195 196
    }

197
    m_debugAdapter->logServiceStateChange(serviceName, version, state);
198 199
}

200
void QmlInspectorAdapter::toolsClientStateChanged(QmlDebugClient::State state)
201 202
{
    BaseToolsClient *client = qobject_cast<BaseToolsClient*>(sender());
203
    QTC_ASSERT(client, return);
204
    if (state == QmlDebugClient::Enabled) {
205 206 207 208 209 210
        m_toolsClient = client;

        connect(client, SIGNAL(currentObjectsChanged(QList<int>)),
                SLOT(selectObjectsFromToolsClient(QList<int>)));
        connect(client, SIGNAL(logActivity(QString,QString)),
                m_debugAdapter, SLOT(logServiceActivity(QString,QString)));
211
        connect(client, SIGNAL(reloaded()), SLOT(onReloaded()));
212
        connect(client, SIGNAL(destroyedObject(int)), SLOT(onDestroyedObject(int)));
213 214 215 216

        // register actions here
        // because there can be multiple QmlEngines
        // at the same time (but hopefully one one is connected)
Eike Ziller's avatar
Eike Ziller committed
217
        Core::ActionManager::registerAction(m_selectAction,
218 219
                                            Core::Id(Constants::QML_SELECTTOOL),
                                            m_inspectorToolsContext);
Eike Ziller's avatar
Eike Ziller committed
220
        Core::ActionManager::registerAction(m_zoomAction, Core::Id(Constants::QML_ZOOMTOOL),
221 222 223 224 225 226 227
                                            m_inspectorToolsContext);
        Core::ActionManager::registerAction(m_showAppOnTopAction,
                                            Core::Id(Constants::QML_SHOW_APP_ON_TOP),
                                            m_inspectorToolsContext);
        Core::ActionManager::registerAction(m_updateOnSaveAction,
                                            Core::Id(Constants::QML_UPDATE_ON_SAVE),
                                            m_inspectorToolsContext);
228

229
        Core::ICore::addAdditionalContext(m_inspectorToolsContext);
230

231 232 233
        m_toolsClientConnected = true;
        onEngineStateChanged(m_engine->state());
        if (m_showAppOnTopAction->isChecked())
234 235
            m_toolsClient->showAppOnTop(true);

236
    } else if (m_toolsClientConnected && client == m_toolsClient) {
237 238 239 240 241
        disconnect(client, SIGNAL(currentObjectsChanged(QList<int>)),
                   this, SLOT(selectObjectsFromToolsClient(QList<int>)));
        disconnect(client, SIGNAL(logActivity(QString,QString)),
                   m_debugAdapter, SLOT(logServiceActivity(QString,QString)));

242 243 244 245 246 247
        Core::ActionManager::unregisterAction(m_selectAction, Core::Id(Constants::QML_SELECTTOOL));
        Core::ActionManager::unregisterAction(m_zoomAction, Core::Id(Constants::QML_ZOOMTOOL));
        Core::ActionManager::unregisterAction(m_showAppOnTopAction,
                                              Core::Id(Constants::QML_SHOW_APP_ON_TOP));
        Core::ActionManager::unregisterAction(m_updateOnSaveAction,
                                              Core::Id(Constants::QML_UPDATE_ON_SAVE));
248

249
        Core::ICore::removeAdditionalContext(m_inspectorToolsContext);
250

251
        enableTools(false);
252
        m_toolsClientConnected = false;
253 254 255 256
        m_selectAction->setCheckable(false);
        m_zoomAction->setCheckable(false);
        m_showAppOnTopAction->setCheckable(false);
        m_updateOnSaveAction->setCheckable(false);
257 258 259
    }
}

260
void QmlInspectorAdapter::engineClientStateChanged(QmlDebugClient::State state)
261 262 263
{
    BaseEngineDebugClient *client
            = qobject_cast<BaseEngineDebugClient*>(sender());
264

265
    if (state == QmlDebugClient::Enabled && !m_engineClientConnected) {
266
        // We accept the first client that is enabled and reject the others.
267 268
        QTC_ASSERT(client, return);
        setActiveEngineClient(client);
269
    } else if (m_engineClientConnected && client == m_engineClient) {
270 271 272
        m_engineClientConnected = false;
        deletePreviews();
    }
273 274 275 276 277 278 279
}

void QmlInspectorAdapter::selectObjectsFromToolsClient(const QList<int> &debugIds)
{
    if (debugIds.isEmpty())
        return;

280 281
    m_targetToSync = EditorTarget;
    m_debugIdToSelect = debugIds.first();
282
    selectObject(agent()->objectForId(m_debugIdToSelect), EditorTarget);
283 284
}

Kai Koehne's avatar
Kai Koehne committed
285
void QmlInspectorAdapter::onObjectFetched(const ObjectReference &ref)
286 287 288 289 290 291 292 293 294
{
    if (ref.debugId() == m_debugIdToSelect) {
        m_debugIdToSelect = -1;
        selectObject(ref, m_targetToSync);
    }
}

void QmlInspectorAdapter::createPreviewForEditor(Core::IEditor *newEditor)
{
295 296 297
    if (!m_engineClientConnected)
        return;

298
    if (!newEditor || newEditor->document()->id()
299 300 301
            != QmlJSEditor::Constants::C_QMLJSEDITOR_ID)
        return;

302
    QString filename = newEditor->document()->filePath();
303 304
    QmlJS::ModelManagerInterface *modelManager =
            QmlJS::ModelManagerInterface::instance();
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
    if (modelManager) {
        QmlJS::Document::Ptr doc = modelManager->snapshot().document(filename);
        if (!doc) {
            if (filename.endsWith(QLatin1String(".qml")) || filename.endsWith(QLatin1String(".js"))) {
                // add to list of docs that we have to update when
                // snapshot figures out that there's a new document
                m_pendingPreviewDocumentNames.append(filename);
            }
            return;
        }
        if (!doc->qmlProgram() && !filename.endsWith(QLatin1String(".js")))
            return;

        QmlJS::Document::Ptr initdoc = m_loadedSnapshot.document(filename);
        if (!initdoc)
            initdoc = doc;

        if (m_textPreviews.contains(filename)) {
            QmlLiveTextPreview *preview = m_textPreviews.value(filename);
            preview->associateEditor(newEditor);
        } else {
            QmlLiveTextPreview *preview
                    = new QmlLiveTextPreview(doc, initdoc, this, this);

hjk's avatar
hjk committed
329
            preview->setApplyChangesToQmlInspector(action(QmlUpdateOnSave)->isChecked());
330 331 332
            connect(preview, SIGNAL(reloadRequest()),
                    this, SLOT(onReload()));

333
            m_textPreviews.insert(newEditor->document()->filePath(), preview);
334 335
            preview->associateEditor(newEditor);
            preview->updateDebugIds();
336 337 338 339 340 341 342
        }
    }
}

void QmlInspectorAdapter::removePreviewForEditor(Core::IEditor *editor)
{
    if (QmlLiveTextPreview *preview
343
            = m_textPreviews.value(editor->document()->filePath())) {
344 345 346 347 348 349 350 351 352 353 354 355 356
        preview->unassociateEditor(editor);
    }
}

void QmlInspectorAdapter::updatePendingPreviewDocuments(QmlJS::Document::Ptr doc)
{
    int idx = -1;
    idx = m_pendingPreviewDocumentNames.indexOf(doc->fileName());

    if (idx == -1)
        return;

    QList<Core::IEditor *> editors
hjk's avatar
hjk committed
357
            = Core::DocumentModel::editorsForFilePath(doc->fileName());
358 359 360 361 362 363 364 365 366

    if (editors.isEmpty())
        return;

    m_pendingPreviewDocumentNames.removeAt(idx);

    Core::IEditor *editor = editors.takeFirst();
    createPreviewForEditor(editor);
    QmlLiveTextPreview *preview
367
            = m_textPreviews.value(editor->document()->filePath());
368 369 370 371 372 373
    foreach (Core::IEditor *editor, editors)
        preview->associateEditor(editor);
}

void QmlInspectorAdapter::onSelectActionTriggered(bool checked)
{
374
    QTC_ASSERT(toolsClient(), return);
375 376 377 378 379 380 381 382 383 384 385
    if (checked) {
        toolsClient()->setDesignModeBehavior(true);
        toolsClient()->changeToSelectTool();
        m_zoomAction->setChecked(false);
    } else {
        toolsClient()->setDesignModeBehavior(false);
    }
}

void QmlInspectorAdapter::onZoomActionTriggered(bool checked)
{
386
    QTC_ASSERT(toolsClient(), return);
387 388 389 390 391 392 393 394 395
    if (checked) {
        toolsClient()->setDesignModeBehavior(true);
        toolsClient()->changeToZoomTool();
        m_selectAction->setChecked(false);
    } else {
        toolsClient()->setDesignModeBehavior(false);
    }
}

396
void QmlInspectorAdapter::onShowAppOnTopChanged(bool checked)
397
{
398 399
    QTC_ASSERT(toolsClient(), return);
    toolsClient()->showAppOnTop(checked);
400 401
}

402
void QmlInspectorAdapter::onUpdateOnSaveChanged(bool checked)
403
{
404
    QTC_ASSERT(toolsClient(), return);
405 406 407
    for (QHash<QString, QmlLiveTextPreview *>::const_iterator it
         = m_textPreviews.constBegin();
         it != m_textPreviews.constEnd(); ++it) {
408
        it.value()->setApplyChangesToQmlInspector(checked);
409 410 411 412 413 414 415 416 417 418
    }
}

void QmlInspectorAdapter::setActiveEngineClient(BaseEngineDebugClient *client)
{
    if (m_engineClient == client)
        return;

    m_engineClient = client;
    m_agent->setEngineClient(m_engineClient);
419
    m_engineClientConnected = true;
420 421

    if (m_engineClient &&
422
            m_engineClient->state() == QmlDebugClient::Enabled) {
423 424
        QmlJS::ModelManagerInterface *modelManager
                = QmlJS::ModelManagerInterface::instance();
425 426 427 428 429 430 431 432 433 434
        if (modelManager) {
            QmlJS::Snapshot snapshot = modelManager->snapshot();
            for (QHash<QString, QmlLiveTextPreview *>::const_iterator it
                 = m_textPreviews.constBegin();
                 it != m_textPreviews.constEnd(); ++it) {
                QmlJS::Document::Ptr doc = snapshot.document(it.key());
                it.value()->resetInitialDoc(doc);
            }

            initializePreviews();
435 436 437 438 439 440 441 442
        }
    }
}

void QmlInspectorAdapter::initializePreviews()
{
    QmlJS::ModelManagerInterface *modelManager
            = QmlJS::ModelManagerInterface::instance();
443 444 445 446 447
    if (modelManager) {
        m_loadedSnapshot = modelManager->snapshot();

        if (!m_listeningToEditorManager) {
            m_listeningToEditorManager = true;
448
            QObject *em = Core::EditorManager::instance();
449 450 451 452 453 454 455 456
            connect(em, SIGNAL(editorAboutToClose(Core::IEditor*)),
                    this, SLOT(removePreviewForEditor(Core::IEditor*)));
            connect(em, SIGNAL(editorOpened(Core::IEditor*)),
                    this, SLOT(createPreviewForEditor(Core::IEditor*)));
            connect(modelManager,
                    SIGNAL(documentChangedOnDisk(QmlJS::Document::Ptr)),
                    this, SLOT(updatePendingPreviewDocuments(QmlJS::Document::Ptr)));
        }
457

458
        // initial update
hjk's avatar
hjk committed
459 460
        foreach (Core::IDocument *document, Core::DocumentModel::openedDocuments()) {
            QList<Core::IEditor *> editors = Core::DocumentModel::editorsForDocument(document);
461 462 463 464 465 466
            createPreviewForEditor(editors.takeFirst());
            QmlLiveTextPreview *preview
                    = m_textPreviews.value(document->filePath());
            foreach (Core::IEditor *editor, editors)
                preview->associateEditor(editor);
        }
467
    }
468 469
}

470
void QmlInspectorAdapter::showConnectionStateMessage(const QString &message)
471 472 473 474
{
    m_engine->showMessage(_("QML Inspector: ") + message, LogStatus);
}

475
void QmlInspectorAdapter::jumpToObjectDefinitionInEditor(
Aurindam Jana's avatar
Aurindam Jana committed
476
        const FileReference &objSource, int debugId)
477
{
478
    const QString fileName = m_engine->toFileInProject(objSource.url());
479

Eike Ziller's avatar
Eike Ziller committed
480
    Core::EditorManager::openEditorAt(fileName, objSource.lineNumber());
Aurindam Jana's avatar
Aurindam Jana committed
481 482 483 484
    if (debugId != -1 && debugId != m_currentSelectedDebugId) {
        m_currentSelectedDebugId = debugId;
        m_currentSelectedDebugName = agent()->displayName(debugId);
    }
485 486
}

Kai Koehne's avatar
Kai Koehne committed
487
void QmlInspectorAdapter::selectObject(const ObjectReference &obj,
488 489
                                       SelectionTarget target)
{
490
    if (m_toolsClient && target == ToolTarget)
491
        m_toolsClient->setObjectIdList(
Kai Koehne's avatar
Kai Koehne committed
492
                    QList<ObjectReference>() << obj);
493 494

    if (target == EditorTarget)
495
        jumpToObjectDefinitionInEditor(obj.source());
496

497
    agent()->selectObjectInTree(obj.debugId());
498 499
}

500 501
void QmlInspectorAdapter::deletePreviews()
{
502 503
    qDeleteAll(m_textPreviews);
    m_textPreviews.clear();
504 505
}

506 507 508 509 510 511 512 513 514 515 516 517 518
void QmlInspectorAdapter::enableTools(const bool enable)
{
    if (!m_toolsClientConnected)
        return;
    m_selectAction->setEnabled(enable);
    m_showAppOnTopAction->setEnabled(enable);
    m_updateOnSaveAction->setEnabled(enable);
    // only enable zoom action for Qt 4.x/old client
    // (zooming is integrated into selection tool in Qt 5).
    if (!qobject_cast<QmlToolsClient*>(m_toolsClient))
        m_zoomAction->setEnabled(enable);
}

519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
void QmlInspectorAdapter::onReload()
{
    QHash<QString, QByteArray> changesHash;
    for (QHash<QString, QmlLiveTextPreview *>::const_iterator it
         = m_textPreviews.constBegin();
         it != m_textPreviews.constEnd(); ++it) {
        if (it.value()->hasUnsynchronizableChange()) {
            QFileInfo info = QFileInfo(it.value()->fileName());
            QFile changedFile(it.value()->fileName());
            QByteArray fileContents;
            if (changedFile.open(QFile::ReadOnly))
                fileContents = changedFile.readAll();
            changedFile.close();
            changesHash.insert(info.fileName(),
                               fileContents);
        }
    }
536 537
    if (m_toolsClient)
        m_toolsClient->reload(changesHash);
538 539 540 541 542 543
}

void QmlInspectorAdapter::onReloaded()
{
    QmlJS::ModelManagerInterface *modelManager =
            QmlJS::ModelManagerInterface::instance();
544 545 546 547 548 549 550 551 552
    if (modelManager) {
        QmlJS::Snapshot snapshot = modelManager->snapshot();
        m_loadedSnapshot = snapshot;
        for (QHash<QString, QmlLiveTextPreview *>::const_iterator it
             = m_textPreviews.constBegin();
             it != m_textPreviews.constEnd(); ++it) {
            QmlJS::Document::Ptr doc = snapshot.document(it.key());
            it.value()->resetInitialDoc(doc);
        }
553
    }
554
    m_agent->reloadEngines();
555 556
}

557
void QmlInspectorAdapter::onDestroyedObject(int objectDebugId)
558
{
559
    m_agent->fetchObject(m_agent->parentIdForObject(objectDebugId));
560 561
}

562 563 564 565 566
void QmlInspectorAdapter::onEngineStateChanged(const DebuggerState state)
{
    enableTools(state == InferiorRunOk);
}

567 568
} // namespace Internal
} // namespace Debugger