From 920576bbfe5e1fef889b6ede5d80f93d14466ea4 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Sun, 21 Apr 2013 14:10:21 -0400 Subject: [PATCH] Implement setting visible ranges on containers. - Objects that act as ranged containers now expose a menu option which allows the user to input a comma-separated list of ranges to show. These need not be contiguous, ergo one can show only the first and last elements of an array, or some random set of indices in the middle as well. --- src/apps/debugger/MessageCodes.h | 2 + .../gui/team_window/VariablesView.cpp | 69 +++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/src/apps/debugger/MessageCodes.h b/src/apps/debugger/MessageCodes.h index 610935a959..7eba27d74f 100644 --- a/src/apps/debugger/MessageCodes.h +++ b/src/apps/debugger/MessageCodes.h @@ -56,6 +56,8 @@ enum { MSG_SHOW_TYPECAST_NODE_PROMPT = 'stnp', MSG_TYPECAST_NODE = 'tyno', MSG_SHOW_WATCH_VARIABLE_PROMPT = 'swvp', + MSG_SHOW_CONTAINER_RANGE_PROMPT = 'scrp', + MSG_SET_CONTAINER_RANGE = 'chcr', MSG_GENERATE_DEBUG_REPORT = 'gdrp' }; 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 01ac6f1fd0..0a1c9a1953 100644 --- a/src/apps/debugger/user_interface/gui/team_window/VariablesView.cpp +++ b/src/apps/debugger/user_interface/gui/team_window/VariablesView.cpp @@ -32,6 +32,7 @@ #include "FunctionInstance.h" #include "GuiSettingsUtils.h" #include "MessageCodes.h" +#include "RangeList.h" #include "Register.h" #include "SettingsMenu.h" #include "SourceLanguage.h" @@ -46,6 +47,7 @@ #include "TypeComponentPath.h" #include "TypeHandlerRoster.h" #include "TypeLookupConstraints.h" +#include "UiUtils.h" #include "Value.h" #include "ValueHandler.h" #include "ValueHandlerRoster.h" @@ -1571,6 +1573,65 @@ VariablesView::MessageReceived(BMessage* message) node->SetCastedType(type); break; } + case MSG_SHOW_CONTAINER_RANGE_PROMPT: + { + ModelNode* node = (ModelNode*)fVariableTable + ->SelectionModel()->NodeAt(0); + int32 lowerBound, upperBound; + ValueNode* valueNode = node->NodeChild()->Node(); + if (valueNode->SupportedChildRange(lowerBound, upperBound) != B_OK) + break; + + BMessage* promptMessage = new(std::nothrow) BMessage( + MSG_SET_CONTAINER_RANGE); + if (promptMessage == NULL) + break; + + ObjectDeleter messageDeleter(promptMessage); + promptMessage->AddPointer("node", node); + BString infoText; + infoText.SetToFormat("Allowed range: %" B_PRId32 + "-%" B_PRId32 ".", lowerBound, upperBound); + PromptWindow* promptWindow = new(std::nothrow) PromptWindow( + "Set Range", "Range: ", infoText.String(), BMessenger(this), + promptMessage); + if (promptWindow == NULL) + return; + + messageDeleter.Detach(); + promptWindow->CenterOnScreen(); + promptWindow->Show(); + break; + } + case MSG_SET_CONTAINER_RANGE: + { + ModelNode* node = (ModelNode*)fVariableTable + ->SelectionModel()->NodeAt(0); + int32 lowerBound, upperBound; + ValueNode* valueNode = node->NodeChild()->Node(); + if (valueNode->SupportedChildRange(lowerBound, upperBound) != B_OK) + break; + + BString rangeExpression = message->FindString("text"); + if (rangeExpression.Length() == 0) + break; + + RangeList ranges; + status_t result = UiUtils::ParseRangeExpression( + rangeExpression, lowerBound, upperBound, ranges); + if (result != B_OK) + break; + + valueNode->ClearChildren(); + for (int32 i = 0; i < ranges.CountRanges(); i++) { + const Range* range = ranges.RangeAt(i); + result = valueNode->CreateChildrenInRange( + range->lowerBound, range->upperBound); + if (result != B_OK) + break; + } + break; + } case MSG_SHOW_WATCH_VARIABLE_PROMPT: { ModelNode* node = reinterpret_cast( @@ -1900,6 +1961,14 @@ VariablesView::_GetContextActionsForNode(ModelNode* node, if (result != B_OK) return result; + ValueNode* valueNode = node->NodeChild()->Node(); + if (valueNode != NULL && valueNode->IsRangedContainer()) { + result = _AddContextAction("Set visible range" B_UTF8_ELLIPSIS, + MSG_SHOW_CONTAINER_RANGE_PROMPT, actions, message); + if (result != B_OK) + return result; + } + return B_OK; }