From 1d3606f4b95b34aed5012960576b36e830bb10f5 Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Wed, 8 Sep 2010 09:09:09 +0200
Subject: [PATCH] debugger: provide a method to copy Locals&Watchers contents
 into a main editor.

Task-number: QTCREATORBUG-982
---
 src/plugins/debugger/debuggerconstants.h |  1 +
 src/plugins/debugger/watchhandler.cpp    | 26 ++++++++++++++++++++++++
 src/plugins/debugger/watchhandler.h      |  2 ++
 src/plugins/debugger/watchwindow.cpp     |  6 ++++++
 4 files changed, 35 insertions(+)

diff --git a/src/plugins/debugger/debuggerconstants.h b/src/plugins/debugger/debuggerconstants.h
index df443e9b83c..e9029f5bb82 100644
--- a/src/plugins/debugger/debuggerconstants.h
+++ b/src/plugins/debugger/debuggerconstants.h
@@ -232,6 +232,7 @@ enum ModelRoles
     LocalsPointerValueRole, // Pointer value (address) as quint64
     LocalsIsWatchpointAtAddressRole,
     LocalsIsWatchpointAtPointerValueRole,
+    RequestShowInEditorRole,
     RequestWatchPointRole,
     RequestToggleWatchRole,
     RequestToolTipByExpressionRole,
diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp
index b913fd3ff91..9a062a420a1 100644
--- a/src/plugins/debugger/watchhandler.cpp
+++ b/src/plugins/debugger/watchhandler.cpp
@@ -743,6 +743,11 @@ bool WatchModel::setData(const QModelIndex &index, const QVariant &value, int ro
             return true;
         }
 
+        case RequestShowInEditorRole: {
+            m_handler->showInEditor();
+            return true;
+        }
+
         case RequestToggleWatchRole: {
             BreakHandler *handler = engine()->breakHandler();
             const quint64 address = value.toULongLong();
@@ -1616,5 +1621,26 @@ void WatchHandler::addTypeFormats(const QByteArray &type, const QStringList &for
     m_reportedTypeFormats.insert(type, formats);
 }
 
+void WatchHandler::showInEditor()
+{
+    QString contents;
+    showInEditorHelper(&contents, m_locals->m_root, 0);
+    showInEditorHelper(&contents, m_watchers->m_root, 0);
+    plugin()->openTextEditor(tr("Locals & Watchers"), contents);
+}
+
+void WatchHandler::showInEditorHelper(QString *contents, WatchItem *item, int depth)
+{
+    const QChar tab = QLatin1Char('\t');
+    const QChar nl = QLatin1Char('\n');
+    contents->append(QString(depth, tab));
+    contents->append(item->name);
+    contents->append(tab);
+    contents->append(item->value);
+    contents->append(nl);
+    foreach (WatchItem *child, item->children)
+       showInEditorHelper(contents, child, depth + 1);
+}
+
 } // namespace Internal
 } // namespace Debugger
diff --git a/src/plugins/debugger/watchhandler.h b/src/plugins/debugger/watchhandler.h
index cada7520f31..6ee27029c1a 100644
--- a/src/plugins/debugger/watchhandler.h
+++ b/src/plugins/debugger/watchhandler.h
@@ -187,6 +187,8 @@ private:
     void saveTypeFormats();
     void setFormat(const QByteArray &type, int format);
     void updateWatchersWindow();
+    void showInEditor();
+    void showInEditorHelper(QString *contents, WatchItem *item, int level);
 
     bool m_inChange;
 
diff --git a/src/plugins/debugger/watchwindow.cpp b/src/plugins/debugger/watchwindow.cpp
index af3bf110a6d..059084bbca9 100644
--- a/src/plugins/debugger/watchwindow.cpp
+++ b/src/plugins/debugger/watchwindow.cpp
@@ -383,6 +383,10 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
     actClearCodeModelSnapshot->setEnabled(actionsEnabled
         && theDebuggerAction(UseCodeModel)->isChecked());
     menu.addAction(actClearCodeModelSnapshot);
+    QAction *actShowInEditor
+        = new QAction(tr("Show View Contents in Editor"), &menu);
+    actShowInEditor->setEnabled(actionsEnabled);
+    menu.addAction(actShowInEditor);
     menu.addSeparator();
     menu.addAction(theDebuggerAction(UseToolTipsInLocalsView));
 
@@ -435,6 +439,8 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
         setModelData(LocalsTypeFormatRole, -1, mi1);
     } else if (act == clearIndividualFormatAction) {
         setModelData(LocalsIndividualFormatRole, -1, mi1);
+    } else if (act == actShowInEditor) {
+        setModelData(RequestShowInEditorRole);
     } else {
         for (int i = 0; i != typeFormatActions.size(); ++i) {
             if (act == typeFormatActions.at(i))
-- 
GitLab