From 473a74f72e6580b2c7cbe5a3e748cb4916a039f6 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Sun, 28 Apr 2013 20:17:08 -0400 Subject: [PATCH] Debugger: Add support for copying variable values. - Implements a simple copy option in the variables context menu that allows one to copy the displayed value to the clipboard. --- .../gui/team_window/VariablesView.cpp | 39 +++++++++++++++++-- .../gui/team_window/VariablesView.h | 3 +- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/apps/debugger/user_interface/gui/team_window/VariablesView.cpp b/src/apps/debugger/user_interface/gui/team_window/VariablesView.cpp index 5d75846ba42..0f62edec9c8 100644 --- a/src/apps/debugger/user_interface/gui/team_window/VariablesView.cpp +++ b/src/apps/debugger/user_interface/gui/team_window/VariablesView.cpp @@ -1,19 +1,18 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. - * Copyright 2011-2013, Rene Gollent, rene@gollent.com. + * Copyright 2011-2014, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ #include "VariablesView.h" -#include - #include #include #include +#include #include #include #include @@ -1822,6 +1821,11 @@ VariablesView::MessageReceived(BMessage* message) fVariableTableModel->NotifyNodeChanged(node); break; } + case B_COPY: + { + _CopyVariableValueToClipboard(); + break; + } default: BGroupView::MessageReceived(message); break; @@ -2084,6 +2088,15 @@ VariablesView::_GetContextActionsForNode(ModelNode* node, if (valueNode == NULL) return B_OK; + if (valueNode->LocationAndValueResolutionState() == B_OK) { + result = _AddContextAction("Copy Value", B_COPY, actions, message); + if (result != B_OK) + return result; + } + + // if the current node isn't itself a ranged container, check if it + // contains a hidden node which is, since in the latter case we + // want to present the range selection as well. if (!valueNode->IsRangedContainer()) { if (node->CountChildren() == 1 && node->ChildAt(0)->IsHidden()) { valueNode = node->ChildAt(0)->NodeChild()->Node(); @@ -2296,6 +2309,26 @@ VariablesView::_ApplyViewStateDescendentNodeInfos(VariablesViewState* viewState, } +void +VariablesView::_CopyVariableValueToClipboard() +{ + ModelNode* node = reinterpret_cast( + fVariableTable->SelectionModel()->NodeAt(0)); + + Value* value = node->GetValue(); + BString valueData; + if (value != NULL && value->ToString(valueData)) { + be_clipboard->Lock(); + be_clipboard->Data()->RemoveData("text/plain"); + be_clipboard->Data()->AddData ("text/plain", + B_MIME_TYPE, valueData.String(), + valueData.Length()); + be_clipboard->Commit(); + be_clipboard->Unlock(); + } +} + + // #pragma mark - Listener diff --git a/src/apps/debugger/user_interface/gui/team_window/VariablesView.h b/src/apps/debugger/user_interface/gui/team_window/VariablesView.h index 9db6c3b53ed..83583f49c05 100644 --- a/src/apps/debugger/user_interface/gui/team_window/VariablesView.h +++ b/src/apps/debugger/user_interface/gui/team_window/VariablesView.h @@ -1,6 +1,6 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. - * Copyright 2012, Rene Gollent, rene@gollent.com. + * Copyright 2012-2014, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ #ifndef VARIABLES_VIEW_H @@ -86,6 +86,7 @@ class VariablesView : public BGroupView, private TreeTableListener { status_t _ApplyViewStateDescendentNodeInfos( VariablesViewState* viewState, void* parent, TreeTablePath& path); + void _CopyVariableValueToClipboard(); private: Thread* fThread;