mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-20 11:56:12 +00:00
Added Context Menu to Strings Widget (#817)
* Added Context Menu to Strigns Widget * Fixed slot getting called twice without Qt::UniqueConnection
This commit is contained in:
parent
781235ba87
commit
3dc71c90d2
@ -6,7 +6,10 @@
|
|||||||
|
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "utils/Helpers.h"
|
#include "utils/Helpers.h"
|
||||||
|
#include "dialogs/XrefsDialog.h"
|
||||||
|
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QClipboard>
|
||||||
|
|
||||||
StringsModel::StringsModel(QList<StringDescription> *strings, QObject *parent)
|
StringsModel::StringsModel(QList<StringDescription> *strings, QObject *parent)
|
||||||
: QAbstractListModel(parent),
|
: QAbstractListModel(parent),
|
||||||
@ -142,6 +145,17 @@ StringsWidget::StringsWidget(MainWindow *main, QAction *action) :
|
|||||||
connect(clear_shortcut, &QShortcut::activated, ui->quickFilterView, &QuickFilterView::clearFilter);
|
connect(clear_shortcut, &QShortcut::activated, ui->quickFilterView, &QuickFilterView::clearFilter);
|
||||||
clear_shortcut->setContext(Qt::WidgetWithChildrenShortcut);
|
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);
|
model = new StringsModel(&strings, this);
|
||||||
proxy_model = new StringsSortFilterProxyModel(model, this);
|
proxy_model = new StringsSortFilterProxyModel(model, this);
|
||||||
ui->stringsTreeView->setModel(proxy_model);
|
ui->stringsTreeView->setModel(proxy_model);
|
||||||
@ -195,3 +209,46 @@ void StringsWidget::stringSearchFinished(const QList<StringDescription> &strings
|
|||||||
|
|
||||||
task = nullptr;
|
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<StringDescription>();
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
@ -70,6 +70,10 @@ private slots:
|
|||||||
void refreshStrings();
|
void refreshStrings();
|
||||||
void stringSearchFinished(const QList<StringDescription> &strings);
|
void stringSearchFinished(const QList<StringDescription> &strings);
|
||||||
|
|
||||||
|
void showStringsContextMenu(const QPoint &pt);
|
||||||
|
void on_actionX_refs_triggered();
|
||||||
|
void on_actionCopy();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Ui::StringsWidget> ui;
|
std::unique_ptr<Ui::StringsWidget> ui;
|
||||||
|
|
||||||
|
@ -71,6 +71,26 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<action name="actionCopy_Address">
|
||||||
|
<property name="text">
|
||||||
|
<string>Copy Address</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionCopy_String">
|
||||||
|
<property name="text">
|
||||||
|
<string>Copy String</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionX_refs">
|
||||||
|
<property name="text">
|
||||||
|
<string>Xrefs</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionFilter">
|
||||||
|
<property name="text">
|
||||||
|
<string>Filter</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
Loading…
Reference in New Issue
Block a user