From d05fdd3d441f0b9ae6e83a28e7b5aa1166177995 Mon Sep 17 00:00:00 2001 From: Adam Zambrzycki Date: Mon, 14 Jan 2019 09:16:10 +0100 Subject: [PATCH] Add 'Copy' context menu option to graph view (#1097) --- src/widgets/DisassemblerGraphView.cpp | 13 +++++++++++++ src/widgets/DisassemblerGraphView.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/src/widgets/DisassemblerGraphView.cpp b/src/widgets/DisassemblerGraphView.cpp index b4456d5e..f7d162c1 100644 --- a/src/widgets/DisassemblerGraphView.cpp +++ b/src/widgets/DisassemblerGraphView.cpp @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include "Cutter.h" #include "common/Colors.h" @@ -114,6 +116,8 @@ DisassemblerGraphView::DisassemblerGraphView(QWidget *parent) initFont(); colorsUpdatedSlot(); + connect(mMenu, SIGNAL(copy()), this, SLOT(copySelection())); + header = new QTextEdit(viewport()); header->setFixedHeight(30); header->setReadOnly(true); @@ -782,6 +786,14 @@ void DisassemblerGraphView::seekLocal(RVA addr, bool update_viewport) } } +void DisassemblerGraphView::copySelection() +{ + if (!highlight_token) return; + + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(highlight_token->content); +} + DisassemblerGraphView::Token *DisassemblerGraphView::getToken(Instr *instr, int x) { x -= (int) (3 * charWidth); // Ignore left margin @@ -828,6 +840,7 @@ void DisassemblerGraphView::blockClicked(GraphView::GraphBlock &block, QMouseEve seekLocal(addr); mMenu->setOffset(addr); + mMenu->setCanCopy(highlight_token); if (event->button() == Qt::RightButton) { mMenu->exec(event->globalPos()); } diff --git a/src/widgets/DisassemblerGraphView.h b/src/widgets/DisassemblerGraphView.h index 3a4e3b6d..f784c02e 100644 --- a/src/widgets/DisassemblerGraphView.h +++ b/src/widgets/DisassemblerGraphView.h @@ -145,6 +145,8 @@ public slots: void nextInstr(); void prevInstr(); + void copySelection(); + protected: virtual void wheelEvent(QWheelEvent *event) override;