diff --git a/src/Cutter.cpp b/src/Cutter.cpp index c43ec761..eade247f 100644 --- a/src/Cutter.cpp +++ b/src/Cutter.cpp @@ -324,6 +324,12 @@ void CutterCore::delFlag(RVA addr) emit flagsChanged(); } +void CutterCore::delFlag(const QString &name) +{ + cmdRaw("f-" + name); + emit flagsChanged(); +} + void CutterCore::editInstruction(RVA addr, const QString &inst) { cmd("wa " + inst + " @ " + RAddressString(addr)); diff --git a/src/Cutter.h b/src/Cutter.h index 770dfcbf..690a4aac 100644 --- a/src/Cutter.h +++ b/src/Cutter.h @@ -305,6 +305,7 @@ public: void delFunction(RVA addr); void renameFlag(QString old_name, QString new_name); void delFlag(RVA addr); + void delFlag(const QString &name); void editInstruction(RVA addr, const QString &inst); void nopInstruction(RVA addr); diff --git a/src/widgets/FlagsWidget.cpp b/src/widgets/FlagsWidget.cpp index 0e8b81a0..cb762bd7 100644 --- a/src/widgets/FlagsWidget.cpp +++ b/src/widgets/FlagsWidget.cpp @@ -1,9 +1,12 @@ #include #include #include +#include + #include "FlagsWidget.h" #include "ui_FlagsWidget.h" #include "MainWindow.h" +#include "dialogs/RenameDialog.h" #include "utils/Helpers.h" FlagsModel::FlagsModel(QList *flags, QObject *parent) @@ -139,6 +142,9 @@ FlagsWidget::FlagsWidget(MainWindow *main, QWidget *parent) : setScrollMode(); + ui->flagsTreeView->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->flagsTreeView, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(showContextMenu(const QPoint &))); + connect(Core(), SIGNAL(flagsChanged()), this, SLOT(flagsChanged())); connect(Core(), SIGNAL(refreshAll()), this, SLOT(refreshFlagspaces())); } @@ -158,6 +164,35 @@ void FlagsWidget::on_flagspaceCombo_currentTextChanged(const QString &arg1) refreshFlags(); } +void FlagsWidget::on_actionRename_triggered() +{ + FlagDescription flag = ui->flagsTreeView->selectionModel()->currentIndex().data(FlagsModel::FlagDescriptionRole).value(); + + RenameDialog *r = new RenameDialog(this); + r->setName(flag.name); + if (r->exec()) + { + QString new_name = r->getName(); + CutterCore::getInstance()->renameFlag(flag.name, new_name); + } +} + +void FlagsWidget::on_actionDelete_triggered() +{ + FlagDescription flag = ui->flagsTreeView->selectionModel()->currentIndex().data(FlagsModel::FlagDescriptionRole).value(); + Core()->delFlag(flag.name); +} + +void FlagsWidget::showContextMenu(const QPoint &pt) +{ + QMenu *menu = new QMenu(ui->flagsTreeView); + menu->addAction(ui->actionRename); + menu->addAction(ui->actionDelete); + menu->exec(ui->flagsTreeView->mapToGlobal(pt)); + delete menu; +} + + void FlagsWidget::flagsChanged() { refreshFlagspaces(); diff --git a/src/widgets/FlagsWidget.h b/src/widgets/FlagsWidget.h index 153a7cac..9a34cdaf 100644 --- a/src/widgets/FlagsWidget.h +++ b/src/widgets/FlagsWidget.h @@ -69,6 +69,11 @@ private slots: void on_flagsTreeView_doubleClicked(const QModelIndex &index); void on_flagspaceCombo_currentTextChanged(const QString &arg1); + void on_actionRename_triggered(); + void on_actionDelete_triggered(); + + void showContextMenu(const QPoint &pt); + void flagsChanged(); void refreshFlagspaces(); diff --git a/src/widgets/FlagsWidget.ui b/src/widgets/FlagsWidget.ui index 438edb4d..24f43c42 100644 --- a/src/widgets/FlagsWidget.ui +++ b/src/widgets/FlagsWidget.ui @@ -94,6 +94,16 @@ + + + Rename + + + + + Delete + +