Skip to content

Commit

Permalink
Add a menu entry in the register widget to follow the register value …
Browse files Browse the repository at this point in the history
…in a new pane. Fix Vector35#474
  • Loading branch information
xusheng6 committed May 11, 2023
1 parent 14b5afa commit 504774f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 29 deletions.
79 changes: 50 additions & 29 deletions ui/registerswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,11 @@ DebugRegistersWidget::DebugRegistersWidget(ViewFrame* view, BinaryViewRef data,
m_menu->addAction(actionName, "Options", MENU_ORDER_FIRST);
m_actionHandler.bindAction(actionName, UIAction([=]() { jump(); }, [&]() { return selectionNotEmpty(); }));

actionName = QString::fromStdString("Jump to Address in New Pane");
UIAction::registerAction(actionName);
m_menu->addAction(actionName, "Options", MENU_ORDER_FIRST);
m_actionHandler.bindAction(actionName, UIAction([=]() { jumpInNewPane(); }, [&]() { return selectionNotEmpty(); }));

m_menu->addAction("Copy", "Options", MENU_ORDER_NORMAL);
m_actionHandler.bindAction("Copy", UIAction([&]() { copy(); }, [&]() { return selectionNotEmpty(); }));
m_actionHandler.setActionDisplayName("Copy", [&]() {
Expand Down Expand Up @@ -577,6 +582,16 @@ void DebugRegistersWidget::jump()
}


void DebugRegistersWidget::jumpInNewPane()
{
QModelIndexList sel = selectionModel()->selectedIndexes();
if (sel.empty())
return;

jumpInNewPaneInternal(sel[0]);
}


void DebugRegistersWidget::copy()
{
QModelIndexList sel = selectionModel()->selectedIndexes();
Expand Down Expand Up @@ -668,46 +683,52 @@ void DebugRegistersWidget::onDoubleClicked()
}


void DebugRegistersWidget::mousePressEvent(QMouseEvent *event)
void DebugRegistersWidget::jumpInNewPaneInternal(const QModelIndex &index)
{
startHoverTimer(event);
if (!index.isValid())
return;

if (event->button() == Qt::MiddleButton)
auto sourceIndex = m_filter->mapToSource(index);
if (!sourceIndex.isValid())
return;

auto reg = m_model->getRow(sourceIndex.row());
uint64_t value = reg.value();

ViewFrame* frame = ViewFrame::viewFrameForWidget(this);
auto* currentWindow = UIContext::contextForWidget(m_view);
if (frame && currentWindow)
{
auto index = indexAt(event->pos());
if (!index.isValid())
auto* splitPaneWidget = qobject_cast<SplitPaneWidget*>(currentWindow->getCurrentTab());
if (!splitPaneWidget)
return;

auto sourceIndex = m_filter->mapToSource(index);
if (!sourceIndex.isValid())
return;
Qt::Orientation defaultSplitDirection = splitPaneWidget->defaultSplitDirection();
splitPaneWidget->splitCurrentPane(defaultSplitDirection);

auto reg = m_model->getRow(sourceIndex.row());
uint64_t value = reg.value();
ViewPane* newPane = splitPaneWidget->currentViewPane();

ViewFrame* frame = ViewFrame::viewFrameForWidget(this);
auto* currentWindow = UIContext::contextForWidget(m_view);
if (frame && currentWindow)
{
auto* splitPaneWidget = qobject_cast<SplitPaneWidget*>(currentWindow->getCurrentTab());
if (!splitPaneWidget)
return;
if (!newPane)
return;

Qt::Orientation defaultSplitDirection = splitPaneWidget->defaultSplitDirection();
splitPaneWidget->splitCurrentPane(defaultSplitDirection);
ViewFrame* newViewFrame = newPane->viewFrame();
if (newViewFrame)
{
newViewFrame->disableSync();
newViewFrame->navigate(m_controller->GetLiveView(), value);
}
}
}

ViewPane* newPane = splitPaneWidget->currentViewPane();

if (!newPane)
return;
void DebugRegistersWidget::mousePressEvent(QMouseEvent *event)
{
startHoverTimer(event);

ViewFrame* newViewFrame = newPane->viewFrame();
if (newViewFrame)
{
newViewFrame->disableSync();
newViewFrame->navigate(m_controller->GetLiveView(), value);
}
}
if (event->button() == Qt::MiddleButton)
{
auto index = indexAt(event->pos());
jumpInNewPaneInternal(index);
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions ui/registerswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class DebugRegistersWidget : public QTableView, public FilterTarget
virtual void activateFirstItem() override;

void updateColumnWidths();
void jumpInNewPaneInternal(const QModelIndex& index);

void startHoverTimer(QMouseEvent* event);

Expand All @@ -196,6 +197,7 @@ class DebugRegistersWidget : public QTableView, public FilterTarget
private slots:
void setToZero();
void jump();
void jumpInNewPane();
void copy();
void paste();
void editValue();
Expand Down

0 comments on commit 504774f

Please sign in to comment.