Add 'Copy' context menu option to graph view (#1097)

This commit is contained in:
Adam Zambrzycki 2019-01-14 09:16:10 +01:00 committed by xarkes
parent b0bb1f0610
commit d05fdd3d44
2 changed files with 15 additions and 0 deletions

View File

@ -14,6 +14,8 @@
#include <QVBoxLayout>
#include <QRegularExpression>
#include <QStandardPaths>
#include <QClipboard>
#include <QApplication>
#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());
}

View File

@ -145,6 +145,8 @@ public slots:
void nextInstr();
void prevInstr();
void copySelection();
protected:
virtual void wheelEvent(QWheelEvent *event) override;