Skip to content

Commit 2302e0f

Browse files
Copilotxusheng6
andcommitted
Add UIAction-based copy support with Ctrl+C to TTD widgets
Co-authored-by: xusheng6 <[email protected]>
1 parent c9ef523 commit 2302e0f

File tree

4 files changed

+118
-32
lines changed

4 files changed

+118
-32
lines changed

ui/ttdcallswidget.cpp

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ TTDCallsQueryWidget::TTDCallsQueryWidget(QWidget* parent, BinaryViewRef data)
6363
setupUI();
6464
setupTable();
6565
setupContextMenu();
66+
setupUIActions();
6667
updateColumnVisibility();
6768
}
6869

@@ -157,6 +158,35 @@ void TTDCallsQueryWidget::setupContextMenu()
157158
connect(m_resultsTable, &QTableWidget::customContextMenuRequested, this, &TTDCallsQueryWidget::showContextMenu);
158159
}
159160

161+
void TTDCallsQueryWidget::setupUIActions()
162+
{
163+
m_actionHandler.setupActionHandler(this);
164+
m_contextMenuManager = new ContextMenuManager(this);
165+
m_menu = new Menu();
166+
167+
// Add Copy action with Ctrl+C support
168+
m_menu->addAction("Copy", "Options", MENU_ORDER_NORMAL);
169+
m_actionHandler.bindAction("Copy", UIAction([&]() { copy(); }, [&]() { return canCopy(); }));
170+
171+
// Add other context menu actions
172+
m_menu->addAction("Copy Cell", "Options", MENU_ORDER_NORMAL);
173+
m_actionHandler.bindAction("Copy Cell", UIAction([&]() { copySelectedCell(); }, [&]() { return canCopy(); }));
174+
175+
m_menu->addAction("Copy Row", "Options", MENU_ORDER_NORMAL);
176+
m_actionHandler.bindAction("Copy Row", UIAction([&]() { copySelectedRow(); }, [&]() { return canCopy(); }));
177+
178+
m_menu->addAction("Copy All", "Options", MENU_ORDER_NORMAL);
179+
m_actionHandler.bindAction("Copy All", UIAction([&]() { copyEntireTable(); }, [&]() { return m_resultsTable->rowCount() > 0; }));
180+
181+
m_menu->addSeparator();
182+
183+
m_menu->addAction("Column Visibility...", "Options", MENU_ORDER_NORMAL);
184+
m_actionHandler.bindAction("Column Visibility...", UIAction([&]() { showColumnVisibilityDialog(); }));
185+
186+
m_menu->addAction("Reset Columns", "Options", MENU_ORDER_NORMAL);
187+
m_actionHandler.bindAction("Reset Columns", UIAction([&]() { resetColumnsToDefault(); }));
188+
}
189+
160190

161191

162192
uint64_t TTDCallsQueryWidget::parseAddress(const QString& text)
@@ -427,18 +457,24 @@ void TTDCallsQueryWidget::resetColumnsToDefault()
427457
updateColumnVisibility();
428458
}
429459

460+
void TTDCallsQueryWidget::contextMenuEvent(QContextMenuEvent* event)
461+
{
462+
showContextMenu(event->pos());
463+
}
464+
430465
void TTDCallsQueryWidget::showContextMenu(const QPoint& position)
431466
{
432-
QMenu contextMenu(this);
433-
434-
contextMenu.addAction("Copy Cell", this, &TTDCallsQueryWidget::copySelectedCell);
435-
contextMenu.addAction("Copy Row", this, &TTDCallsQueryWidget::copySelectedRow);
436-
contextMenu.addAction("Copy All", this, &TTDCallsQueryWidget::copyEntireTable);
437-
contextMenu.addSeparator();
438-
contextMenu.addAction("Column Visibility...", this, &TTDCallsQueryWidget::showColumnVisibilityDialog);
439-
contextMenu.addAction("Reset Columns", this, &TTDCallsQueryWidget::resetColumnsToDefault);
440-
441-
contextMenu.exec(m_resultsTable->mapToGlobal(position));
467+
m_contextMenuManager->show(m_menu, &m_actionHandler);
468+
}
469+
470+
bool TTDCallsQueryWidget::canCopy()
471+
{
472+
return m_resultsTable->currentItem() != nullptr;
473+
}
474+
475+
void TTDCallsQueryWidget::copy()
476+
{
477+
copySelectedCell();
442478
}
443479

444480
void TTDCallsQueryWidget::copySelectedCell()

ui/ttdcallswidget.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@ limitations under the License.
3838
#include <QPropertyAnimation>
3939
#include <QParallelAnimationGroup>
4040
#include <QFrame>
41+
#include <QContextMenuEvent>
4142
#include "inttypes.h"
4243
#include "binaryninjaapi.h"
4344
#include "debuggerapi.h"
4445
#include "viewframe.h"
4546
#include "expandablegroup.h"
4647
#include "debuggeruicommon.h"
48+
#include "menus.h"
49+
#include "uitypes.h"
4750

4851
using namespace BinaryNinja;
4952
using namespace BinaryNinjaDebuggerAPI;
@@ -87,11 +90,20 @@ class TTDCallsQueryWidget : public QWidget
8790
QStringList m_columnNames;
8891
QList<bool> m_columnVisibility;
8992

93+
// UIAction support
94+
UIActionHandler m_actionHandler;
95+
ContextMenuManager* m_contextMenuManager;
96+
Menu* m_menu;
97+
9098
void setupUI();
9199
void setupTable();
92100
uint64_t parseAddress(const QString& text);
93101
void setupContextMenu();
102+
void setupUIActions();
94103
void updateColumnVisibility();
104+
bool canCopy();
105+
106+
virtual void contextMenuEvent(QContextMenuEvent* event) override;
95107

96108
public:
97109
TTDCallsQueryWidget(QWidget* parent, BinaryViewRef data);
@@ -110,6 +122,7 @@ private Q_SLOTS:
110122
void showColumnVisibilityDialog();
111123
void resetColumnsToDefault();
112124
void showContextMenu(const QPoint& position);
125+
void copy();
113126
void copySelectedCell();
114127
void copySelectedRow();
115128
void copyEntireTable();

ui/ttdmemorywidget.cpp

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ TTDMemoryQueryWidget::TTDMemoryQueryWidget(QWidget* parent, BinaryViewRef data)
119119
<< true; // IP
120120

121121
setupUI();
122+
setupUIActions();
122123
}
123124

124125
TTDMemoryQueryWidget::~TTDMemoryQueryWidget()
@@ -288,6 +289,35 @@ void TTDMemoryQueryWidget::setupContextMenu()
288289
this, &TTDMemoryQueryWidget::showContextMenu);
289290
}
290291

292+
void TTDMemoryQueryWidget::setupUIActions()
293+
{
294+
m_actionHandler.setupActionHandler(this);
295+
m_contextMenuManager = new ContextMenuManager(this);
296+
m_menu = new Menu();
297+
298+
// Add Copy action with Ctrl+C support
299+
m_menu->addAction("Copy", "Options", MENU_ORDER_NORMAL);
300+
m_actionHandler.bindAction("Copy", UIAction([&]() { copy(); }, [&]() { return canCopy(); }));
301+
302+
// Add other context menu actions
303+
m_menu->addAction("Copy Cell", "Options", MENU_ORDER_NORMAL);
304+
m_actionHandler.bindAction("Copy Cell", UIAction([&]() { copySelectedCell(); }, [&]() { return canCopy(); }));
305+
306+
m_menu->addAction("Copy Row", "Options", MENU_ORDER_NORMAL);
307+
m_actionHandler.bindAction("Copy Row", UIAction([&]() { copySelectedRow(); }, [&]() { return canCopy(); }));
308+
309+
m_menu->addAction("Copy Table", "Options", MENU_ORDER_NORMAL);
310+
m_actionHandler.bindAction("Copy Table", UIAction([&]() { copyEntireTable(); }, [&]() { return m_resultsTable->rowCount() > 0; }));
311+
312+
m_menu->addSeparator();
313+
314+
m_menu->addAction("Columns...", "Options", MENU_ORDER_NORMAL);
315+
m_actionHandler.bindAction("Columns...", UIAction([&]() { showColumnVisibilityDialog(); }));
316+
317+
m_menu->addAction("Reset Columns to Default", "Options", MENU_ORDER_NORMAL);
318+
m_actionHandler.bindAction("Reset Columns to Default", UIAction([&]() { resetColumnsToDefault(); }));
319+
}
320+
291321
void TTDMemoryQueryWidget::updateColumnVisibility()
292322
{
293323
for (int i = 0; i < m_columnVisibility.size(); ++i)
@@ -505,30 +535,24 @@ void TTDMemoryQueryWidget::showColumnVisibilityDialog()
505535
}
506536
}
507537

538+
void TTDMemoryQueryWidget::contextMenuEvent(QContextMenuEvent* event)
539+
{
540+
showContextMenu(event->pos());
541+
}
542+
508543
void TTDMemoryQueryWidget::showContextMenu(const QPoint& position)
509544
{
510-
QMenu menu(this);
511-
512-
QAction* copyCellAction = menu.addAction("Copy Cell");
513-
QAction* copyRowAction = menu.addAction("Copy Row");
514-
QAction* copyTableAction = menu.addAction("Copy Table");
515-
menu.addSeparator();
516-
QAction* columnsAction = menu.addAction("Columns...");
517-
QAction* resetColumnsAction = menu.addAction("Reset Columns to Default");
518-
519-
connect(copyCellAction, &QAction::triggered, this, &TTDMemoryQueryWidget::copySelectedCell);
520-
connect(copyRowAction, &QAction::triggered, this, &TTDMemoryQueryWidget::copySelectedRow);
521-
connect(copyTableAction, &QAction::triggered, this, &TTDMemoryQueryWidget::copyEntireTable);
522-
connect(columnsAction, &QAction::triggered, this, &TTDMemoryQueryWidget::showColumnVisibilityDialog);
523-
connect(resetColumnsAction, &QAction::triggered, this, &TTDMemoryQueryWidget::resetColumnsToDefault);
524-
525-
// Enable/disable actions based on selection
526-
QTableWidgetItem* item = m_resultsTable->itemAt(position);
527-
copyCellAction->setEnabled(item != nullptr);
528-
copyRowAction->setEnabled(item != nullptr);
529-
copyTableAction->setEnabled(m_resultsTable->rowCount() > 0);
530-
531-
menu.exec(m_resultsTable->mapToGlobal(position));
545+
m_contextMenuManager->show(m_menu, &m_actionHandler);
546+
}
547+
548+
bool TTDMemoryQueryWidget::canCopy()
549+
{
550+
return m_resultsTable->currentItem() != nullptr;
551+
}
552+
553+
void TTDMemoryQueryWidget::copy()
554+
{
555+
copySelectedCell();
532556
}
533557

534558
void TTDMemoryQueryWidget::copySelectedCell()

ui/ttdmemorywidget.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ limitations under the License.
3737
#include <QToolButton>
3838
#include <QPropertyAnimation>
3939
#include <QParallelAnimationGroup>
40+
#include <QContextMenuEvent>
4041
#include "inttypes.h"
4142
#include "binaryninjaapi.h"
4243
#include "debuggerapi.h"
4344
#include "viewframe.h"
4445
#include "expandablegroup.h"
4546
#include "debuggeruicommon.h"
47+
#include "menus.h"
48+
#include "uitypes.h"
4649

4750
using namespace BinaryNinja;
4851
using namespace BinaryNinjaDebuggerAPI;
@@ -102,13 +105,22 @@ class TTDMemoryQueryWidget : public QWidget
102105
QStringList m_columnNames;
103106
QList<bool> m_columnVisibility;
104107

108+
// UIAction support
109+
UIActionHandler m_actionHandler;
110+
ContextMenuManager* m_contextMenuManager;
111+
Menu* m_menu;
112+
105113
void setupUI();
106114
void setupTable();
107115
void updateStatus(const QString& message);
108116
uint64_t parseAddress(const QString& text);
109117
TTDMemoryAccessType getSelectedAccessTypes();
110118
void setupContextMenu();
119+
void setupUIActions();
111120
void updateColumnVisibility();
121+
bool canCopy();
122+
123+
virtual void contextMenuEvent(QContextMenuEvent* event) override;
112124

113125
public:
114126
TTDMemoryQueryWidget(QWidget* parent, BinaryViewRef data);
@@ -127,6 +139,7 @@ private Q_SLOTS:
127139
void showColumnVisibilityDialog();
128140
void resetColumnsToDefault();
129141
void showContextMenu(const QPoint& position);
142+
void copy();
130143
void copySelectedCell();
131144
void copySelectedRow();
132145
void copyEntireTable();

0 commit comments

Comments
 (0)