From 80180ba714e3945c6e23f2c1eec38c4f2fea3ee9 Mon Sep 17 00:00:00 2001
From: Simjees Abraham <simjees.abraham@nokia.com>
Date: Mon, 4 Jun 2012 17:17:50 +0200
Subject: [PATCH] Debugger: Prompt for reload if set/reset binding fails.

QtCreator takes into account the result of message from
qtdeclarative for setting, resetting and updating the method
body.

Task-number: QTCREATORBUG-3264
Change-Id: I15d1a33990175e86bb3f2fee08f75dd5b7b1b628
Reviewed-by: Christiaan Janssen <christiaan.janssen@nokia.com>
---
 src/libs/qmldebug/baseenginedebugclient.cpp     |  5 ++++-
 src/plugins/debugger/qml/qmlinspectoragent.cpp  |  8 ++++++++
 src/plugins/debugger/qml/qmlinspectoragent.h    |  1 +
 src/plugins/debugger/qml/qmllivetextpreview.cpp | 14 ++++++++++++--
 src/plugins/debugger/qml/qmllivetextpreview.h   |  4 +++-
 5 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/src/libs/qmldebug/baseenginedebugclient.cpp b/src/libs/qmldebug/baseenginedebugclient.cpp
index 9dc51c1084d..512437f8a0f 100644
--- a/src/libs/qmldebug/baseenginedebugclient.cpp
+++ b/src/libs/qmldebug/baseenginedebugclient.cpp
@@ -230,7 +230,10 @@ void BaseEngineDebugClient::messageReceived(const QByteArray &data)
         emit result(queryId, exprResult, type);
     } else if (type == "WATCH_PROPERTY_R" ||
                type == "WATCH_OBJECT_R" ||
-               type == "WATCH_EXPR_OBJECT_R") {
+               type == "WATCH_EXPR_OBJECT_R" ||
+               type == "SET_BINDING_R" ||
+               type == "RESET_BINDING_R" ||
+               type == "SET_METHOD_BODY_R") {
         bool valid;
         ds >> valid;
         emit result(queryId, valid, type);
diff --git a/src/plugins/debugger/qml/qmlinspectoragent.cpp b/src/plugins/debugger/qml/qmlinspectoragent.cpp
index 22a25c7f538..6fbc41cbcfd 100644
--- a/src/plugins/debugger/qml/qmlinspectoragent.cpp
+++ b/src/plugins/debugger/qml/qmlinspectoragent.cpp
@@ -423,6 +423,14 @@ void QmlInspectorAgent::onResult(quint32 queryId, const QVariant &value,
     if (type == _("FETCH_OBJECT_R")) {
         log(LogReceive, _("FETCH_OBJECT_R %1").arg(
                 qvariant_cast<ObjectReference>(value).idString()));
+    } else if (type == _("SET_BINDING_R")
+               || type == _("RESET_BINDING_R")
+               || type == _("SET_METHOD_BODY_R")) {
+        QString msg = QLatin1String(type) + tr(" success : ");
+        msg += value.toBool() ? "1" : "0";
+        if (!value.toBool())
+            emit automaticUpdateFailed();
+        log(LogReceive, msg);
     } else {
         log(LogReceive, QLatin1String(type));
     }
diff --git a/src/plugins/debugger/qml/qmlinspectoragent.h b/src/plugins/debugger/qml/qmlinspectoragent.h
index 4efe5b18949..88a469eadf5 100644
--- a/src/plugins/debugger/qml/qmlinspectoragent.h
+++ b/src/plugins/debugger/qml/qmlinspectoragent.h
@@ -103,6 +103,7 @@ signals:
     void expressionResult(quint32 queryId, const QVariant &value);
     void propertyChanged(int debugId, const QByteArray &propertyName,
                          const QVariant &propertyValue);
+    void automaticUpdateFailed();
 
 private slots:
     void updateStatus();
diff --git a/src/plugins/debugger/qml/qmllivetextpreview.cpp b/src/plugins/debugger/qml/qmllivetextpreview.cpp
index cb5c78f3af1..ee7ade0c953 100644
--- a/src/plugins/debugger/qml/qmllivetextpreview.cpp
+++ b/src/plugins/debugger/qml/qmllivetextpreview.cpp
@@ -376,6 +376,8 @@ QmlLiveTextPreview::QmlLiveTextPreview(const QmlJS::Document::Ptr &doc,
             SIGNAL(fetchObjectsForLocation(QString,int,int)),
             m_inspectorAdapter->agent(),
             SLOT(fetchContextObjectsForLocation(QString,int,int)));
+    connect(m_inspectorAdapter->agent(), SIGNAL(automaticUpdateFailed()),
+            SLOT(onAutomaticUpdateFailed()));
 }
 
 void QmlLiveTextPreview::associateEditor(Core::IEditor *editor)
@@ -598,7 +600,6 @@ void QmlLiveTextPreview::documentChanged(QmlJS::Document::Ptr doc)
 
         if (doc && m_previousDoc && doc->fileName() == m_previousDoc->fileName()) {
             if (doc->fileName().endsWith(".js")) {
-                m_changesUnsynchronizable = true;
                 showSyncWarning(JSChangeWarning, QString(), 0, 0);
                 m_previousDoc = doc;
                 return;
@@ -612,7 +613,6 @@ void QmlLiveTextPreview::documentChanged(QmlJS::Document::Ptr doc)
 
 
                 if (delta.unsyncronizableChanges != NoUnsyncronizableChanges) {
-                    m_changesUnsynchronizable = true;
                     showSyncWarning(delta.unsyncronizableChanges,
                                     delta.unsyncronizableElementName,
                                     delta.unsyncronizableChangeLine,
@@ -638,6 +638,11 @@ void QmlLiveTextPreview::editorContentsChanged()
     m_contentsChanged = true;
 }
 
+void QmlLiveTextPreview::onAutomaticUpdateFailed()
+{
+    showSyncWarning(AutomaticUpdateFailed, QString(), -1, -1);
+}
+
 QList<int> QmlLiveTextPreview::objectReferencesForOffset(quint32 offset)
 {
     QList<int> result;
@@ -688,11 +693,16 @@ void QmlLiveTextPreview::showSyncWarning(
         errorMessage = tr("The changes in JavaScript cannot be applied "
                           "without reloading the QML application. ");
         break;
+    case AutomaticUpdateFailed:
+        errorMessage = tr("The changes made cannot be applied without "
+                          "reloading the QML application. ");
+        break;
     case QmlLiveTextPreview::NoUnsyncronizableChanges:
     default:
         return;
     }
 
+    m_changesUnsynchronizable = true;
     errorMessage.append(tr("You can continue debugging, but behavior can be unexpected."));
 
     // Clear infobars if present before showing the same. Otherwise multiple infobars
diff --git a/src/plugins/debugger/qml/qmllivetextpreview.h b/src/plugins/debugger/qml/qmllivetextpreview.h
index 7a6c052bb92..3353afcccd8 100644
--- a/src/plugins/debugger/qml/qmllivetextpreview.h
+++ b/src/plugins/debugger/qml/qmllivetextpreview.h
@@ -84,13 +84,15 @@ private slots:
                                 const QString &wordAtCursor);
     void documentChanged(QmlJS::Document::Ptr doc);
     void editorContentsChanged();
+    void onAutomaticUpdateFailed();
 
 private:
     enum UnsyncronizableChangeType {
         NoUnsyncronizableChanges,
         AttributeChangeWarning,
         ElementChangeWarning,
-        JSChangeWarning
+        JSChangeWarning,
+        AutomaticUpdateFailed
     };
 
     bool changeSelectedElements(const QList<int> offsets, const QString &wordAtCursor);
-- 
GitLab