1
0
Fork 0

GUI: Comments and labels in graph view (#1229)

This commit is contained in:
kkthx 2016-11-07 22:06:37 +01:00 committed by Duncan Ogilvie
parent 3a7726015f
commit afabd01f77
3 changed files with 54 additions and 0 deletions

View File

@ -1488,6 +1488,8 @@ void DisassemblerGraphView::setupContextMenu()
});
mMenuBuilder->addSeparator();
mMenuBuilder->addAction(mToggleOverview = makeShortcutAction(DIcon("comment.png"), tr("&Comment"), SLOT(setCommentSlot()), "ActionGraphComment"));
mMenuBuilder->addAction(mToggleOverview = makeShortcutAction(DIcon("label.png"), tr("&Label"), SLOT(setLabelSlot()), "ActionGraphLabel"));
mMenuBuilder->addAction(mToggleOverview = makeShortcutAction(tr("&Save as image"), SLOT(saveImageSlot()), "ActionGraphSaveImage"));
mMenuBuilder->addAction(mToggleOverview = makeShortcutAction(DIcon("graph.png"), tr("&Overview"), SLOT(toggleOverviewSlot()), "ActionGraphToggleOverview"));
mMenuBuilder->addAction(mToggleSyncOrigin = makeShortcutAction(DIcon("lock.png"), tr("&Sync with origin"), SLOT(toggleSyncOriginSlot()), "ActionGraphSyncOrigin"));
@ -1623,3 +1625,50 @@ void DisassemblerGraphView::saveImageSlot()
saveGraph = true;
this->viewport()->update();
}
void DisassemblerGraphView::setCommentSlot()
{
duint wVA = this->get_cursor_pos();
LineEditDialog mLineEdit(this);
QString addr_text = ToPtrString(wVA);
char comment_text[MAX_COMMENT_SIZE] = "";
if(DbgGetCommentAt((duint)wVA, comment_text))
{
if(comment_text[0] == '\1') //automatic comment
mLineEdit.setText(QString(comment_text + 1));
else
mLineEdit.setText(QString(comment_text));
}
mLineEdit.setWindowTitle(tr("Add comment at ") + addr_text);
if(mLineEdit.exec() != QDialog::Accepted)
return;
if(!DbgSetCommentAt(wVA, mLineEdit.editText.replace('\r', "").replace('\n', "").toUtf8().constData()))
SimpleErrorBox(this, tr("Error!"), tr("DbgSetCommentAt failed!"));
this->refreshSlot();
}
void DisassemblerGraphView::setLabelSlot()
{
duint wVA = this->get_cursor_pos();
LineEditDialog mLineEdit(this);
QString addr_text = ToPtrString(wVA);
char label_text[MAX_COMMENT_SIZE] = "";
if(DbgGetLabelAt((duint)wVA, SEG_DEFAULT, label_text))
mLineEdit.setText(QString(label_text));
mLineEdit.setWindowTitle(tr("Add label at ") + addr_text);
if(mLineEdit.exec() != QDialog::Accepted)
return;
if(!DbgSetLabelAt(wVA, mLineEdit.editText.toUtf8().constData()))
SimpleErrorBox(this, tr("Error!"), tr("DbgSetLabelAt failed!"));
this->refreshSlot();
}

View File

@ -15,6 +15,7 @@
#include <algorithm>
#include <QMutex>
#include "Bridge.h"
#include "LineEditDialog.h"
#include "RichTextPainter.h"
#include "QBeaEngine.h"
@ -272,6 +273,8 @@ public slots:
void toggleSyncOriginSlot();
void refreshSlot();
void saveImageSlot();
void setCommentSlot();
void setLabelSlot();
private:
QString status;

View File

@ -484,6 +484,8 @@ Configuration::Configuration() : QObject(), noMoreMsgbox(false)
defaultShortcuts.insert("ActionRefresh", Shortcut(tr("Actions -> Refresh"), "F5"));
defaultShortcuts.insert("ActionGraph", Shortcut(tr("Actions -> Graph"), "G"));
defaultShortcuts.insert("ActionGraphFollowDisassembler", Shortcut(tr("Actions -> Graph -> Follow in disassembler"), "Shift+Return"));
defaultShortcuts.insert("ActionGraphComment", Shortcut(tr("Actions -> Graph -> Comment"), ";"));
defaultShortcuts.insert("ActionGraphLabel", Shortcut(tr("Actions -> Graph -> Label"), ":"));
defaultShortcuts.insert("ActionGraphSaveImage", Shortcut(tr("Actions -> Graph -> Save as image"), "I"));
defaultShortcuts.insert("ActionGraphToggleOverview", Shortcut(tr("Actions -> Graph -> Toggle overview"), "O"));
defaultShortcuts.insert("ActionGraphRefresh", Shortcut(tr("Actions -> Graph -> Refresh"), "R"));