Skip to content

Commit

Permalink
Traktor: Some cleanup in debugger and GridView widget.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed Feb 29, 2024
1 parent 56e166d commit 431fc06
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 44 deletions.
38 changes: 18 additions & 20 deletions code/Script/Editor/ScriptDebuggerView.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -38,12 +38,10 @@
#include "Ui/ToolBar/ToolBarButton.h"
#include "Ui/ToolBar/ToolBarButtonClickEvent.h"

namespace traktor
namespace traktor::script
{
namespace script
namespace
{
namespace
{

struct VariablePred
{
Expand All @@ -53,7 +51,7 @@ struct VariablePred
}
};

}
}

T_IMPLEMENT_RTTI_CLASS(L"traktor.script.ScriptDebuggerView", ScriptDebuggerView, ui::Container)

Expand Down Expand Up @@ -172,9 +170,9 @@ void ScriptDebuggerView::updateLocals(int32_t depth)
if (m_scriptDebugger->captureLocals(depth, locals))
{
locals.sort(VariablePred());
for (RefArray< Variable >::const_iterator j = locals.begin(); j != locals.end(); ++j)
for (auto local : locals)
{
Ref< ui::GridRow > row = createVariableRow(*j);
Ref< ui::GridRow > row = createVariableRow(local);
if (row)
m_localsGrid->addRow(row);
}
Expand All @@ -187,35 +185,34 @@ void ScriptDebuggerView::debugeeStateChange(IScriptDebugger* scriptDebugger)
{
if (!scriptDebugger->isRunning())
{
// Capture all stack frames.
m_stackFrames.resize(0);
for (uint32_t depth = 0; ; ++depth)
{
Ref< StackFrame > sf;
if (!scriptDebugger->captureStackFrame(depth, sf))
break;

T_FATAL_ASSERT (sf);
m_stackFrames.push_back(sf);
}

m_callStackGrid->removeAllRows();
const bool autoOpenDebuggedScript = m_editor->getSettings()->getProperty< bool >(L"Editor.AutoOpenDebuggedScript", true);

bool autoOpenDebuggedScript = m_editor->getSettings()->getProperty< bool >(L"Editor.AutoOpenDebuggedScript", true);
Ref< ui::HierarchicalState > state = m_callStackGrid->captureState();
m_callStackGrid->removeAllRows();

int32_t depth = 0;
for (auto stackFrame : m_stackFrames)
{
Ref< db::Instance > scriptInstance = m_editor->getSourceDatabase()->getInstance(stackFrame->getScriptId());

Ref< ui::GridRow > row = new ui::GridRow(0);

row->add(stackFrame->getFunctionName());
row->add(toString(stackFrame->getLine() + 1));
row->add(scriptInstance ? scriptInstance->getName() : L"(Unknown script)");
row->setData(L"SCRIPT_ID", new PropertyString(stackFrame->getScriptId().format()));
row->setData(L"SCRIPT_LINE", new PropertyInteger(stackFrame->getLine()));
row->setData(L"FRAME_DEPTH", new PropertyInteger(depth++));

m_callStackGrid->addRow(row);

// Open debugged script and issue a "goto line" to scroll script editor to debugged line.
Expand All @@ -232,7 +229,9 @@ void ScriptDebuggerView::debugeeStateChange(IScriptDebugger* scriptDebugger)
updateLocals(0);

m_callStackGrid->setEnable(true);
m_callStackGrid->applyState(state);
m_callStackGrid->update();

m_localsGrid->setEnable(true);
m_localsGrid->update();
}
Expand All @@ -258,9 +257,9 @@ void ScriptDebuggerView::eventCallStackGridDoubleClick(ui::MouseDoubleClickEvent
ui::GridRow* selectedRow = m_callStackGrid->getSelectedRow();
if (selectedRow)
{
Guid scriptId = Guid(*(selectedRow->getData< PropertyString >(L"SCRIPT_ID")));
int32_t line = *(selectedRow->getData< PropertyInteger >(L"SCRIPT_LINE"));
int32_t depth = *(selectedRow->getData< PropertyInteger >(L"FRAME_DEPTH"));
const Guid scriptId = Guid(*(selectedRow->getData< PropertyString >(L"SCRIPT_ID")));
const int32_t line = *(selectedRow->getData< PropertyInteger >(L"SCRIPT_LINE"));
const int32_t depth = *(selectedRow->getData< PropertyInteger >(L"FRAME_DEPTH"));

Ref< db::Instance > scriptInstance = m_editor->getSourceDatabase()->getInstance(scriptId);
if (scriptInstance)
Expand Down Expand Up @@ -294,9 +293,9 @@ void ScriptDebuggerView::eventLocalsGridStateChange(ui::GridRowStateChangeEvent*
if (m_scriptDebugger->captureObject(valueObject->getObjectRef(), members))
{
members.sort(VariablePred());
for (RefArray< Variable >::const_iterator j = members.begin(); j != members.end(); ++j)
for (auto member : members)
{
Ref< ui::GridRow > childRow = createVariableRow(*j);
Ref< ui::GridRow > childRow = createVariableRow(member);
if (childRow)
row->addChild(childRow);
}
Expand All @@ -321,11 +320,10 @@ void ScriptDebuggerView::eventLocalsGridButtonDown(ui::MouseButtonDownEvent* eve
ui::GridRow* selectedRow = m_localsGrid->getSelectedRow();
if (selectedRow)
{
std::wstring value = selectedRow->get(1)->getText();
const std::wstring value = selectedRow->get(1)->getText();
ui::Application::getInstance()->getClipboard()->setText(value);
}
}
}

}
}
22 changes: 9 additions & 13 deletions code/Script/Editor/ScriptDebuggerView.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -11,17 +11,15 @@
#include "Script/IScriptDebugger.h"
#include "Ui/Container.h"

namespace traktor
namespace traktor::editor
{
namespace editor
{

class IEditor;

}
}

namespace ui
{
namespace traktor::ui
{

class Command;
class GridRow;
Expand All @@ -31,10 +29,10 @@ class Menu;
class ToolBar;
class ToolBarButtonClickEvent;

}
}

namespace script
{
namespace traktor::script
{

class Variable;

Expand All @@ -45,7 +43,7 @@ class ScriptDebuggerView
T_RTTI_CLASS;

public:
ScriptDebuggerView(editor::IEditor* editor, IScriptDebugger* scriptDebugger);
explicit ScriptDebuggerView(editor::IEditor* editor, IScriptDebugger* scriptDebugger);

virtual ~ScriptDebuggerView();

Expand Down Expand Up @@ -85,6 +83,4 @@ class ScriptDebuggerView
void eventLocalsGridButtonDown(ui::MouseButtonDownEvent* event);
};

}
}

16 changes: 8 additions & 8 deletions code/Script/Lua/ScriptDebuggerLua.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -162,7 +162,7 @@ bool ScriptDebuggerLua::captureLocals(uint32_t depth, RefArray< Variable >& outL
if (object)
variable->setTypeName(type_name(object));

uint32_t objectRef = luaL_ref(m_luaState, LUA_REGISTRYINDEX);
const uint32_t objectRef = luaL_ref(m_luaState, LUA_REGISTRYINDEX);

Boxed* b = dynamic_type_cast< Boxed* >(object);
if (b)
Expand All @@ -174,7 +174,7 @@ bool ScriptDebuggerLua::captureLocals(uint32_t depth, RefArray< Variable >& outL
{
lua_pop(L, 1);

uint32_t objectRef = luaL_ref(m_luaState, LUA_REGISTRYINDEX);
const uint32_t objectRef = luaL_ref(m_luaState, LUA_REGISTRYINDEX);
variable->setValue(new ValueObject(objectRef));
}
}
Expand Down Expand Up @@ -231,7 +231,7 @@ bool ScriptDebuggerLua::captureLocals(uint32_t depth, RefArray< Variable >& outL
if (object)
variable->setTypeName(type_name(object));

uint32_t objectRef = luaL_ref(m_luaState, LUA_REGISTRYINDEX);
const uint32_t objectRef = luaL_ref(m_luaState, LUA_REGISTRYINDEX);

Boxed* b = dynamic_type_cast< Boxed* >(object);
if (b)
Expand All @@ -243,7 +243,7 @@ bool ScriptDebuggerLua::captureLocals(uint32_t depth, RefArray< Variable >& outL
{
lua_pop(L, 1);

uint32_t objectRef = luaL_ref(m_luaState, LUA_REGISTRYINDEX);
const uint32_t objectRef = luaL_ref(m_luaState, LUA_REGISTRYINDEX);
variable->setValue(new ValueObject(objectRef));
}
}
Expand Down Expand Up @@ -278,7 +278,7 @@ bool ScriptDebuggerLua::captureObject(uint32_t object, RefArray< Variable >& out
if (lua_getmetatable(L, -1))
{
Ref< Variable > variable = new Variable(L"(meta)", L"", 0);
uint32_t objectRef = luaL_ref(m_luaState, LUA_REGISTRYINDEX);
const uint32_t objectRef = luaL_ref(m_luaState, LUA_REGISTRYINDEX);
variable->setValue(new ValueObject(objectRef));
outMembers.push_back(variable);
}
Expand Down Expand Up @@ -345,7 +345,7 @@ bool ScriptDebuggerLua::captureObject(uint32_t object, RefArray< Variable >& out
else
lua_pop(L, 1);

uint32_t objectRef = luaL_ref(m_luaState, LUA_REGISTRYINDEX);
const uint32_t objectRef = luaL_ref(m_luaState, LUA_REGISTRYINDEX);
variable->setValue(new ValueObject(objectRef));
}
else
Expand Down Expand Up @@ -400,7 +400,7 @@ void ScriptDebuggerLua::analyzeState(lua_State* L, lua_Debug* ar)
if (!currentContext)
return;

int32_t currentLine = ar->currentline - 1;
const int32_t currentLine = ar->currentline - 1;
m_breadcrumb.push_back(currentLine);

if (m_state == StRunning)
Expand Down
2 changes: 1 addition & 1 deletion code/Ui/GridView/GridRow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void GridRow::placeCells(AutoWidget* widget, const Rect& rect)

rcCell.right = rcCell.left + width;

if (m_items[i])
if (i < m_items.size() && m_items[i] != nullptr)
{
Rect rcCellLocal = rcCell;
if (i == 0)
Expand Down
8 changes: 6 additions & 2 deletions code/Ui/GridView/GridView.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma optimize( "", off )

/*
* TRAKTOR
* Copyright (c) 2022-2023 Anders Pistol.
Expand Down Expand Up @@ -283,7 +285,8 @@ Ref< HierarchicalState > GridView::captureState() const
for (uint32_t i = 0; i < (uint32_t)m_columns.size(); ++i)
state->setValue(i, m_columns[i]->getWidth().get());

for (auto row : getRows(GfDescendants))
RefArray< GridRow > rows = getRows(GfDescendants);
for (auto row : rows)
{
state->addState(
getRowPath(row),
Expand All @@ -303,7 +306,8 @@ void GridView::applyState(const HierarchicalState* state)
m_columns[i]->setWidth(Unit(width));
}

for (auto row : getRows(GfDescendants))
RefArray< GridRow > rows = getRows(GfDescendants);
for (auto row : rows)
{
const std::wstring path = getRowPath(row);
row->setState(
Expand Down

0 comments on commit 431fc06

Please sign in to comment.