Remember any applied typecasts in VariableViewState.

Preserves and restores typecasts across steps like we already do
for node expansion states.
This commit is contained in:
Rene Gollent
2013-04-15 23:17:27 -04:00
parent 3f7664ad1c
commit 41cec3e6d4
3 changed files with 75 additions and 6 deletions
@@ -1,4 +1,5 @@
/*
* Copyright 2013, Rene Gollent, [email protected].
* Copyright 2009, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License.
*/
@@ -10,6 +11,7 @@
#include "FunctionID.h"
#include "StackFrameValues.h"
#include "Type.h"
#include "TypeComponentPath.h"
@@ -18,15 +20,26 @@
VariablesViewNodeInfo::VariablesViewNodeInfo()
:
fNodeExpanded(false)
fNodeExpanded(false),
fCastedType(NULL)
{
}
VariablesViewNodeInfo::VariablesViewNodeInfo(const VariablesViewNodeInfo& other)
:
fNodeExpanded(other.fNodeExpanded)
fNodeExpanded(other.fNodeExpanded),
fCastedType(other.fCastedType)
{
if (fCastedType != NULL)
fCastedType->AcquireReference();
}
VariablesViewNodeInfo::~VariablesViewNodeInfo()
{
if (fCastedType != NULL)
fCastedType->ReleaseReference();
}
@@ -34,6 +47,8 @@ VariablesViewNodeInfo&
VariablesViewNodeInfo::operator=(const VariablesViewNodeInfo& other)
{
fNodeExpanded = other.fNodeExpanded;
SetCastedType(other.fCastedType);
return *this;
}
@@ -45,6 +60,18 @@ VariablesViewNodeInfo::SetNodeExpanded(bool expanded)
}
void
VariablesViewNodeInfo::SetCastedType(Type* type)
{
if (fCastedType != NULL)
fCastedType->ReleaseReference();
fCastedType = type;
if (fCastedType != NULL)
fCastedType->AcquireReference();
}
// #pragma mark - Key
@@ -1,4 +1,5 @@
/*
* Copyright 2013, Rene Gollent, [email protected].
* Copyright 2009, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License.
*/
@@ -12,6 +13,7 @@
class ObjectID;
class StackFrameValues;
class Type;
class TypeComponentPath;
@@ -20,6 +22,7 @@ public:
VariablesViewNodeInfo();
VariablesViewNodeInfo(
const VariablesViewNodeInfo& other);
virtual ~VariablesViewNodeInfo();
VariablesViewNodeInfo& operator=(
const VariablesViewNodeInfo& other);
@@ -28,8 +31,13 @@ public:
{ return fNodeExpanded; }
void SetNodeExpanded(bool expanded);
Type* GetCastedType() const
{ return fCastedType; }
void SetCastedType(Type* type);
private:
bool fNodeExpanded;
Type* fCastedType;
};
@@ -1,6 +1,6 @@
/*
* Copyright 2009, Ingo Weinhold, [email protected].
* Copyright 2011-2012, Rene Gollent, [email protected].
* Copyright 2011-2013, Rene Gollent, [email protected].
* Distributed under the terms of the MIT License.
*/
@@ -111,7 +111,8 @@ public:
fTableCellRenderer(NULL),
fComponentPath(NULL),
fIsPresentationNode(isPresentationNode),
fHidden(false)
fHidden(false),
fCastedType(NULL)
{
fNodeChild->AcquireReference();
}
@@ -129,6 +130,9 @@ public:
if (fComponentPath != NULL)
fComponentPath->ReleaseReference();
if (fCastedType != NULL)
fCastedType->ReleaseReference();
}
status_t Init()
@@ -195,6 +199,21 @@ public:
fValue->AcquireReference();
}
Type* GetCastedType() const
{
return fCastedType;
}
void SetCastedType(Type* type)
{
if (fCastedType != NULL)
fCastedType->ReleaseReference();
fCastedType = type;
if (type != NULL)
fCastedType->AcquireReference();
}
TypeComponentPath* GetPath() const
{
return fComponentPath;
@@ -309,6 +328,7 @@ private:
TypeComponentPath* fComponentPath;
bool fIsPresentationNode;
bool fHidden;
Type* fCastedType;
public:
ModelNode* fNext;
@@ -1509,9 +1529,8 @@ VariablesView::MessageReceived(BMessage* message)
break;
}
// TODO: we need to also persist/restore the casted state
// in VariableViewState
node->NodeChild()->SetNode(valueNode);
node->SetCastedType(type);
break;
}
case MSG_SHOW_WATCH_VARIABLE_PROMPT:
@@ -1967,6 +1986,7 @@ VariablesView::_AddViewStateDescendentNodeInfos(VariablesViewState* viewState,
// add the node's info
VariablesViewNodeInfo nodeInfo;
nodeInfo.SetNodeExpanded(fVariableTable->IsNodeExpanded(path));
nodeInfo.SetCastedType(node->GetCastedType());
status_t error = viewState->SetNodeInfo(node->GetVariable()->ID(),
node->GetPath(), nodeInfo);
@@ -1999,6 +2019,20 @@ VariablesView::_ApplyViewStateDescendentNodeInfos(VariablesViewState* viewState,
const VariablesViewNodeInfo* nodeInfo = viewState->GetNodeInfo(
node->GetVariable()->ID(), node->GetPath());
if (nodeInfo != NULL) {
// NB: if the node info indicates that the node in question
// was being cast to a different type, this *must* be applied
// before any other view state restoration, since it potentially
// changes the child hierarchy under that node.
Type* type = nodeInfo->GetCastedType();
if (type != NULL) {
ValueNode* valueNode = NULL;
if (TypeHandlerRoster::Default()->CreateValueNode(
node->NodeChild(), type, valueNode) == B_OK) {
node->NodeChild()->SetNode(valueNode);
node->SetCastedType(type);
}
}
fVariableTable->SetNodeExpanded(path, nodeInfo->IsNodeExpanded());
// recurse