]> git.siccegge.de Git - frida/frida.git/commitdiff
Add option to comment on instructions (in GUI)
authorChristoph Egger <Christoph.Egger@fau.de>
Wed, 18 Feb 2015 15:38:18 +0000 (16:38 +0100)
committerChristoph Egger <Christoph.Egger@fau.de>
Wed, 18 Feb 2015 15:38:18 +0000 (16:38 +0100)
src/gui/Mainwindow.cxx
src/gui/dialogs/RenameFunctionDialog.cxx [deleted file]
src/gui/dialogs/RenameFunctionDialog.hxx [deleted file]
src/gui/dialogs/SimpleStringDialog.cxx [new file with mode: 0644]
src/gui/dialogs/SimpleStringDialog.hxx [new file with mode: 0644]
src/gui/widgets/BasicBlockWidget.cxx

index 70d31d509c33abf939ca44d9eef15f57eaebe7e5..18dcc8bef99f180c7a193962a2ac674709b9de75 100644 (file)
@@ -4,7 +4,7 @@
 
 #include "widgets/CFGScene.hxx"
 #include "dialogs/NewFunctionDialog.hxx"
-#include "dialogs/RenameFunctionDialog.hxx"
+#include "dialogs/SimpleStringDialog.hxx"
 
 #include <sstream>
 
@@ -140,7 +140,7 @@ void Mainwindow::requestNewFunctionByAddress(uint64_t address) {
 }
 
 void Mainwindow::renameFunction(QListWidgetItem * item) {
-       RenameFunctionDialog dialog;
+       SimpleStringDialog dialog("New name");
        int result = dialog.exec();
        if (QDialog::Accepted == result) {
                LOG4CXX_DEBUG(logger, "renaming Function " << item->text().toStdString()
diff --git a/src/gui/dialogs/RenameFunctionDialog.cxx b/src/gui/dialogs/RenameFunctionDialog.cxx
deleted file mode 100644 (file)
index 1cd6ceb..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-#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
deleted file mode 100644 (file)
index 8c02828..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-#include "gui/qt.hxx"
-
-class RenameFunctionDialog : public QDialog {
-       Q_OBJECT
-public:
-       RenameFunctionDialog();
-
-       QString result();
-private:
-       QLineEdit * edit;
-};
diff --git a/src/gui/dialogs/SimpleStringDialog.cxx b/src/gui/dialogs/SimpleStringDialog.cxx
new file mode 100644 (file)
index 0000000..8bea6e9
--- /dev/null
@@ -0,0 +1,26 @@
+#include "SimpleStringDialog.hxx"
+
+SimpleStringDialog::SimpleStringDialog(const QString& title) {
+       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(title);
+}
+
+QString SimpleStringDialog::result() {
+       bool ok;
+       QString result = edit->text();
+       return result;
+}
diff --git a/src/gui/dialogs/SimpleStringDialog.hxx b/src/gui/dialogs/SimpleStringDialog.hxx
new file mode 100644 (file)
index 0000000..4fbb26c
--- /dev/null
@@ -0,0 +1,11 @@
+#include "gui/qt.hxx"
+
+class SimpleStringDialog : public QDialog {
+       Q_OBJECT
+public:
+       SimpleStringDialog(const QString& title);
+
+       QString result();
+private:
+       QLineEdit * edit;
+};
index 586b7078efd8853041494b5f95fa06dc081ec70d..454119e25d11623738996f3f81dff2d504302877 100644 (file)
@@ -1,6 +1,7 @@
 #include "BasicBlockWidget.hxx"
 #include "CustomQGraphicsTextItem.hxx"
 #include "gui/Mainwindow.hxx"
+#include "gui/dialogs/SimpleStringDialog.hxx"
 
 class CustomQGraphicsTextItem : public QObject, public QGraphicsTextItem {
 public:
@@ -12,6 +13,20 @@ private:
        Mainwindow* mainwindow;
 };
 
+namespace {
+       void addComment(QTextTableCell cell, const QString& title) {
+               SimpleStringDialog dialog(title);
+               int result = dialog.exec();
+               if (QDialog::Accepted == result) {
+                       // LOG4CXX_DEBUG(logger, "adding comment " << dialog.result().toStdString()
+                       //               << " at row " << cell.row());
+                       cell.firstCursorPosition().insertHtml(QString(";; ") + dialog.result());
+               } else {
+                       // LOG4CXX_DEBUG(logger, "addComment aborted");
+               }
+       }
+}
+
 void CustomQGraphicsTextItem::contextMenuEvent(QGraphicsSceneContextMenuEvent* event) {
        QTextCursor c = textCursor();
        c.setPosition(document()->documentLayout()->hitTest(event->pos(), Qt::FuzzyHit));
@@ -25,6 +40,20 @@ void CustomQGraphicsTextItem::contextMenuEvent(QGraphicsSceneContextMenuEvent* e
                QObject::connect(act, &QAction::triggered,
                                 [=]() {mainwindow->requestNewFunctionByAddress(address);});
        }
+
+       QTextTable* table = c.currentTable();
+       if (NULL != table) {
+               int row = table->cellAt(c).row();
+               QTextTableCell cell = table->cellAt(row, 2);
+               QAction* globalComment = menu.addAction("Add global Comment");
+               QAction* localComment = menu.addAction("Add local Comment");
+
+               QObject::connect(globalComment, &QAction::triggered,
+                                [=]() { addComment(cell, "Global comment"); });
+               QObject::connect(localComment, &QAction::triggered,
+                                [=]() { addComment(cell, "Local comment"); });
+       }
+
        menu.exec(event->screenPos());
 }
 
@@ -81,15 +110,14 @@ void BasicBlockWidget::addItem(uint8_t* bytes, size_t num_bytes,
                                         mainwindow->switchMainPlaneToAddress(address.toInt(NULL, 16));
                                 }
                         });
+}
 
+void BasicBlockWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+                  QWidget *widget) {
        width = 10 + _widget->boundingRect().width();
        height = 25 + _widget->boundingRect().height();
-
        if (width < 250) width = 250;
-}
 
-void BasicBlockWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
-                  QWidget *widget) {
        painter->fillRect(0, 0, width, height, QColor(0xcc, 0xcc, 0xff, 0xff));
        painter->setPen(QColor(0x00, 0x00, 0xff, 0xff));
        painter->drawRect(0, 0, width, height);