Skip to content

Commit

Permalink
Debugger: Finish variable edit support.
Browse files Browse the repository at this point in the history
VariablesView:
- Intercept table node invocations. If the invocation corresponds to
  a writable variable, request a corresponding editor and bring up a
  an edit window for it.
- Handle requests from the edit window to write the final updated value
  of the variable.

This implements the last missing piece for ticket #9708, except for an
editor for floats.
  • Loading branch information
anevilyak committed Jul 24, 2015
1 parent 473b2c6 commit d88d941
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 2 deletions.
114 changes: 114 additions & 0 deletions src/apps/debugger/user_interface/gui/team_window/VariablesView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "StringUtils.h"
#include "StringValue.h"
#include "SyntheticPrimitiveType.h"
#include "TableCellValueEditor.h"
#include "TableCellValueRenderer.h"
#include "Team.h"
#include "TeamDebugInfo.h"
Expand All @@ -59,6 +60,7 @@
#include "ValueNode.h"
#include "ValueNodeManager.h"
#include "Variable.h"
#include "VariableEditWindow.h"
#include "VariableValueNodeChild.h"
#include "VariablesViewState.h"
#include "VariablesViewStateHistory.h"
Expand Down Expand Up @@ -1773,6 +1775,7 @@ VariablesView::VariablesView(Listener* listener)
fPendingTypecastInfo(NULL),
fTemporaryExpression(NULL),
fFrameClearPending(false),
fEditWindow(NULL),
fListener(listener)
{
SetName("Variables");
Expand All @@ -1781,6 +1784,9 @@ VariablesView::VariablesView(Listener* listener)

VariablesView::~VariablesView()
{
if (fEditWindow != NULL)
BMessenger(fEditWindow).SendMessage(B_QUIT_REQUESTED);

SetStackFrame(NULL, NULL);
fVariableTable->SetTreeTableModel(NULL);

Expand Down Expand Up @@ -1887,6 +1893,66 @@ VariablesView::MessageReceived(BMessage* message)
Looper()->PostMessage(message);
break;
}
case MSG_SHOW_VARIABLE_EDIT_WINDOW:
{
TableCellValueEditor* editor = NULL;
if (message->FindPointer("editor", reinterpret_cast<void**>(
&editor)) != B_OK) {
break;
}
BReference<TableCellValueEditor> editorReference(editor, true);
if (fEditWindow != NULL)
fEditWindow->Activate();
else {
ValueNode* node = NULL;
if (message->FindPointer("node", reinterpret_cast<void**>(
&node)) != B_OK) {
break;
}

Value* value = NULL;
if (message->FindPointer("value", reinterpret_cast<void**>(
&value)) != B_OK) {
break;
}

try {
fEditWindow = VariableEditWindow::Create(value, node,
editor, this);
} catch (...) {
fEditWindow = NULL;
break;
}

fEditWindow->Show();
}
break;
}
case MSG_VARIABLE_EDIT_WINDOW_CLOSED:
{
fEditWindow = NULL;
break;
}
case MSG_WRITE_VARIABLE_VALUE:
{
Value* value = NULL;
if (message->FindPointer("value", reinterpret_cast<void**>(
&value)) != B_OK) {
break;
}

BReference<Value> valueReference(value, true);

ValueNode* node = NULL;
if (message->FindPointer("node", reinterpret_cast<void**>(
&node)) != B_OK) {
break;
}

fListener->ValueNodeWriteRequested(node,
fStackFrame->GetCpuState(), value);
break;
}
case MSG_SHOW_TYPECAST_NODE_PROMPT:
{
BMessage* promptMessage = new(std::nothrow) BMessage(
Expand Down Expand Up @@ -2328,6 +2394,54 @@ VariablesView::TreeTableNodeExpandedChanged(TreeTable* table,
}


void
VariablesView::TreeTableNodeInvoked(TreeTable* table,
const TreeTablePath& path)
{
ModelNode* node = (ModelNode*)fVariableTableModel->NodeForPath(path);
if (node == NULL)
return;

ValueNodeChild* child = node->NodeChild();

if (child->LocationResolutionState() != B_OK)
return;

ValueLocation* location = child->Location();
if (!location->IsWritable())
return;

Value* value = node->GetValue();
if (value == NULL)
return;

// get a value handler
ValueHandler* valueHandler;
status_t error = ValueHandlerRoster::Default()->FindValueHandler(value,
valueHandler);
if (error != B_OK)
return;

BReference<ValueHandler> handlerReference(valueHandler, true);
TableCellValueRenderer* renderer = node->TableCellRenderer();
TableCellValueEditor* editor = NULL;
error = valueHandler->GetTableCellValueEditor(value,
renderer != NULL ? renderer->GetSettings() : NULL, editor);
if (error != B_OK || editor == NULL)
return;

BReference<TableCellValueEditor> editorReference(editor, true);

BMessage message(MSG_SHOW_VARIABLE_EDIT_WINDOW);
message.AddPointer("editor", editor);
message.AddPointer("node", node->NodeChild()->Node());
message.AddPointer("value", value);

if (BMessenger(this).SendMessage(&message) == B_OK)
editorReference.Detach();
}


void
VariablesView::TreeTableCellMouseDown(TreeTable* table,
const TreeTablePath& path, int32 columnIndex, BPoint screenWhere,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2012-2014, Rene Gollent, rene@gollent.com.
* Copyright 2012-2015, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#ifndef VARIABLES_VIEW_H
Expand All @@ -22,11 +22,13 @@ class StackFrame;
class Thread;
class Type;
class TypeComponentPath;
class ValueLocation;
class ValueNode;
class ValueNodeChild;
class ValueNodeContainer;
class Value;
class Variable;
class VariableEditWindow;
class VariablesViewState;
class VariablesViewStateHistory;

Expand Down Expand Up @@ -59,7 +61,8 @@ class VariablesView : public BGroupView, private TreeTableListener,
// TreeTableListener
virtual void TreeTableNodeExpandedChanged(TreeTable* table,
const TreeTablePath& path, bool expanded);

virtual void TreeTableNodeInvoked(TreeTable* table,
const TreeTablePath& path);
virtual void TreeTableCellMouseDown(TreeTable* table,
const TreeTablePath& path,
int32 columnIndex, BPoint screenWhere,
Expand Down Expand Up @@ -143,6 +146,7 @@ class VariablesView : public BGroupView, private TreeTableListener,
VariablesExpressionInfo* fPendingTypecastInfo;
ExpressionInfo* fTemporaryExpression;
bool fFrameClearPending;
VariableEditWindow* fEditWindow;
Listener* fListener;
};

Expand Down

0 comments on commit d88d941

Please sign in to comment.