Adapt VariablesView to use the ValueNodeManager.
This commit is contained in:
@@ -50,7 +50,7 @@
|
|||||||
#include "ValueHandlerRoster.h"
|
#include "ValueHandlerRoster.h"
|
||||||
#include "ValueLocation.h"
|
#include "ValueLocation.h"
|
||||||
#include "ValueNode.h"
|
#include "ValueNode.h"
|
||||||
#include "ValueNodeContainer.h"
|
#include "ValueNodeManager.h"
|
||||||
#include "Variable.h"
|
#include "Variable.h"
|
||||||
#include "VariableValueNodeChild.h"
|
#include "VariableValueNodeChild.h"
|
||||||
#include "VariablesViewState.h"
|
#include "VariablesViewState.h"
|
||||||
@@ -451,17 +451,10 @@ private:
|
|||||||
ValueNodeChild* nodeChild,
|
ValueNodeChild* nodeChild,
|
||||||
bool isPresentationNode = false,
|
bool isPresentationNode = false,
|
||||||
bool isOnlyChild = false);
|
bool isOnlyChild = false);
|
||||||
void _AddNode(Variable* variable);
|
|
||||||
status_t _CreateValueNode(ValueNodeChild* nodeChild);
|
|
||||||
status_t _AddChildNodes(ValueNodeChild* nodeChild);
|
|
||||||
|
|
||||||
// ModelNode* _GetNode(Variable* variable,
|
|
||||||
// TypeComponentPath* path) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Thread* fThread;
|
Thread* fThread;
|
||||||
StackFrame* fStackFrame;
|
ValueNodeManager* fNodeManager;
|
||||||
ValueNodeContainer* fContainer;
|
|
||||||
ContainerListener* fContainerListener;
|
ContainerListener* fContainerListener;
|
||||||
NodeList fNodes;
|
NodeList fNodes;
|
||||||
NodeTable fNodeTable;
|
NodeTable fNodeTable;
|
||||||
@@ -841,8 +834,8 @@ VariablesView::ContainerListener::ModelNodeRestoreViewStateRequested(
|
|||||||
|
|
||||||
VariablesView::VariableTableModel::VariableTableModel()
|
VariablesView::VariableTableModel::VariableTableModel()
|
||||||
:
|
:
|
||||||
fStackFrame(NULL),
|
fThread(NULL),
|
||||||
fContainer(NULL),
|
fNodeManager(NULL),
|
||||||
fContainerListener(NULL),
|
fContainerListener(NULL),
|
||||||
fNodeTable()
|
fNodeTable()
|
||||||
{
|
{
|
||||||
@@ -851,13 +844,18 @@ VariablesView::VariableTableModel::VariableTableModel()
|
|||||||
|
|
||||||
VariablesView::VariableTableModel::~VariableTableModel()
|
VariablesView::VariableTableModel::~VariableTableModel()
|
||||||
{
|
{
|
||||||
SetStackFrame(NULL, NULL);
|
if (fNodeManager != NULL)
|
||||||
|
fNodeManager->ReleaseReference();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
VariablesView::VariableTableModel::Init()
|
VariablesView::VariableTableModel::Init()
|
||||||
{
|
{
|
||||||
|
fNodeManager = new(std::nothrow) ValueNodeManager();
|
||||||
|
if (fNodeManager == NULL)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
return fNodeTable.Init();
|
return fNodeTable.Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -870,10 +868,8 @@ VariablesView::VariableTableModel::SetContainerListener(
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (fContainerListener != NULL) {
|
if (fContainerListener != NULL) {
|
||||||
if (fContainer != NULL) {
|
if (fNodeManager != NULL)
|
||||||
AutoLocker<ValueNodeContainer> containerLocker(fContainer);
|
fNodeManager->RemoveListener(fContainerListener);
|
||||||
fContainer->RemoveListener(fContainerListener);
|
|
||||||
}
|
|
||||||
|
|
||||||
fContainerListener->SetModel(NULL);
|
fContainerListener->SetModel(NULL);
|
||||||
}
|
}
|
||||||
@@ -883,10 +879,8 @@ VariablesView::VariableTableModel::SetContainerListener(
|
|||||||
if (fContainerListener != NULL) {
|
if (fContainerListener != NULL) {
|
||||||
fContainerListener->SetModel(this);
|
fContainerListener->SetModel(this);
|
||||||
|
|
||||||
if (fContainer != NULL) {
|
if (fNodeManager != NULL)
|
||||||
AutoLocker<ValueNodeContainer> containerLocker(fContainer);
|
fNodeManager->AddListener(fContainerListener);
|
||||||
fContainer->AddListener(fContainerListener);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -895,17 +889,9 @@ void
|
|||||||
VariablesView::VariableTableModel::SetStackFrame(Thread* thread,
|
VariablesView::VariableTableModel::SetStackFrame(Thread* thread,
|
||||||
StackFrame* stackFrame)
|
StackFrame* stackFrame)
|
||||||
{
|
{
|
||||||
if (fContainer != NULL) {
|
fThread = thread;
|
||||||
AutoLocker<ValueNodeContainer> containerLocker(fContainer);
|
|
||||||
|
|
||||||
if (fContainerListener != NULL)
|
fNodeManager->SetStackFrame(thread, stackFrame);
|
||||||
fContainer->RemoveListener(fContainerListener);
|
|
||||||
|
|
||||||
fContainer->RemoveAllChildren();
|
|
||||||
containerLocker.Unlock();
|
|
||||||
fContainer->ReleaseReference();
|
|
||||||
fContainer = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
fNodeTable.Clear(true);
|
fNodeTable.Clear(true);
|
||||||
|
|
||||||
@@ -917,38 +903,19 @@ VariablesView::VariableTableModel::SetStackFrame(Thread* thread,
|
|||||||
NotifyNodesRemoved(TreeTablePath(), 0, count);
|
NotifyNodesRemoved(TreeTablePath(), 0, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
fStackFrame = stackFrame;
|
if (stackFrame == NULL)
|
||||||
fThread = thread;
|
return;
|
||||||
|
|
||||||
if (fStackFrame != NULL) {
|
ValueNodeContainer* container = fNodeManager->GetContainer();
|
||||||
fContainer = new(std::nothrow) ValueNodeContainer;
|
AutoLocker<ValueNodeContainer> containerLocker(container);
|
||||||
if (fContainer == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
status_t error = fContainer->Init();
|
for (int32 i = 0; i < container->CountChildren(); i++) {
|
||||||
if (error != B_OK) {
|
VariableValueNodeChild* child = dynamic_cast<VariableValueNodeChild *>(
|
||||||
delete fContainer;
|
container->ChildAt(i));
|
||||||
fContainer = NULL;
|
_AddNode(child->GetVariable(), NULL, child);
|
||||||
return;
|
// top level nodes get their children added immediately
|
||||||
}
|
// so those won't invoke our callback hook. Add them directly here.
|
||||||
|
ValueNodeChildrenCreated(child->Node());
|
||||||
AutoLocker<ValueNodeContainer> containerLocker(fContainer);
|
|
||||||
|
|
||||||
if (fContainerListener != NULL)
|
|
||||||
fContainer->AddListener(fContainerListener);
|
|
||||||
|
|
||||||
for (int32 i = 0; Variable* variable = fStackFrame->ParameterAt(i);
|
|
||||||
i++) {
|
|
||||||
_AddNode(variable);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int32 i = 0; Variable* variable
|
|
||||||
= fStackFrame->LocalVariableAt(i); i++) {
|
|
||||||
_AddNode(variable);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (!fNodes.IsEmpty())
|
|
||||||
// NotifyNodesAdded(TreeTablePath(), 0, fNodes.CountItems());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -957,19 +924,14 @@ void
|
|||||||
VariablesView::VariableTableModel::ValueNodeChanged(ValueNodeChild* nodeChild,
|
VariablesView::VariableTableModel::ValueNodeChanged(ValueNodeChild* nodeChild,
|
||||||
ValueNode* oldNode, ValueNode* newNode)
|
ValueNode* oldNode, ValueNode* newNode)
|
||||||
{
|
{
|
||||||
if (fContainer == NULL)
|
AutoLocker<ValueNodeContainer> containerLocker(
|
||||||
return;
|
fNodeManager->GetContainer());
|
||||||
|
|
||||||
AutoLocker<ValueNodeContainer> containerLocker(fContainer);
|
|
||||||
ModelNode* modelNode = fNodeTable.Lookup(nodeChild);
|
ModelNode* modelNode = fNodeTable.Lookup(nodeChild);
|
||||||
if (modelNode == NULL)
|
if (modelNode == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (oldNode != NULL) {
|
if (oldNode != NULL)
|
||||||
ValueNodeChildrenDeleted(oldNode);
|
|
||||||
newNode->CreateChildren();
|
|
||||||
NotifyNodeChanged(modelNode);
|
NotifyNodeChanged(modelNode);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -977,10 +939,8 @@ void
|
|||||||
VariablesView::VariableTableModel::ValueNodeChildrenCreated(
|
VariablesView::VariableTableModel::ValueNodeChildrenCreated(
|
||||||
ValueNode* valueNode)
|
ValueNode* valueNode)
|
||||||
{
|
{
|
||||||
if (fContainer == NULL)
|
AutoLocker<ValueNodeContainer> containerLocker(
|
||||||
return;
|
fNodeManager->GetContainer());
|
||||||
|
|
||||||
AutoLocker<ValueNodeContainer> containerLocker(fContainer);
|
|
||||||
|
|
||||||
// check whether we know the node
|
// check whether we know the node
|
||||||
ValueNodeChild* nodeChild = valueNode->NodeChild();
|
ValueNodeChild* nodeChild = valueNode->NodeChild();
|
||||||
@@ -1016,10 +976,8 @@ VariablesView::VariableTableModel::ValueNodeChildrenCreated(
|
|||||||
void
|
void
|
||||||
VariablesView::VariableTableModel::ValueNodeChildrenDeleted(ValueNode* node)
|
VariablesView::VariableTableModel::ValueNodeChildrenDeleted(ValueNode* node)
|
||||||
{
|
{
|
||||||
if (fContainer == NULL)
|
AutoLocker<ValueNodeContainer> containerLocker(
|
||||||
return;
|
fNodeManager->GetContainer());
|
||||||
|
|
||||||
AutoLocker<ValueNodeContainer> containerLocker(fContainer);
|
|
||||||
|
|
||||||
// check whether we know the node
|
// check whether we know the node
|
||||||
ValueNodeChild* nodeChild = node->NodeChild();
|
ValueNodeChild* nodeChild = node->NodeChild();
|
||||||
@@ -1058,10 +1016,8 @@ VariablesView::VariableTableModel::ValueNodeChildrenDeleted(ValueNode* node)
|
|||||||
void
|
void
|
||||||
VariablesView::VariableTableModel::ValueNodeValueChanged(ValueNode* valueNode)
|
VariablesView::VariableTableModel::ValueNodeValueChanged(ValueNode* valueNode)
|
||||||
{
|
{
|
||||||
if (fContainer == NULL)
|
AutoLocker<ValueNodeContainer> containerLocker(
|
||||||
return;
|
fNodeManager->GetContainer());
|
||||||
|
|
||||||
AutoLocker<ValueNodeContainer> containerLocker(fContainer);
|
|
||||||
|
|
||||||
// check whether we know the node
|
// check whether we know the node
|
||||||
ValueNodeChild* nodeChild = valueNode->NodeChild();
|
ValueNodeChild* nodeChild = valueNode->NodeChild();
|
||||||
@@ -1072,19 +1028,6 @@ VariablesView::VariableTableModel::ValueNodeValueChanged(ValueNode* valueNode)
|
|||||||
if (modelNode == NULL)
|
if (modelNode == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (valueNode->ChildCreationNeedsValue()
|
|
||||||
&& !valueNode->ChildrenCreated()) {
|
|
||||||
status_t error = valueNode->CreateChildren();
|
|
||||||
if (error != B_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (int32 i = 0; i < valueNode->CountChildren(); i++) {
|
|
||||||
ValueNodeChild* child = valueNode->ChildAt(i);
|
|
||||||
_CreateValueNode(child);
|
|
||||||
_AddChildNodes(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check whether the value actually changed
|
// check whether the value actually changed
|
||||||
Value* value = valueNode->GetValue();
|
Value* value = valueNode->GetValue();
|
||||||
if (value == modelNode->GetValue())
|
if (value == modelNode->GetValue())
|
||||||
@@ -1214,11 +1157,8 @@ VariablesView::VariableTableModel::GetValueAt(void* object, int32 columnIndex,
|
|||||||
void
|
void
|
||||||
VariablesView::VariableTableModel::NodeExpanded(ModelNode* node)
|
VariablesView::VariableTableModel::NodeExpanded(ModelNode* node)
|
||||||
{
|
{
|
||||||
if (fContainer == NULL)
|
AutoLocker<ValueNodeContainer> containerLocker(
|
||||||
return;
|
fNodeManager->GetContainer());
|
||||||
|
|
||||||
AutoLocker<ValueNodeContainer> containerLocker(fContainer);
|
|
||||||
|
|
||||||
// add children of all children
|
// add children of all children
|
||||||
|
|
||||||
// If the node only has a hidden child, add the child's children instead.
|
// If the node only has a hidden child, add the child's children instead.
|
||||||
@@ -1230,7 +1170,7 @@ VariablesView::VariableTableModel::NodeExpanded(ModelNode* node)
|
|||||||
|
|
||||||
// add the children
|
// add the children
|
||||||
for (int32 i = 0; ModelNode* child = node->ChildAt(i); i++)
|
for (int32 i = 0; ModelNode* child = node->ChildAt(i); i++)
|
||||||
_AddChildNodes(child->NodeChild());
|
fNodeManager->AddChildNodes(child->NodeChild());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1365,150 +1305,12 @@ VariablesView::VariableTableModel::_AddNode(Variable* variable,
|
|||||||
|
|
||||||
// if the node is hidden, add its children
|
// if the node is hidden, add its children
|
||||||
if (node->IsHidden())
|
if (node->IsHidden())
|
||||||
_AddChildNodes(nodeChild);
|
fNodeManager->AddChildNodes(nodeChild);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
VariablesView::VariableTableModel::_AddNode(Variable* variable)
|
|
||||||
{
|
|
||||||
// create the node child for the variable
|
|
||||||
ValueNodeChild* nodeChild = new (std::nothrow) VariableValueNodeChild(
|
|
||||||
variable);
|
|
||||||
BReference<ValueNodeChild> nodeChildReference(nodeChild, true);
|
|
||||||
if (nodeChild == NULL || !fContainer->AddChild(nodeChild)) {
|
|
||||||
delete nodeChild;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// create the model node
|
|
||||||
status_t error = _AddNode(variable, NULL, nodeChild, false);
|
|
||||||
if (error != B_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// automatically add child nodes for the top level nodes
|
|
||||||
_AddChildNodes(nodeChild);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
VariablesView::VariableTableModel::_CreateValueNode(ValueNodeChild* nodeChild)
|
|
||||||
{
|
|
||||||
if (nodeChild->Node() != NULL)
|
|
||||||
return B_OK;
|
|
||||||
|
|
||||||
// create the node
|
|
||||||
ValueNode* valueNode;
|
|
||||||
status_t error;
|
|
||||||
if (nodeChild->IsInternal()) {
|
|
||||||
error = nodeChild->CreateInternalNode(valueNode);
|
|
||||||
} else {
|
|
||||||
error = TypeHandlerRoster::Default()->CreateValueNode(nodeChild,
|
|
||||||
nodeChild->GetType(), valueNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error != B_OK)
|
|
||||||
return error;
|
|
||||||
|
|
||||||
nodeChild->SetNode(valueNode);
|
|
||||||
valueNode->ReleaseReference();
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
VariablesView::VariableTableModel::_AddChildNodes(ValueNodeChild* nodeChild)
|
|
||||||
{
|
|
||||||
// create a value node for the value node child, if doesn't have one yet
|
|
||||||
ValueNode* valueNode = nodeChild->Node();
|
|
||||||
if (valueNode == NULL) {
|
|
||||||
status_t error = _CreateValueNode(nodeChild);
|
|
||||||
if (error != B_OK)
|
|
||||||
return error;
|
|
||||||
valueNode = nodeChild->Node();
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if this node requires child creation
|
|
||||||
// to be deferred until after its location/value have been resolved
|
|
||||||
if (valueNode->ChildCreationNeedsValue())
|
|
||||||
return B_OK;
|
|
||||||
|
|
||||||
// create the children, if not done yet
|
|
||||||
if (valueNode->ChildrenCreated())
|
|
||||||
return B_OK;
|
|
||||||
|
|
||||||
return valueNode->CreateChildren();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//VariablesView::ModelNode*
|
|
||||||
//VariablesView::VariableTableModel::_GetNode(Variable* variable,
|
|
||||||
// TypeComponentPath* path) const
|
|
||||||
//{
|
|
||||||
// // find the variable node
|
|
||||||
// ModelNode* node;
|
|
||||||
// for (int32 i = 0; (node = fNodes.ItemAt(i)) != NULL; i++) {
|
|
||||||
// if (node->GetVariable() == variable)
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// if (node == NULL)
|
|
||||||
// return NULL;
|
|
||||||
//
|
|
||||||
// // Now walk along the path, finding the respective child node for each
|
|
||||||
// // component (might be several components at once).
|
|
||||||
// int32 componentCount = path->CountComponents();
|
|
||||||
// for (int32 i = 0; i < componentCount;) {
|
|
||||||
// ModelNode* childNode = NULL;
|
|
||||||
//
|
|
||||||
// for (int32 k = 0; (childNode = node->ChildAt(k)) != NULL; k++) {
|
|
||||||
// TypeComponentPath* childPath = childNode->Path();
|
|
||||||
// int32 childComponentCount = childPath->CountComponents();
|
|
||||||
// if (childComponentCount > componentCount)
|
|
||||||
// continue;
|
|
||||||
//
|
|
||||||
// for (int32 componentIndex = i;
|
|
||||||
// componentIndex < childComponentCount; componentIndex++) {
|
|
||||||
// TypeComponent childComponent
|
|
||||||
// = childPath->ComponentAt(componentIndex);
|
|
||||||
// TypeComponent pathComponent
|
|
||||||
// = path->ComponentAt(componentIndex);
|
|
||||||
// if (childComponent != pathComponent) {
|
|
||||||
// if (componentIndex + 1 == childComponentCount
|
|
||||||
// && pathComponent.HasPrefix(childComponent)) {
|
|
||||||
// // The last child component is a prefix of the
|
|
||||||
// // corresponding path component. We consider this a
|
|
||||||
// // match, but need to recheck the component with the
|
|
||||||
// // next node level.
|
|
||||||
// childComponentCount--;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // mismatch -- skip the child
|
|
||||||
// childNode = NULL;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (childNode != NULL) {
|
|
||||||
// // got a match -- skip the matched children components
|
|
||||||
// i = childComponentCount;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (childNode == NULL)
|
|
||||||
// return NULL;
|
|
||||||
//
|
|
||||||
// node = childNode;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return node;
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
VariablesView::VariableTableModel::GetTreePath(ModelNode* node,
|
VariablesView::VariableTableModel::GetTreePath(ModelNode* node,
|
||||||
TreeTablePath& _path) const
|
TreeTablePath& _path) const
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ public:
|
|||||||
virtual Type* GetType() const;
|
virtual Type* GetType() const;
|
||||||
virtual ValueNode* Parent() const;
|
virtual ValueNode* Parent() const;
|
||||||
|
|
||||||
|
Variable* GetVariable() const { return fVariable; };
|
||||||
|
|
||||||
virtual status_t ResolveLocation(ValueLoader* valueLoader,
|
virtual status_t ResolveLocation(ValueLoader* valueLoader,
|
||||||
ValueLocation*& _location);
|
ValueLocation*& _location);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user