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.
This commit is contained in:
Rene Gollent 2013-04-21 14:10:21 -04:00
parent 7969833f35
commit 920576bbfe
2 changed files with 71 additions and 0 deletions

View File

@ -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'
};

View File

@ -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<BMessage> 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<ModelNode*>(
@ -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;
}