diff --git a/src/plugins/qmljsinspector/qmljsinspector.cpp b/src/plugins/qmljsinspector/qmljsinspector.cpp index 0201deaddfde9121204e3923ea13bc5af538a0c5..5e0ca38bd2e80610c8545824daf0f70af0e5e871 100644 --- a/src/plugins/qmljsinspector/qmljsinspector.cpp +++ b/src/plugins/qmljsinspector/qmljsinspector.cpp @@ -124,7 +124,8 @@ Inspector::Inspector(QObject *parent) m_connectionAttempts(0), m_cppDebuggerState(0), m_simultaneousCppAndQmlDebugMode(false), - m_debugMode(StandaloneMode) + m_debugMode(StandaloneMode), + m_listeningToEditorManager(false) { m_clientProxy = ClientProxy::instance(); @@ -160,11 +161,10 @@ void Inspector::disconnectWidgets() void Inspector::disconnected() { - Core::EditorManager *em = Core::EditorManager::instance(); - disconnect(em, SIGNAL(editorAboutToClose(Core::IEditor*)), this, SLOT(removePreviewForEditor(Core::IEditor*))); - disconnect(em, SIGNAL(editorOpened(Core::IEditor*)), this, SLOT(createPreviewForEditor(Core::IEditor*))); resetViews(); updateMenuActions(); + + applyChangesToQmlObserverHelper(false); } void Inspector::aboutToReloadEngines() @@ -227,15 +227,21 @@ void Inspector::initializeDocuments() if (!modelManager()) return; - m_loadedSnapshot = modelManager()->snapshot(); Core::EditorManager *em = Core::EditorManager::instance(); - connect(em, SIGNAL(editorAboutToClose(Core::IEditor*)), SLOT(removePreviewForEditor(Core::IEditor*))); - connect(em, SIGNAL(editorOpened(Core::IEditor*)), SLOT(createPreviewForEditor(Core::IEditor*))); + m_loadedSnapshot = modelManager()->snapshot(); + + if (!m_listeningToEditorManager) { + m_listeningToEditorManager = true; + connect(em, SIGNAL(editorAboutToClose(Core::IEditor*)), SLOT(removePreviewForEditor(Core::IEditor*))); + connect(em, SIGNAL(editorOpened(Core::IEditor*)), SLOT(createPreviewForEditor(Core::IEditor*))); + } // initial update foreach (Core::IEditor *editor, em->openedEditors()) { createPreviewForEditor(editor); } + + applyChangesToQmlObserverHelper(true); } void Inspector::serverReloaded() @@ -261,7 +267,9 @@ void Inspector::removePreviewForEditor(Core::IEditor *oldEditor) void Inspector::createPreviewForEditor(Core::IEditor *newEditor) { - if (newEditor && newEditor->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID) { + if (newEditor && newEditor->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID + && m_clientProxy->isConnected()) + { QString filename = newEditor->file()->fileName(); QmlJS::Document::Ptr doc = modelManager()->snapshot().document(filename); if (!doc || !doc->qmlProgram()) @@ -643,16 +651,6 @@ bool Inspector::addQuotesForData(const QVariant &value) const return false; } -void Inspector::setApplyChangesToQmlObserver(bool applyChanges) -{ - emit livePreviewActivated(applyChanges); - QHashIterator<QString, QmlJSLiveTextPreview *> iter(m_textPreviews); - while(iter.hasNext()) { - iter.next(); - iter.value()->setApplyChangesToQmlObserver(applyChanges); - } -} - bool Inspector::showExperimentalWarning() { return m_showExperimentalWarning; @@ -663,6 +661,21 @@ void Inspector::setShowExperimentalWarning(bool value) m_showExperimentalWarning = value; } +void Inspector::setApplyChangesToQmlObserver(bool applyChanges) +{ + emit livePreviewActivated(applyChanges); + applyChangesToQmlObserverHelper(applyChanges); +} + +void Inspector::applyChangesToQmlObserverHelper(bool applyChanges) +{ + QHashIterator<QString, QmlJSLiveTextPreview *> iter(m_textPreviews); + while(iter.hasNext()) { + iter.next(); + iter.value()->setApplyChangesToQmlObserver(applyChanges); + } +} + void Inspector::disableLivePreview() { setApplyChangesToQmlObserver(false); diff --git a/src/plugins/qmljsinspector/qmljsinspector.h b/src/plugins/qmljsinspector/qmljsinspector.h index fb83678b3cf2cdd4f95cdc06c1af85200763b264..971aa6fb1a05fced69e2abdd6d4330cdfc9cfe64 100644 --- a/src/plugins/qmljsinspector/qmljsinspector.h +++ b/src/plugins/qmljsinspector/qmljsinspector.h @@ -147,6 +147,7 @@ private: QmlJS::ModelManagerInterface *modelManager(); void initializeDocuments(); + void applyChangesToQmlObserverHelper(bool applyChanges); private: QWeakPointer<QDeclarativeEngineDebug> m_client; @@ -161,6 +162,7 @@ private: ClientProxy *m_clientProxy; static bool m_showExperimentalWarning; + bool m_listeningToEditorManager; // Qml/JS integration QHash<QString, QmlJSLiveTextPreview *> m_textPreviews;