qmlinspectoradapter.cpp 21 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
hjk's avatar
hjk committed
3 4
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** 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 13 14
** 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
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29 30 31 32 33 34 35

#include "qmlinspectoradapter.h"

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

#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/icore.h>
#include <qmldebug/declarativeenginedebugclient.h>
44
#include <qmldebug/declarativeenginedebugclientv2.h>
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#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>

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,
62
                                         DebuggerEngine *engine,
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
                                         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))
78 79
    , m_showAppOnTopAction(debuggerCore()->action(ShowAppOnTop))
    , m_updateOnSaveAction(debuggerCore()->action(QmlUpdateOnSave))
80
    , m_engineClientConnected(false)
81
{
82 83 84 85
    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
86 87
    connect(m_agent, SIGNAL(objectFetched(QmlDebug::ObjectReference)),
            SLOT(onObjectFetched(QmlDebug::ObjectReference)));
Aurindam Jana's avatar
Aurindam Jana committed
88 89
    connect(m_agent, SIGNAL(jumpToObjectDefinition(QmlDebug::FileReference,int)),
            SLOT(jumpToObjectDefinitionInEditor(QmlDebug::FileReference,int)));
90 91 92 93

    QmlDebugConnection *connection = m_debugAdapter->connection();
    DeclarativeEngineDebugClient *engineClient1
            = new DeclarativeEngineDebugClient(connection);
Kai Koehne's avatar
Kai Koehne committed
94 95 96 97
    connect(engineClient1, SIGNAL(newStatus(QmlDebug::ClientStatus)),
            this, SLOT(clientStatusChanged(QmlDebug::ClientStatus)));
    connect(engineClient1, SIGNAL(newStatus(QmlDebug::ClientStatus)),
            this, SLOT(engineClientStatusChanged(QmlDebug::ClientStatus)));
98 99

    QmlEngineDebugClient *engineClient2 = new QmlEngineDebugClient(connection);
Kai Koehne's avatar
Kai Koehne committed
100 101 102 103
    connect(engineClient2, SIGNAL(newStatus(QmlDebug::ClientStatus)),
            this, SLOT(clientStatusChanged(QmlDebug::ClientStatus)));
    connect(engineClient2, SIGNAL(newStatus(QmlDebug::ClientStatus)),
            this, SLOT(engineClientStatusChanged(QmlDebug::ClientStatus)));
104

105 106 107 108 109 110 111
    DeclarativeEngineDebugClientV2 *engineClient3
            = new DeclarativeEngineDebugClientV2(connection);
    connect(engineClient3, SIGNAL(newStatus(QmlDebug::ClientStatus)),
            this, SLOT(clientStatusChanged(QmlDebug::ClientStatus)));
    connect(engineClient3, SIGNAL(newStatus(QmlDebug::ClientStatus)),
            this, SLOT(engineClientStatusChanged(QmlDebug::ClientStatus)));

112 113
    m_engineClients.insert(engineClient1->name(), engineClient1);
    m_engineClients.insert(engineClient2->name(), engineClient2);
114
    m_engineClients.insert(engineClient3->name(), engineClient3);
115

Kai Koehne's avatar
Kai Koehne committed
116
    if (engineClient1->status() == QmlDebug::Enabled)
117
        setActiveEngineClient(engineClient1);
Kai Koehne's avatar
Kai Koehne committed
118
    if (engineClient2->status() == QmlDebug::Enabled)
119
        setActiveEngineClient(engineClient2);
120 121
    if (engineClient3->status() == QmlDebug::Enabled)
        setActiveEngineClient(engineClient3);
122 123

    DeclarativeToolsClient *toolsClient1 = new DeclarativeToolsClient(connection);
Kai Koehne's avatar
Kai Koehne committed
124
    connect(toolsClient1, SIGNAL(newStatus(QmlDebug::ClientStatus)),
Kai Koehne's avatar
Kai Koehne committed
125
            this, SLOT(clientStatusChanged(QmlDebug::ClientStatus)));
Kai Koehne's avatar
Kai Koehne committed
126
    connect(toolsClient1, SIGNAL(newStatus(QmlDebug::ClientStatus)),
Kai Koehne's avatar
Kai Koehne committed
127
            this, SLOT(toolsClientStatusChanged(QmlDebug::ClientStatus)));
128 129

    QmlToolsClient *toolsClient2 = new QmlToolsClient(connection);
Kai Koehne's avatar
Kai Koehne committed
130
    connect(toolsClient2, SIGNAL(newStatus(QmlDebug::ClientStatus)),
Kai Koehne's avatar
Kai Koehne committed
131
            this, SLOT(clientStatusChanged(QmlDebug::ClientStatus)));
Kai Koehne's avatar
Kai Koehne committed
132
    connect(toolsClient2, SIGNAL(newStatus(QmlDebug::ClientStatus)),
Kai Koehne's avatar
Kai Koehne committed
133
            this, SLOT(toolsClientStatusChanged(QmlDebug::ClientStatus)));
134 135

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

    connect(m_selectAction, SIGNAL(triggered(bool)),
            SLOT(onSelectActionTriggered(bool)));
    connect(m_zoomAction, SIGNAL(triggered(bool)),
            SLOT(onZoomActionTriggered(bool)));
151 152 153 154
    connect(m_showAppOnTopAction, SIGNAL(triggered(bool)),
            SLOT(onShowAppOnTopChanged(bool)));
    connect(m_updateOnSaveAction, SIGNAL(triggered(bool)),
            SLOT(onUpdateOnSaveChanged(bool)));
155 156 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
}

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;
}

Kai Koehne's avatar
Kai Koehne committed
186
void QmlInspectorAdapter::clientStatusChanged(QmlDebug::ClientStatus status)
187 188 189 190 191 192 193 194 195 196 197
{
    QString serviceName;
    float version = 0;
    if (QmlDebugClient *client = qobject_cast<QmlDebugClient*>(sender())) {
        serviceName = client->name();
        version = client->serviceVersion();
    }

    m_debugAdapter->logServiceStatusChange(serviceName, version, status);
}

Kai Koehne's avatar
Kai Koehne committed
198
void QmlInspectorAdapter::toolsClientStatusChanged(QmlDebug::ClientStatus status)
199 200
{
    BaseToolsClient *client = qobject_cast<BaseToolsClient*>(sender());
201
    QTC_ASSERT(client, return);
Kai Koehne's avatar
Kai Koehne committed
202
    if (status == QmlDebug::Enabled) {
203 204 205 206 207 208
        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)));
209
        connect(client, SIGNAL(reloaded()), SLOT(onReloaded()));
210
        connect(client, SIGNAL(destroyedObject(int)), SLOT(onDestroyedObject(int)));
211 212 213 214

        // 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
215
        Core::ActionManager::registerAction(m_selectAction,
216 217
                                            Core::Id(Constants::QML_SELECTTOOL),
                                            m_inspectorToolsContext);
Eike Ziller's avatar
Eike Ziller committed
218
        Core::ActionManager::registerAction(m_zoomAction, Core::Id(Constants::QML_ZOOMTOOL),
219 220 221 222 223 224 225
                                            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);
226

227
        Core::ICore::updateAdditionalContexts(Core::Context(), m_inspectorToolsContext);
228

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

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

240 241 242 243 244 245
        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));
246

247
        Core::ICore::updateAdditionalContexts(m_inspectorToolsContext, Core::Context());
248

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

Kai Koehne's avatar
Kai Koehne committed
258
void QmlInspectorAdapter::engineClientStatusChanged(QmlDebug::ClientStatus status)
259 260 261
{
    BaseEngineDebugClient *client
            = qobject_cast<BaseEngineDebugClient*>(sender());
262

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

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

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

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

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

296
    if (!newEditor || newEditor->id()
297 298 299 300 301 302 303 304
            != QmlJSEditor::Constants::C_QMLJSEDITOR_ID)
        return;

    QString filename = newEditor->document()->fileName();
    QmlJS::ModelManagerInterface *modelManager =
            QmlJS::ModelManagerInterface::instance();
    QmlJS::Document::Ptr doc = modelManager->snapshot().document(filename);
    if (!doc) {
305
        if (filename.endsWith(QLatin1String(".qml")) || filename.endsWith(QLatin1String(".js"))) {
306 307 308 309 310 311
            // 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;
    }
312
    if (!doc->qmlProgram() && !filename.endsWith(QLatin1String(".js")))
313 314 315 316 317 318 319 320 321 322 323 324
        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);
325

326 327
        preview->setApplyChangesToQmlInspector(
                    debuggerCore()->action(QmlUpdateOnSave)->isChecked());
328 329
        connect(preview, SIGNAL(reloadRequest()),
                this, SLOT(onReload()));
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369

        m_textPreviews.insert(newEditor->document()->fileName(), preview);
        preview->associateEditor(newEditor);
        preview->updateDebugIds();
    }
}

void QmlInspectorAdapter::removePreviewForEditor(Core::IEditor *editor)
{
    if (QmlLiveTextPreview *preview
            = m_textPreviews.value(editor->document()->fileName())) {
        preview->unassociateEditor(editor);
    }
}

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

    if (idx == -1)
        return;

    Core::EditorManager *em = Core::EditorManager::instance();
    QList<Core::IEditor *> editors
            = em->editorsForFileName(doc->fileName());

    if (editors.isEmpty())
        return;

    m_pendingPreviewDocumentNames.removeAt(idx);

    Core::IEditor *editor = editors.takeFirst();
    createPreviewForEditor(editor);
    QmlLiveTextPreview *preview
            = m_textPreviews.value(editor->document()->fileName());
    foreach (Core::IEditor *editor, editors)
        preview->associateEditor(editor);
}

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

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

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

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

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

    m_engineClient = client;
    m_agent->setEngineClient(m_engineClient);
417
    m_engineClientConnected = true;
418 419

    if (m_engineClient &&
Kai Koehne's avatar
Kai Koehne committed
420
            m_engineClient->status() == QmlDebug::Enabled) {
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
        QmlJS::ModelManagerInterface *modelManager
                = QmlJS::ModelManagerInterface::instance();
        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();
    }
}

void QmlInspectorAdapter::initializePreviews()
{
    Core::EditorManager *em = Core::EditorManager::instance();
    QmlJS::ModelManagerInterface *modelManager
            = QmlJS::ModelManagerInterface::instance();
    m_loadedSnapshot = modelManager->snapshot();

    if (!m_listeningToEditorManager) {
        m_listeningToEditorManager = true;
        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)));
    }

    // initial update
    foreach (Core::IEditor *editor, em->openedEditors())
        createPreviewForEditor(editor);
}

void QmlInspectorAdapter::showConnectionStatusMessage(const QString &message)
{
    m_engine->showMessage(_("QML Inspector: ") + message, LogStatus);
}

463
void QmlInspectorAdapter::jumpToObjectDefinitionInEditor(
Aurindam Jana's avatar
Aurindam Jana committed
464
        const FileReference &objSource, int debugId)
465
{
466
    const QString fileName = m_engine->toFileInProject(objSource.url());
467 468 469 470 471 472 473

    Core::EditorManager *editorManager = Core::EditorManager::instance();
    Core::IEditor *editor = editorManager->openEditor(fileName);
    TextEditor::ITextEditor *textEditor
            = qobject_cast<TextEditor::ITextEditor*>(editor);

    if (textEditor) {
474 475 476
        editorManager->addCurrentPositionToNavigationHistory();
        textEditor->gotoLine(objSource.lineNumber());
        textEditor->widget()->setFocus();
477
    }
Aurindam Jana's avatar
Aurindam Jana committed
478 479 480 481 482 483

    if (debugId != -1 && debugId != m_currentSelectedDebugId) {
        m_currentSelectedDebugId = debugId;
        m_currentSelectedDebugName = agent()->displayName(debugId);
        emit selectionChanged();
    }
484 485
}

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

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

496 497
    if (!agent()->selectObjectInTree(obj.debugId()))
        return;
498 499

    m_currentSelectedDebugId = obj.debugId();
500
    m_currentSelectedDebugName = agent()->displayName(obj.debugId());
501 502 503
    emit selectionChanged();
}

504 505 506 507 508 509
void QmlInspectorAdapter::deletePreviews()
{
    foreach (const QString &key, m_textPreviews.keys())
        delete m_textPreviews.take(key);
}

510 511 512 513 514 515 516 517 518 519 520 521 522
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);
}

523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
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);
        }
    }
540 541
    if (m_toolsClient)
        m_toolsClient->reload(changesHash);
542 543 544 545 546 547 548 549 550 551 552 553 554 555
}

void QmlInspectorAdapter::onReloaded()
{
    QmlJS::ModelManagerInterface *modelManager =
            QmlJS::ModelManagerInterface::instance();
    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);
    }
556
    m_agent->reloadEngines();
557 558
}

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

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

569 570
} // namespace Internal
} // namespace Debugger