Add Ctrl-Shift-C shortcut (#1476)

* Copies address at cursor from hexdump, graph and disassembly views
This commit is contained in:
Christopher Harvey 2019-04-25 07:38:53 -04:00 committed by Itay Cohen
parent f68ed82489
commit e00a70ceaa
5 changed files with 38 additions and 3 deletions

View File

@ -25,11 +25,11 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent)
initAction(&actionCopy, tr("Copy"), SLOT(on_actionCopy_triggered()), getCopySequence());
addAction(&actionCopy);
copySeparator = addSeparator();
initAction(&actionCopyAddr, tr("Copy address"), SLOT(on_actionCopyAddr_triggered()));
initAction(&actionCopyAddr, tr("Copy address"), SLOT(on_actionCopyAddr_triggered()), getCopyAddressSequence());
addAction(&actionCopyAddr);
copySeparator = addSeparator();
initAction(&actionAddComment, tr("Add Comment"),
SLOT(on_actionAddComment_triggered()), getCommentSequence());
addAction(&actionAddComment);
@ -388,6 +388,11 @@ QKeySequence DisassemblyContextMenu::getCommentSequence() const
return {Qt::Key_Semicolon};
}
QKeySequence DisassemblyContextMenu::getCopyAddressSequence() const
{
return {Qt::CTRL + Qt::SHIFT + Qt::Key_C};
}
QKeySequence DisassemblyContextMenu::getSetToCodeSequence() const
{
return {Qt::Key_C};

View File

@ -79,6 +79,7 @@ private slots:
private:
QKeySequence getCopySequence() const;
QKeySequence getCommentSequence() const;
QKeySequence getCopyAddressSequence() const;
QKeySequence getSetToCodeSequence() const;
QKeySequence getSetAsStringSequence() const;
QKeySequence getSetToDataSequence() const;

View File

@ -13,6 +13,7 @@
#include <QClipboard>
#include <QScrollBar>
#include <QInputDialog>
#include <QShortcut>
HexdumpWidget::HexdumpWidget(MainWindow *main, QAction *action) :
MemoryDockWidget(CutterCore::MemoryWidgetType::Hexdump, main, action),
@ -37,6 +38,11 @@ HexdumpWidget::HexdumpWidget(MainWindow *main, QAction *action) :
//connect(ui->hexHexText, SIGNAL(cursorPositionChanged()), this, SLOT(highlightHexCurrentLine()));
//highlightHexCurrentLine();
auto cpyAddrShortcut = new QShortcut(QKeySequence{Qt::CTRL + Qt::SHIFT + Qt::Key_C}, this);
cpyAddrShortcut->setContext(Qt::WidgetWithChildrenShortcut);
ui->actionCopyAddressAtCursor->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_C);
connect(cpyAddrShortcut, &QShortcut::activated, this, &HexdumpWidget::on_actionCopyAddressAtCursor_triggered);
ui->copyMD5->setIcon(QIcon(":/img/icons/copy.svg"));
ui->copySHA1->setIcon(QIcon(":/img/icons/copy.svg"));
@ -621,6 +627,11 @@ void HexdumpWidget::showHexdumpContextMenu(const QPoint &pt)
// Set Hexdump popup menu
QMenu *menu = ui->hexHexText->createStandardContextMenu();
menu->clear();
menu->addAction(ui->actionCopyAddressAtCursor);
menu->addSeparator();
/*menu->addAction(ui->actionHexCopy_Hexpair);
menu->addAction(ui->actionHexCopy_ASCII);
menu->addAction(ui->actionHexCopy_Text);
@ -983,6 +994,14 @@ void HexdumpWidget::scrollChanged()
* Actions callback functions
*/
void HexdumpWidget::on_actionCopyAddressAtCursor_triggered()
{
auto addr = hexPositionToAddress(ui->hexHexText->textCursor().position());
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(RAddressString(addr));
}
void HexdumpWidget::on_actionHideHexdump_side_panel_triggered()
{
if (ui->hexSideTab_2->isVisible()) {

View File

@ -137,6 +137,8 @@ private slots:
void on_parseTypeComboBox_currentTextChanged(const QString &arg1);
void on_parseEndianComboBox_currentTextChanged(const QString &arg1);
void on_actionCopyAddressAtCursor_triggered();
void on_action1column_triggered();
void on_action2columns_triggered();
void on_action4columns_triggered();

View File

@ -764,6 +764,14 @@
<string>Copy Text</string>
</property>
</action>
<action name="actionCopyAddressAtCursor">
<property name="text">
<string>Copy Address</string>
</property>
<property name="toolTip">
<string>Copy Address at Cursor</string>
</property>
</action>
<action name="action1column">
<property name="text">
<string>1</string>