mirror of
https://github.com/rizinorg/cutter.git
synced 2025-02-21 22:23:46 +00:00
Add rename X used here
This commit is contained in:
parent
f80cf8eb03
commit
baea88d744
@ -15,6 +15,7 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent)
|
|||||||
actionAddComment(this),
|
actionAddComment(this),
|
||||||
actionAddFlag(this),
|
actionAddFlag(this),
|
||||||
actionRename(this),
|
actionRename(this),
|
||||||
|
actionRenameUsedHere(this),
|
||||||
actionXRefs(this),
|
actionXRefs(this),
|
||||||
actionDisplayOptions(this),
|
actionDisplayOptions(this),
|
||||||
actionSetBaseBinary(this),
|
actionSetBaseBinary(this),
|
||||||
@ -37,11 +38,15 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent)
|
|||||||
|
|
||||||
actionAddFlag.setText(tr("Add Flag"));
|
actionAddFlag.setText(tr("Add Flag"));
|
||||||
this->addAction(&actionAddFlag);
|
this->addAction(&actionAddFlag);
|
||||||
actionAddComment.setShortcut(getAddFlagSequence());
|
actionAddFlag.setShortcut(getAddFlagSequence());
|
||||||
|
|
||||||
actionRename.setText(tr("Rename"));
|
actionRename.setText(tr("Rename"));
|
||||||
this->addAction(&actionRename);
|
this->addAction(&actionRename);
|
||||||
actionAddComment.setShortcut(getRenameSequence());
|
actionRename.setShortcut(getRenameSequence());
|
||||||
|
|
||||||
|
actionRenameUsedHere.setText(("Rename Flag/Fcn/Var Used Here"));
|
||||||
|
this->addAction(&actionRenameUsedHere);
|
||||||
|
actionRenameUsedHere.setShortcut(getRenameUsedHereSequence());
|
||||||
|
|
||||||
setBaseMenu = new QMenu(tr("Set Immediate Base to..."), this);
|
setBaseMenu = new QMenu(tr("Set Immediate Base to..."), this);
|
||||||
setBaseMenuAction = addMenu(setBaseMenu);
|
setBaseMenuAction = addMenu(setBaseMenu);
|
||||||
@ -65,50 +70,35 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent)
|
|||||||
this->addSeparator();
|
this->addSeparator();
|
||||||
actionXRefs.setText(tr("Show X-Refs"));
|
actionXRefs.setText(tr("Show X-Refs"));
|
||||||
this->addAction(&actionXRefs);
|
this->addAction(&actionXRefs);
|
||||||
actionAddComment.setShortcut(getXRefSequence());
|
actionXRefs.setShortcut(getXRefSequence());
|
||||||
|
|
||||||
this->addSeparator();
|
this->addSeparator();
|
||||||
actionDisplayOptions.setText(tr("Show Options"));
|
actionDisplayOptions.setText(tr("Show Options"));
|
||||||
actionAddComment.setShortcut(getDisplayOptionsSequence());
|
actionDisplayOptions.setShortcut(getDisplayOptionsSequence());
|
||||||
this->addAction(&actionDisplayOptions);
|
this->addAction(&actionDisplayOptions);
|
||||||
|
|
||||||
auto pWidget = parentWidget();
|
auto pWidget = parentWidget();
|
||||||
|
|
||||||
QShortcut *shortcut_Copy = new QShortcut(getCopySequence(), pWidget);
|
#define ADD_SHORTCUT(sequence, slot) { \
|
||||||
shortcut_Copy->setContext(Qt::WidgetWithChildrenShortcut);
|
QShortcut *shortcut = new QShortcut((sequence), pWidget); \
|
||||||
connect(shortcut_Copy, &QShortcut::activated,
|
shortcut->setContext(Qt::WidgetWithChildrenShortcut); \
|
||||||
this, &DisassemblyContextMenu::on_actionCopy_triggered);
|
connect(shortcut, &QShortcut::activated, this, (slot)); \
|
||||||
|
}
|
||||||
QShortcut *shortcut_dispOptions = new QShortcut(getDisplayOptionsSequence(), pWidget);
|
ADD_SHORTCUT(getCopySequence(), &DisassemblyContextMenu::on_actionCopy_triggered);
|
||||||
shortcut_dispOptions->setContext(Qt::WidgetWithChildrenShortcut);
|
ADD_SHORTCUT(getDisplayOptionsSequence(), &DisassemblyContextMenu::on_actionDisplayOptions_triggered);
|
||||||
connect(shortcut_dispOptions, &QShortcut::activated,
|
ADD_SHORTCUT(getXRefSequence(), &DisassemblyContextMenu::on_actionXRefs_triggered);
|
||||||
this, &DisassemblyContextMenu::on_actionDisplayOptions_triggered);
|
ADD_SHORTCUT(getCommentSequence(), &DisassemblyContextMenu::on_actionAddComment_triggered);
|
||||||
|
ADD_SHORTCUT(getAddFlagSequence(), &DisassemblyContextMenu::on_actionAddFlag_triggered);
|
||||||
QShortcut *shortcut_x = new QShortcut(getXRefSequence(), pWidget);
|
ADD_SHORTCUT(getRenameSequence(), &DisassemblyContextMenu::on_actionRename_triggered);
|
||||||
shortcut_x->setContext(Qt::WidgetWithChildrenShortcut);
|
ADD_SHORTCUT(getRenameUsedHereSequence(), &DisassemblyContextMenu::on_actionRenameUsedHere_triggered);
|
||||||
connect(shortcut_x, &QShortcut::activated,
|
#undef ADD_SHORTCUT
|
||||||
this, &DisassemblyContextMenu::on_actionXRefs_triggered);
|
|
||||||
|
|
||||||
QShortcut *shortcut_comment = new QShortcut(getCommentSequence(), pWidget);
|
|
||||||
shortcut_comment->setContext(Qt::WidgetWithChildrenShortcut);
|
|
||||||
connect(shortcut_comment, &QShortcut::activated,
|
|
||||||
this, &DisassemblyContextMenu::on_actionAddComment_triggered);
|
|
||||||
|
|
||||||
QShortcut *shortcut_addFlag = new QShortcut(getAddFlagSequence(), pWidget);
|
|
||||||
shortcut_addFlag->setContext(Qt::WidgetWithChildrenShortcut);
|
|
||||||
connect(shortcut_addFlag, &QShortcut::activated,
|
|
||||||
this, &DisassemblyContextMenu::on_actionAddFlag_triggered);
|
|
||||||
|
|
||||||
QShortcut *shortcut_renameSequence = new QShortcut(getRenameSequence(), pWidget);
|
|
||||||
shortcut_renameSequence->setContext(Qt::WidgetWithChildrenShortcut);
|
|
||||||
connect(shortcut_renameSequence, &QShortcut::activated,
|
|
||||||
this, &DisassemblyContextMenu::on_actionRename_triggered);
|
|
||||||
|
|
||||||
connect(&actionCopy, SIGNAL(triggered(bool)), this, SLOT(on_actionCopy_triggered()));
|
connect(&actionCopy, SIGNAL(triggered(bool)), this, SLOT(on_actionCopy_triggered()));
|
||||||
|
|
||||||
connect(&actionAddComment, SIGNAL(triggered(bool)), this, SLOT(on_actionAddComment_triggered()));
|
connect(&actionAddComment, SIGNAL(triggered(bool)), this, SLOT(on_actionAddComment_triggered()));
|
||||||
connect(&actionAddFlag, SIGNAL(triggered(bool)), this, SLOT(on_actionAddFlag_triggered()));
|
connect(&actionAddFlag, SIGNAL(triggered(bool)), this, SLOT(on_actionAddFlag_triggered()));
|
||||||
connect(&actionRename, SIGNAL(triggered(bool)), this, SLOT(on_actionRename_triggered()));
|
connect(&actionRename, SIGNAL(triggered(bool)), this, SLOT(on_actionRename_triggered()));
|
||||||
|
connect(&actionRenameUsedHere, SIGNAL(triggered(bool)), this, SLOT(on_actionRenameUsedHere_triggered()));
|
||||||
connect(&actionXRefs, SIGNAL(triggered(bool)), this, SLOT(on_actionXRefs_triggered()));
|
connect(&actionXRefs, SIGNAL(triggered(bool)), this, SLOT(on_actionXRefs_triggered()));
|
||||||
connect(&actionDisplayOptions, SIGNAL(triggered()), this, SLOT(on_actionDisplayOptions_triggered()));
|
connect(&actionDisplayOptions, SIGNAL(triggered()), this, SLOT(on_actionDisplayOptions_triggered()));
|
||||||
|
|
||||||
@ -174,6 +164,19 @@ void DisassemblyContextMenu::aboutToShowSlot()
|
|||||||
{
|
{
|
||||||
actionRename.setVisible(false);
|
actionRename.setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// only show "rename X used here" if there is something to rename
|
||||||
|
QString thingUsedHere = Core()->cmd("an @ " + QString::number(offset)).trimmed();
|
||||||
|
if (!thingUsedHere.isEmpty())
|
||||||
|
{
|
||||||
|
actionRenameUsedHere.setVisible(true);
|
||||||
|
actionRenameUsedHere.setText(tr("Rename \"%1\" (used here)").arg(thingUsedHere));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
actionRenameUsedHere.setVisible(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QKeySequence DisassemblyContextMenu::getCopySequence() const
|
QKeySequence DisassemblyContextMenu::getCopySequence() const
|
||||||
@ -196,6 +199,11 @@ QKeySequence DisassemblyContextMenu::getRenameSequence() const
|
|||||||
return {Qt::Key_N};
|
return {Qt::Key_N};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QKeySequence DisassemblyContextMenu::getRenameUsedHereSequence() const
|
||||||
|
{
|
||||||
|
return {Qt::SHIFT + Qt::Key_N};
|
||||||
|
}
|
||||||
|
|
||||||
QKeySequence DisassemblyContextMenu::getXRefSequence() const
|
QKeySequence DisassemblyContextMenu::getXRefSequence() const
|
||||||
{
|
{
|
||||||
return {Qt::Key_X};
|
return {Qt::Key_X};
|
||||||
@ -284,6 +292,23 @@ void DisassemblyContextMenu::on_actionRename_triggered()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DisassemblyContextMenu::on_actionRenameUsedHere_triggered()
|
||||||
|
{
|
||||||
|
QString thingUsedHere = Core()->cmd("an @ " + QString::number(offset)).trimmed();
|
||||||
|
if (thingUsedHere.isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RenameDialog *dialog = new RenameDialog(this);
|
||||||
|
dialog->setWindowTitle(tr("Rename %1").arg(thingUsedHere));
|
||||||
|
dialog->setName(thingUsedHere);
|
||||||
|
if (dialog->exec()) {
|
||||||
|
QString new_name = dialog->getName();
|
||||||
|
Core()->cmd("an " + new_name.trimmed() + " @ " + QString::number(offset));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DisassemblyContextMenu::on_actionXRefs_triggered()
|
void DisassemblyContextMenu::on_actionXRefs_triggered()
|
||||||
{
|
{
|
||||||
XrefsDialog *dialog = new XrefsDialog(this);
|
XrefsDialog *dialog = new XrefsDialog(this);
|
||||||
|
@ -28,6 +28,7 @@ private slots:
|
|||||||
void on_actionAddComment_triggered();
|
void on_actionAddComment_triggered();
|
||||||
void on_actionAddFlag_triggered();
|
void on_actionAddFlag_triggered();
|
||||||
void on_actionRename_triggered();
|
void on_actionRename_triggered();
|
||||||
|
void on_actionRenameUsedHere_triggered();
|
||||||
void on_actionXRefs_triggered();
|
void on_actionXRefs_triggered();
|
||||||
void on_actionDisplayOptions_triggered();
|
void on_actionDisplayOptions_triggered();
|
||||||
|
|
||||||
@ -45,6 +46,7 @@ private:
|
|||||||
QKeySequence getCommentSequence() const;
|
QKeySequence getCommentSequence() const;
|
||||||
QKeySequence getAddFlagSequence() const;
|
QKeySequence getAddFlagSequence() const;
|
||||||
QKeySequence getRenameSequence() const;
|
QKeySequence getRenameSequence() const;
|
||||||
|
QKeySequence getRenameUsedHereSequence() const;
|
||||||
QKeySequence getXRefSequence() const;
|
QKeySequence getXRefSequence() const;
|
||||||
QKeySequence getDisplayOptionsSequence() const;
|
QKeySequence getDisplayOptionsSequence() const;
|
||||||
|
|
||||||
@ -57,6 +59,7 @@ private:
|
|||||||
QAction actionAddComment;
|
QAction actionAddComment;
|
||||||
QAction actionAddFlag;
|
QAction actionAddFlag;
|
||||||
QAction actionRename;
|
QAction actionRename;
|
||||||
|
QAction actionRenameUsedHere;
|
||||||
QAction actionXRefs;
|
QAction actionXRefs;
|
||||||
QAction actionDisplayOptions;
|
QAction actionDisplayOptions;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user