From 0821f6fa512f1627b1a777bddc3eae167c1bd6ed Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Fri, 11 Dec 2009 18:19:51 +0100
Subject: [PATCH] debugger: make 'Add to watch' available in the editor context
 menu in debug mode

---
 src/plugins/debugger/debuggeractions.h   |  3 ++-
 src/plugins/debugger/debuggermanager.cpp | 10 ++++++---
 src/plugins/debugger/debuggerplugin.cpp  | 27 ++++++++++++++++--------
 3 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/src/plugins/debugger/debuggeractions.h b/src/plugins/debugger/debuggeractions.h
index c43d7caae41..cfa43c39238 100644
--- a/src/plugins/debugger/debuggeractions.h
+++ b/src/plugins/debugger/debuggeractions.h
@@ -150,7 +150,8 @@ struct DebuggerManagerActions
     QAction *runToFunctionAction;
     QAction *jumpToLineAction;
     QAction *nextAction;
-    QAction *watchAction;
+    QAction *watchAction1; // in the Debug menu
+    QAction *watchAction2; // in the text editor context menu
     QAction *breakAction;
     QAction *sepAction;
     QAction *reverseDirectionAction;
diff --git a/src/plugins/debugger/debuggermanager.cpp b/src/plugins/debugger/debuggermanager.cpp
index b136b2aeeed..ee3e910e65f 100644
--- a/src/plugins/debugger/debuggermanager.cpp
+++ b/src/plugins/debugger/debuggermanager.cpp
@@ -468,7 +468,8 @@ void DebuggerManager::init()
 
     d->m_actions.breakAction = new QAction(tr("Toggle Breakpoint"), this);
 
-    d->m_actions.watchAction = new QAction(tr("Add to Watch Window"), this);
+    d->m_actions.watchAction1 = new QAction(tr("Add to Watch Window"), this);
+    d->m_actions.watchAction2 = new QAction(tr("Add to Watch Window"), this);
 
     d->m_actions.reverseDirectionAction = new QAction(tr("Reverse Direction"), this);
     d->m_actions.reverseDirectionAction->setCheckable(true);
@@ -492,7 +493,9 @@ void DebuggerManager::init()
         this, SLOT(runToFunctionExec()));
     connect(d->m_actions.jumpToLineAction, SIGNAL(triggered()),
         this, SLOT(jumpToLineExec()));
-    connect(d->m_actions.watchAction, SIGNAL(triggered()),
+    connect(d->m_actions.watchAction1, SIGNAL(triggered()),
+        this, SLOT(addToWatchWindow()));
+    connect(d->m_actions.watchAction2, SIGNAL(triggered()),
         this, SLOT(addToWatchWindow()));
     connect(d->m_actions.breakAction, SIGNAL(triggered()),
         this, SLOT(toggleBreakpoint()));
@@ -1669,7 +1672,8 @@ void DebuggerManager::setState(DebuggerState state, bool forced)
     if (stopped)
         QApplication::alert(mainWindow(), 3000);
 
-    d->m_actions.watchAction->setEnabled(true);
+    d->m_actions.watchAction1->setEnabled(true);
+    d->m_actions.watchAction2->setEnabled(true);
     d->m_actions.breakAction->setEnabled(true);
 
     bool interruptIsExit = !running;
diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp
index 02eb6fd8bb8..0d269658bcd 100644
--- a/src/plugins/debugger/debuggerplugin.cpp
+++ b/src/plugins/debugger/debuggerplugin.cpp
@@ -119,7 +119,8 @@ const char * const JUMP_TO_LINE         = "Debugger.JumpToLine";
 const char * const TOGGLE_BREAK         = "Debugger.ToggleBreak";
 const char * const BREAK_BY_FUNCTION    = "Debugger.BreakByFunction";
 const char * const BREAK_AT_MAIN        = "Debugger.BreakAtMain";
-const char * const ADD_TO_WATCH         = "Debugger.AddToWatch";
+const char * const ADD_TO_WATCH1        = "Debugger.AddToWatch1";
+const char * const ADD_TO_WATCH2        = "Debugger.AddToWatch2";
 const char * const OPERATE_BY_INSTRUCTION  = "Debugger.OperateByInstruction";
 
 #ifdef Q_WS_MAC
@@ -801,16 +802,24 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
     cmd = am->registerAction(sep, QLatin1String("Debugger.Sep.Watch"), globalcontext);
     mdebug->addAction(cmd);
 
-    cmd = am->registerAction(actions.watchAction,
-        Constants::ADD_TO_WATCH, cppeditorcontext);
+    cmd = am->registerAction(actions.watchAction1,
+        Constants::ADD_TO_WATCH1, cppeditorcontext);
     cmd->action()->setEnabled(true);
-    cmd->setDefaultKeySequence(QKeySequence(tr("ALT+D,ALT+W")));
+    //cmd->setDefaultKeySequence(QKeySequence(tr("ALT+D,ALT+W")));
     mdebug->addAction(cmd);
-    // QTCREATORBUG-342 asks for that unconditionally
-    //ActionContainer *editorContextMenu =
-    //    am->actionContainer(CppEditor::Constants::M_CONTEXT);
-    //editorContextMenu->addAction(cmd);
-    //cmd->setAttribute(Command::CA_Hide);
+
+    ActionContainer *editorContextMenu =
+        am->actionContainer(CppEditor::Constants::M_CONTEXT);
+    cmd = am->registerAction(sep, QLatin1String("Debugger.Sep.Views"),
+        debuggercontext);
+    editorContextMenu->addAction(cmd);
+    cmd->setAttribute(Command::CA_Hide);
+    cmd = am->registerAction(actions.watchAction2,
+        Constants::ADD_TO_WATCH2, debuggercontext);
+    cmd->action()->setEnabled(true);
+    //cmd->setDefaultKeySequence(QKeySequence(tr("ALT+D,ALT+W")));
+    editorContextMenu->addAction(cmd);
+    cmd->setAttribute(Command::CA_Hide);
 
     // Views menu
     cmd = am->registerAction(sep, QLatin1String("Debugger.Sep.Views"), globalcontext);
-- 
GitLab