From 3dc71c90d25247a2907511522e25ff843fed71fd Mon Sep 17 00:00:00 2001 From: Ankur Saini Date: Mon, 15 Oct 2018 14:36:15 +0530 Subject: [PATCH] Added Context Menu to Strings Widget (#817) * Added Context Menu to Strigns Widget * Fixed slot getting called twice without Qt::UniqueConnection --- src/widgets/StringsWidget.cpp | 57 +++++++++++++++++++++++++++++++++++ src/widgets/StringsWidget.h | 4 +++ src/widgets/StringsWidget.ui | 20 ++++++++++++ 3 files changed, 81 insertions(+) diff --git a/src/widgets/StringsWidget.cpp b/src/widgets/StringsWidget.cpp index 4bcfa388..efdc700b 100644 --- a/src/widgets/StringsWidget.cpp +++ b/src/widgets/StringsWidget.cpp @@ -6,7 +6,10 @@ #include "MainWindow.h" #include "utils/Helpers.h" +#include "dialogs/XrefsDialog.h" +#include +#include StringsModel::StringsModel(QList *strings, QObject *parent) : QAbstractListModel(parent), @@ -142,6 +145,17 @@ StringsWidget::StringsWidget(MainWindow *main, QAction *action) : connect(clear_shortcut, &QShortcut::activated, ui->quickFilterView, &QuickFilterView::clearFilter); clear_shortcut->setContext(Qt::WidgetWithChildrenShortcut); + connect(ui->actionFilter, SIGNAL(triggered()), ui->quickFilterView, SLOT(showFilter())); + connect(ui->actionCopy_String, SIGNAL(triggered()), this, SLOT(on_actionCopy())); + connect(ui->actionCopy_Address, SIGNAL(triggered()), this, SLOT(on_actionCopy())); + + connect(ui->stringsTreeView, SIGNAL(customContextMenuRequested(const QPoint &)), + this, SLOT(showStringsContextMenu(const QPoint &))); + + ui->actionFilter->setShortcut(QKeySequence::Find); + + ui->stringsTreeView->setContextMenuPolicy(Qt::CustomContextMenu); + model = new StringsModel(&strings, this); proxy_model = new StringsSortFilterProxyModel(model, this); ui->stringsTreeView->setModel(proxy_model); @@ -195,3 +209,46 @@ void StringsWidget::stringSearchFinished(const QList &strings task = nullptr; } + +void StringsWidget::showStringsContextMenu(const QPoint &pt) +{ + QMenu *menu = new QMenu(ui->stringsTreeView); + + menu->clear(); + menu->addAction(ui->actionCopy_String); + menu->addAction(ui->actionCopy_Address); + menu->addAction(ui->actionFilter); + menu->addSeparator(); + menu->addAction(ui->actionX_refs); + + menu->exec(ui->stringsTreeView->mapToGlobal(pt)); + + delete menu; +} + +void StringsWidget::on_actionX_refs_triggered() +{ + StringDescription str = ui->stringsTreeView->selectionModel()->currentIndex().data( + StringsModel::StringDescriptionRole).value(); + + XrefsDialog *x = new XrefsDialog(this); + x->fillRefsForAddress(str.vaddr, RAddressString(str.vaddr), false); + x->setAttribute(Qt::WA_DeleteOnClose); + x->exec(); +} + +void StringsWidget::on_actionCopy() +{ + QModelIndex current_item = ui->stringsTreeView->currentIndex(); + int row = current_item.row(); + + QModelIndex index; + + if(sender() == ui->actionCopy_String) + index = ui->stringsTreeView->model()->index(row, 1); + else if(sender() == ui->actionCopy_Address) + index = ui->stringsTreeView->model()->index(row, 0); + + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(index.data().toString()); +} diff --git a/src/widgets/StringsWidget.h b/src/widgets/StringsWidget.h index 7ae49b25..e7aa0725 100644 --- a/src/widgets/StringsWidget.h +++ b/src/widgets/StringsWidget.h @@ -70,6 +70,10 @@ private slots: void refreshStrings(); void stringSearchFinished(const QList &strings); + void showStringsContextMenu(const QPoint &pt); + void on_actionX_refs_triggered(); + void on_actionCopy(); + private: std::unique_ptr ui; diff --git a/src/widgets/StringsWidget.ui b/src/widgets/StringsWidget.ui index 7622b983..000c88f9 100644 --- a/src/widgets/StringsWidget.ui +++ b/src/widgets/StringsWidget.ui @@ -71,6 +71,26 @@ + + + Copy Address + + + + + Copy String + + + + + Xrefs + + + + + Filter + +