From 954fbc0a236ead64f568e9f591a5248c742084a0 Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Mon, 16 Feb 2015 13:16:03 +0100 Subject: [PATCH] Renaming functions It's now possible to arbitrarily rename functions. Currently only the name displayed in the sidebar is updated. --- CMakeLists.txt | 2 ++ src/gui/Mainwindow.cxx | 21 +++++++++++++++---- src/gui/Mainwindow.hxx | 1 + src/gui/dialogs/RenameFunctionDialog.cxx | 26 ++++++++++++++++++++++++ src/gui/dialogs/RenameFunctionDialog.hxx | 11 ++++++++++ 5 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 src/gui/dialogs/RenameFunctionDialog.cxx create mode 100644 src/gui/dialogs/RenameFunctionDialog.hxx diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b42ebe..1d811d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,7 @@ SET(frida_SOURCES src/gui/widgets/CFGScene.cxx src/gui/widgets/ScriptingDock.cxx src/gui/dialogs/NewFunctionDialog.cxx + src/gui/dialogs/RenameFunctionDialog.cxx src/disassembler/Disassembler.cxx src/disassembler/llvm/LLVMDisassembler.cxx ) @@ -59,6 +60,7 @@ SET(frida_HEADERS src/gui/widgets/CFGScene.hxx src/gui/widgets/ScriptingDock.hxx src/gui/dialogs/NewFunctionDialog.hxx + src/gui/dialogs/RenameFunctionDialog.hxx src/disassembler/llvm/LLVMDisassembler.hxx src/disassembler/Disassembler.hxx ) diff --git a/src/gui/Mainwindow.cxx b/src/gui/Mainwindow.cxx index 0f2486d..611f3da 100644 --- a/src/gui/Mainwindow.cxx +++ b/src/gui/Mainwindow.cxx @@ -4,6 +4,7 @@ #include "widgets/CFGScene.hxx" #include "dialogs/NewFunctionDialog.hxx" +#include "dialogs/RenameFunctionDialog.hxx" #include @@ -99,15 +100,15 @@ void Mainwindow::switchMainPlane(int index) { void Mainwindow::showListContextMenu(const QPoint& point) { QListWidgetItem * item = listWidget->itemAt(point); + QMenu menu(this); if (item) { - LOG4CXX_DEBUG(logger, "WOHO " << item->text().toStdString()); + QAction * act = menu.addAction("Rename Function"); + connect(act, &QAction::triggered, [=]() {this->renameFunction(item);}); } else { - QMenu menu(this); QAction * act = menu.addAction("AddFunction"); connect(act, SIGNAL(triggered()), this, SLOT(requestNewFunction())); - - menu.exec(listWidget->mapToGlobal(point)); } + menu.exec(listWidget->mapToGlobal(point)); } void Mainwindow::requestNewFunction() { @@ -121,6 +122,18 @@ void Mainwindow::requestNewFunction() { } } +void Mainwindow::renameFunction(QListWidgetItem * item) { + RenameFunctionDialog dialog; + int result = dialog.exec(); + if (QDialog::Accepted == result) { + LOG4CXX_DEBUG(logger, "renaming Function" << item->text().toStdString() + << " to " << dialog.result().toStdString()); + item->setText(dialog.result()); + } else { + LOG4CXX_DEBUG(logger, "renameFunction aborted"); + } +} + void Mainwindow::addFunction(Function* fun) { if (functions.find(fun) != functions.end()) return; diff --git a/src/gui/Mainwindow.hxx b/src/gui/Mainwindow.hxx index 14d41b3..a78b446 100644 --- a/src/gui/Mainwindow.hxx +++ b/src/gui/Mainwindow.hxx @@ -54,6 +54,7 @@ private Q_SLOTS: void switchMainPlane(int); void showListContextMenu(const QPoint&); void requestNewFunction(); + void renameFunction(QListWidgetItem * item); }; #endif /* INCLUDE__Mainwindow_hxx_ */ diff --git a/src/gui/dialogs/RenameFunctionDialog.cxx b/src/gui/dialogs/RenameFunctionDialog.cxx new file mode 100644 index 0000000..1cd6ceb --- /dev/null +++ b/src/gui/dialogs/RenameFunctionDialog.cxx @@ -0,0 +1,26 @@ +#include "RenameFunctionDialog.hxx" + +RenameFunctionDialog::RenameFunctionDialog() { + QGridLayout * layout = new QGridLayout; + + edit = new QLineEdit; + layout->addWidget(edit, 0, 0, 1, 2); + + QPushButton * cancelButton = new QPushButton("Cancel"); + QPushButton * okButton = new QPushButton("OK"); + layout->addWidget(okButton, 1, 1, 1, 1); + connect(okButton, SIGNAL(clicked()), + this, SLOT(accept())); + layout->addWidget(cancelButton, 1, 0, 1, 1); + connect(cancelButton, SIGNAL(clicked()), + this, SLOT(reject())); + + setLayout(layout); + setWindowTitle("Add function"); +} + +QString RenameFunctionDialog::result() { + bool ok; + QString result = edit->text(); + return result; +} diff --git a/src/gui/dialogs/RenameFunctionDialog.hxx b/src/gui/dialogs/RenameFunctionDialog.hxx new file mode 100644 index 0000000..8c02828 --- /dev/null +++ b/src/gui/dialogs/RenameFunctionDialog.hxx @@ -0,0 +1,11 @@ +#include "gui/qt.hxx" + +class RenameFunctionDialog : public QDialog { + Q_OBJECT +public: + RenameFunctionDialog(); + + QString result(); +private: + QLineEdit * edit; +}; -- 2.39.5