Skip to content

Commit 51f53ee

Browse files
committed
GUI: implement all the missing SourceView features from before
1 parent 4af8ff6 commit 51f53ee

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

src/gui/Src/Gui/SourceView.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ SourceView::SourceView(QString path, duint addr, QWidget* parent)
2626
setupContextMenu();
2727

2828
connect(this, SIGNAL(contextMenuSignal(QPoint)), this, SLOT(contextMenuSlot(QPoint)));
29+
connect(this, SIGNAL(doubleClickedSignal()), this, SLOT(followDisassemblerSlot()));
30+
connect(this, SIGNAL(enterPressedSignal()), this, SLOT(followDisassemblerSlot()));
2931

3032
Initialize();
3133

@@ -116,9 +118,35 @@ void SourceView::contextMenuSlot(const QPoint & pos)
116118
void SourceView::followDisassemblerSlot()
117119
{
118120
duint addr = addrFromIndex(getInitialSelection());
121+
if(!DbgMemIsValidReadPtr(addr))
122+
return;
119123
DbgCmdExec(QString("disasm %1").arg(ToPtrString(addr)).toUtf8().constData());
120124
}
121125

126+
void SourceView::followDumpSlot()
127+
{
128+
duint addr = addrFromIndex(getInitialSelection());
129+
if(!DbgMemIsValidReadPtr(addr))
130+
return;
131+
DbgCmdExec(QString("dump %1").arg(ToPtrString(addr)).toUtf8().constData());
132+
}
133+
134+
void SourceView::toggleBookmarkSlot()
135+
{
136+
duint addr = addrFromIndex(getInitialSelection());
137+
if(!DbgMemIsValidReadPtr(addr))
138+
return;
139+
140+
bool result;
141+
if(DbgGetBookmarkAt(addr))
142+
result = DbgSetBookmarkAt(addr, false);
143+
else
144+
result = DbgSetBookmarkAt(addr, true);
145+
if(!result)
146+
SimpleErrorBox(this, tr("Error!"), tr("DbgSetBookmarkAt failed!"));
147+
GuiUpdateAllViews();
148+
}
149+
122150
void SourceView::gotoLineSlot()
123151
{
124152
bool ok = false;
@@ -150,9 +178,22 @@ void SourceView::setupContextMenu()
150178
{
151179
return DbgMemIsValidReadPtr(addrFromIndex(getInitialSelection()));
152180
});
181+
mMenuBuilder->addAction(makeAction(DIcon("dump.png"), tr("Follow in &Dump"), SLOT(followDumpSlot())), [this](QMenu*)
182+
{
183+
return DbgMemIsValidReadPtr(addrFromIndex(getInitialSelection()));
184+
});
185+
mMenuBuilder->addSeparator();
186+
mBreakpointMenu = new BreakpointMenu(this, getActionHelperFuncs(), [this]()
187+
{
188+
return addrFromIndex(getInitialSelection());
189+
});
190+
mBreakpointMenu->build(mMenuBuilder);
191+
mMenuBuilder->addAction(makeShortcutAction(DIcon("bookmark_toggle.png"), tr("Toggle Bookmark"), SLOT(toggleBookmarkSlot()), "ActionToggleBookmark"));
192+
mMenuBuilder->addSeparator();
153193
mMenuBuilder->addAction(makeShortcutAction(DIcon("geolocation-goto.png"), tr("Go to line"), SLOT(gotoLineSlot()), "ActionGotoExpression"));
154194
mMenuBuilder->addAction(makeAction(DIcon("source.png"), tr("Open source file"), SLOT(openSourceFileSlot())));
155195
mMenuBuilder->addAction(makeAction(DIcon("source_show_in_folder.png"), tr("Show source file in directory"), SLOT(showInDirectorySlot())));
196+
mMenuBuilder->addSeparator();
156197
MenuBuilder* copyMenu = new MenuBuilder(this);
157198
setupCopyColumnMenu(copyMenu);
158199
mMenuBuilder->addMenu(makeMenu(DIcon("copy.png"), tr("&Copy")), copyMenu);

src/gui/Src/Gui/SourceView.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <QWidget>
55
#include <AbstractStdTable.h>
6+
#include "BreakpointMenu.h"
67

78
class FileLines;
89

@@ -25,12 +26,15 @@ class SourceView : public AbstractStdTable
2526
private slots:
2627
void contextMenuSlot(const QPoint & pos);
2728
void followDisassemblerSlot();
29+
void followDumpSlot();
30+
void toggleBookmarkSlot();
2831
void gotoLineSlot();
2932
void openSourceFileSlot();
3033
void showInDirectorySlot();
3134

3235
private:
3336
MenuBuilder* mMenuBuilder = nullptr;
37+
BreakpointMenu* mBreakpointMenu = nullptr;
3438
QString mSourcePath;
3539
duint mModBase;
3640
int mTabSize = 4; //TODO: make customizable?

src/gui/Src/Gui/SourceViewerManager.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ void SourceViewerManager::loadSourceFile(QString path, duint addr)
2828
SourceView* curView = (SourceView*)this->widget(i);
2929
if(curView->getSourcePath().compare(path, Qt::CaseInsensitive) == 0) //file already loaded
3030
{
31-
QWidget* now = QApplication::focusWidget();
3231
curView->setSelection(addr);
3332
setCurrentIndex(i); //show that loaded tab
34-
if(now)
35-
now->setFocus();
33+
QTimer::singleShot(50, [curView]()
34+
{
35+
curView->setFocus();
36+
});
3637
return;
3738
}
3839
}

src/gui/Src/Utils/Configuration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ Configuration::Configuration() : QObject(), noMoreMsgbox(false)
285285
insertMenuBuilderBools(&guiBool, "CallStackView", 50); //CallStackView
286286
insertMenuBuilderBools(&guiBool, "ThreadView", 50); //Thread
287287
insertMenuBuilderBools(&guiBool, "CPUStack", 50); //Stack
288-
insertMenuBuilderBools(&guiBool, "SourceView", 10); //Source
288+
insertMenuBuilderBools(&guiBool, "SourceView", 50); //Source
289289
insertMenuBuilderBools(&guiBool, "DisassemblerGraphView", 50); //Graph
290290
insertMenuBuilderBools(&guiBool, "XrefBrowseDialog", 10); //XrefBrowseDialog
291291
insertMenuBuilderBools(&guiBool, "StructWidget", 8); //StructWidget

0 commit comments

Comments
 (0)