From e6590ff5988739d89dad652d08ca5b2ae66603af Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Tue, 22 Jun 2010 18:30:18 +0200
Subject: [PATCH] debugger: fix addToWatchWindow

---
 src/plugins/debugger/debuggerengine.cpp | 48 +++++++++++++++---------
 src/plugins/debugger/debuggerengine.h   |  1 +
 src/plugins/debugger/debuggerplugin.cpp | 50 -------------------------
 src/plugins/debugger/debuggerplugin.h   |  4 --
 src/plugins/debugger/debuggerrunner.cpp |  1 -
 5 files changed, 31 insertions(+), 73 deletions(-)

diff --git a/src/plugins/debugger/debuggerengine.cpp b/src/plugins/debugger/debuggerengine.cpp
index 9943b7d9937..51929a406f4 100644
--- a/src/plugins/debugger/debuggerengine.cpp
+++ b/src/plugins/debugger/debuggerengine.cpp
@@ -44,6 +44,7 @@
 #include "stackhandler.h"
 #include "threadshandler.h"
 #include "watchhandler.h"
+#include "watchutils.h"
 
 #include <coreplugin/icore.h>
 #include <coreplugin/editormanager/editormanager.h>
@@ -312,8 +313,7 @@ void DebuggerEngine::handleCommand(int role, const QVariant &value)
             break;
 
         case RequestExecWatchRole:
-            //exec();
-            QTC_ASSERT(false, /* FIXME ABC */);
+            addToWatchWindow();
             break;
 
         case RequestExecExitRole:
@@ -552,22 +552,6 @@ void DebuggerEngine::breakByFunction(const QString &functionName)
     attemptBreakpointSynchronization();
 }
 
-/*
-void DebuggerEngine::loadSessionData()
-{
-    QTC_ASSERT(isSessionEngine(), return);
-    m_breakHandler.loadSessionData();
-    m_watchHandler.loadSessionData();
-}
-
-void DebuggerEngine::saveSessionData()
-{
-    QTC_ASSERT(isSessionEngine(), return);
-    m_breakHandler.saveSessionData();
-    m_watchHandler.saveSessionData();
-}
-*/
-
 void DebuggerEngine::resetLocation()
 {
     d->m_disassemblerViewAgent.resetLocation();
@@ -689,6 +673,34 @@ void DebuggerEngine::executeJumpToLine()
     executeJumpToLine(fileName, lineNumber);
 }
 
+void DebuggerEngine::addToWatchWindow()
+{
+    // Requires a selection, but that's the only case we want anyway.
+    EditorManager *editorManager = EditorManager::instance();
+    if (!editorManager)
+        return;
+    IEditor *editor = editorManager->currentEditor();
+    if (!editor)
+        return;
+    ITextEditor *textEditor = qobject_cast<ITextEditor*>(editor);
+    if (!textEditor)
+        return;
+    QTextCursor tc;
+    QPlainTextEdit *ptEdit = qobject_cast<QPlainTextEdit*>(editor->widget());
+    if (ptEdit)
+        tc = ptEdit->textCursor();
+    QString exp;
+    if (tc.hasSelection()) {
+        exp = tc.selectedText();
+    } else {
+        int line, column;
+        exp = cppExpressionAt(textEditor, tc.position(), &line, &column);
+    }
+
+    if (!exp.isEmpty())
+        watchHandler()->watchExpression(exp);
+}
+
 // Called from RunControl.
 void DebuggerEngine::handleFinished()
 {
diff --git a/src/plugins/debugger/debuggerengine.h b/src/plugins/debugger/debuggerengine.h
index 11c45619d7f..ad717273636 100644
--- a/src/plugins/debugger/debuggerengine.h
+++ b/src/plugins/debugger/debuggerengine.h
@@ -259,6 +259,7 @@ private:
     void executeRunToLine();
     void executeRunToFunction();
     void executeJumpToLine();
+    void addToWatchWindow();
 
     DebuggerEnginePrivate *d;
 };
diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp
index 71d4a552ac0..597d661ff91 100644
--- a/src/plugins/debugger/debuggerplugin.cpp
+++ b/src/plugins/debugger/debuggerplugin.cpp
@@ -51,7 +51,6 @@
 #include "threadswindow.h"
 #include "watchwindow.h"
 
-//#include "sessiondata.h"
 #include "watchutils.h"
 #include "breakhandler.h" 
 #include "stackhandler.h"  // FIXME
@@ -2478,55 +2477,6 @@ void DebuggerPlugin::aboutToShutdown()
     //    d->m_engine->shutdown();
 }
 
-void DebuggerPlugin::addToWatchWindow()
-{
-    using namespace Core;
-    using namespace TextEditor;
-    // Requires a selection, but that's the only case we want anyway.
-    EditorManager *editorManager = EditorManager::instance();
-    if (!editorManager)
-        return;
-    IEditor *editor = editorManager->currentEditor();
-    if (!editor)
-        return;
-    ITextEditor *textEditor = qobject_cast<ITextEditor*>(editor);
-    if (!textEditor)
-        return;
-    QTextCursor tc;
-    QPlainTextEdit *ptEdit = qobject_cast<QPlainTextEdit*>(editor->widget());
-    if (ptEdit)
-        tc = ptEdit->textCursor();
-    QString exp;
-    if (tc.hasSelection()) {
-        exp = tc.selectedText();
-    } else {
-        int line, column;
-        exp = cppExpressionAt(textEditor, tc.position(), &line, &column);
-    }
-
-// FIXME:
-//    if (!exp.isEmpty())
-//        d->m_watchHandler->watchExpression(exp);
-}
-
-void DebuggerPlugin::setBusyCursor(bool busy)
-{
-    d->setBusyCursor(busy);
-}
-
-/*
-void DebuggerPlugin::gotoLocation(const StackFrame &frame, bool setMarker)
-{
-    if (theDebuggerBoolSetting(OperateByInstruction) || !frame.isUsable()) {
-        if (setMarker)
-            d->m_plugin->resetLocation();
-        d->m_disassemblerViewAgent->setFrame(frame);
-    } else {
-        d->m_plugin->gotoLocation(frame.file, frame.line, setMarker);
-    }
-}
-*/
-
 void DebuggerPlugin::showMessage(const QString &msg, int channel, int timeout)
 {
     //qDebug() << "PLUGIN OUTPUT: " << channel << msg;
diff --git a/src/plugins/debugger/debuggerplugin.h b/src/plugins/debugger/debuggerplugin.h
index 8107be8036f..1a502459736 100644
--- a/src/plugins/debugger/debuggerplugin.h
+++ b/src/plugins/debugger/debuggerplugin.h
@@ -105,11 +105,7 @@ public:
 
 public slots:
     void exitDebugger();  // FIXME: remove
-    void setBusyCursor(bool on);
-    void addToWatchWindow(); // FIXME: use
-
     void clearCppCodeModelSnapshot();
-
     void ensureLogVisible();
     void updateWatchersWindow(bool showWatchers, bool showReturn);
 
diff --git a/src/plugins/debugger/debuggerrunner.cpp b/src/plugins/debugger/debuggerrunner.cpp
index e6d7bf36ecf..61afe22be23 100644
--- a/src/plugins/debugger/debuggerrunner.cpp
+++ b/src/plugins/debugger/debuggerrunner.cpp
@@ -462,7 +462,6 @@ void DebuggerRunControl::start()
         .arg(toolChainName(sp.toolChainType)), LogStatus);
     showMessage(DebuggerSettings::instance()->dump(), LogDebug);
 
-    plugin()->setBusyCursor(false);
     engine()->startDebugger(this);
 }
 
-- 
GitLab