Skip to content

Commit

Permalink
Raise/focus docks for Goto actions, and create them if UI edit mode i…
Browse files Browse the repository at this point in the history
…s enabled
  • Loading branch information
calc84maniac committed Aug 13, 2024
1 parent 9e1611d commit 282539c
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 13 deletions.
61 changes: 51 additions & 10 deletions gui/qt/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2004,23 +2004,54 @@ void MainWindow::gotoPressed() {

void MainWindow::gotoDisasmAddr(uint32_t address) {
disasmUpdateAddr(address, false);
raiseContainingDock(ui->disasm);
ui->disasm->setFocus();
}

QAction *MainWindow::gotoDisasmAction(QMenu *menu) {
QAction *gotoDisasm = menu->addAction(ACTION_GOTO_DISASM_VIEW);
gotoDisasm->setEnabled(m_uiEditMode || ui->debugDisassemblyWidget->isVisible());
return gotoDisasm;
}

void MainWindow::gotoMemAddr(uint32_t address) {
if (m_memWidget != Q_NULLPTR) {
memGoto(m_memWidget, address);
} else {
for (HexWidget *edit : { ui->flashEdit, ui->ramEdit }) {
HexWidget *memWidget = m_memWidget;
bool didGoto = false;
if (memWidget == Q_NULLPTR && !ui->debugMemoryWidget->isVisible()) {
memWidget = firstMemWidget();
}
if (memWidget == Q_NULLPTR) {
for (HexWidget *edit : ui->debugMemoryWidget->findChildren<HexWidget*>()) {
uint32_t offset = address - edit->getBase();
if (offset < edit->getSize()) {

Check warning on line 2026 in gui/qt/debugger.cpp

View workflow job for this annotation

GitHub Actions / Build: ubuntu-20.04 - Qt6-Dynamic

comparison of integer expressions of different signedness: ‘uint32_t’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]

Check warning on line 2026 in gui/qt/debugger.cpp

View workflow job for this annotation

GitHub Actions / Build: ubuntu-20.04 - Qt6

comparison of integer expressions of different signedness: ‘uint32_t’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]

Check warning on line 2026 in gui/qt/debugger.cpp

View workflow job for this annotation

GitHub Actions / Build: macos-12 Qt5_intel

comparison of integers of different signs: 'uint32_t' (aka 'unsigned int') and 'int' [-Wsign-compare]

Check warning on line 2026 in gui/qt/debugger.cpp

View workflow job for this annotation

GitHub Actions / Build: macos-13 Qt6_intel

comparison of integers of different signs: 'uint32_t' (aka 'unsigned int') and 'int' [-Wsign-compare]
edit->setFocus();
edit->setOffset(offset);
memWidget = edit;
didGoto = true;
break;
}
}
if (!didGoto) {
if (m_docksMemory.isEmpty() && m_uiEditMode) {
addMemDock(randomString(20), 8, true);
}
memWidget = firstMemWidget();
}
}
if (memWidget != Q_NULLPTR) {
if (!didGoto) {
memGoto(memWidget, address);
}
raiseContainingDock(memWidget);
memWidget->setFocus();
}
}

QAction *MainWindow::gotoMemAction(QMenu *menu, bool vat) {
QAction *gotoMem = menu->addAction(vat ? ACTION_GOTO_VAT_MEMORY_VIEW : ACTION_GOTO_MEMORY_VIEW);
gotoMem->setEnabled(m_uiEditMode || ui->debugMemoryWidget->isVisible() || !m_docksMemory.isEmpty());
return gotoMem;
}

void MainWindow::handleCtrlClickText(QPlainTextEdit *edit) {
if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier)) {
bool ok = true;
Expand Down Expand Up @@ -2552,7 +2583,7 @@ void MainWindow::contextOp(const QPoint &posa) {
QString data = obj->item(obj->selectionModel()->selectedRows().first().row(), obj->objectName() == QStringLiteral("opView") ? 2 : 1)->text();

QMenu menu;
QAction *gotoMem = menu.addAction(ACTION_GOTO_MEMORY_VIEW);
QAction *gotoMem = gotoMemAction(&menu);
QAction *copyAddr = menu.addAction(ACTION_COPY_ADDR);
menu.addSeparator();
QAction *copyData = menu.addAction(ACTION_COPY_DATA);
Expand All @@ -2579,17 +2610,17 @@ void MainWindow::contextVat(const QPoint &posa) {
QString vatAddr = obj->item(obj->selectionModel()->selectedRows().first().row(), VAT_VAT_ADDR_COL)->text();

QMenu menu;
QAction *gotoMem = menu.addAction(ACTION_GOTO_MEMORY_VIEW);
QAction *gotoVat = menu.addAction(ACTION_GOTO_VAT_MEMORY_VIEW);
QAction *gotoDisasm = menu.addAction(ACTION_GOTO_DISASM_VIEW);
QAction *gotoMem = gotoMemAction(&menu);
QAction *gotoVat = gotoMemAction(&menu, true);
QAction *gotoDisasm = gotoDisasmAction(&menu);

QAction *item = menu.exec(globalPos);
if (item == gotoMem) {
gotoMemAddr(hex2int(addr));
} else if (item == gotoVat) {
gotoMemAddr(hex2int(vatAddr));
} else if (item == gotoDisasm) {
disasmUpdateAddr(hex2int(addr) + 4, false);
gotoDisasmAddr(hex2int(addr) + 4);
}
}

Expand All @@ -2604,6 +2635,16 @@ void MainWindow::memDocksUpdate() {
}
}

HexWidget *MainWindow::firstMemWidget() {
if (!m_docksMemory.isEmpty()) {
QWidget *dock = findChild<QDockWidget*>(m_docksMemory.first());
if (dock != Q_NULLPTR) {
return dock->findChild<HexWidget*>();
}
}
return Q_NULLPTR;
}

//------------------------------------------------
// Stepping
//------------------------------------------------
Expand Down
17 changes: 14 additions & 3 deletions gui/qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,17 @@ bool MainWindow::redistributeDocks(const QPoint &pos, const QPoint &offset,
return false;
}

void MainWindow::raiseContainingDock(QWidget *widget) {
QWidget *dock = findSelfOrParent<QDockWidget*>(widget);
if (dock != Q_NULLPTR) {
if (m_uiEditMode) {
dock->show();
}
dock->activateWindow();
dock->raise();
}
}

void MainWindow::mouseDoubleClickEvent(QMouseEvent *event) {
if (!childAt(event->pos())) {
int sep = style()->pixelMetric(QStyle::PM_DockWidgetSeparatorExtent, Q_NULLPTR, this);
Expand Down Expand Up @@ -2489,7 +2500,7 @@ void MainWindow::contextDisasm(const QPoint &posa) {
QAction *toggleWrite = menu.addAction(ACTION_TOGGLE_WRITE);
QAction *toggleRw = menu.addAction(ACTION_TOGGLE_RW);
menu.addSeparator();
QAction *gotoMem = menu.addAction(ACTION_GOTO_MEMORY_VIEW);
QAction *gotoMem = gotoMemAction(&menu);
QAction *setPc = menu.addAction(tr("Set PC"));

QAction *item = menu.exec(globalPos);
Expand Down Expand Up @@ -2575,8 +2586,8 @@ void MainWindow::contextConsole(const QPoint &posa) {
ui->console->setTextCursor(cursor);

QMenu menu;
QAction *gotoMem = menu.addAction(ACTION_GOTO_MEMORY_VIEW);
QAction *gotoDisasm = menu.addAction(ACTION_GOTO_DISASM_VIEW);
QAction *gotoMem = gotoMemAction(&menu);
QAction *gotoDisasm = gotoDisasmAction(&menu);
menu.addSeparator();
QAction *toggleBreak = menu.addAction(ACTION_TOGGLE_BREAK);
QAction *toggleRead = menu.addAction(ACTION_TOGGLE_READ);
Expand Down
4 changes: 4 additions & 0 deletions gui/qt/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ class MainWindow : public QMainWindow {
// goto
void gotoPressed();
void gotoDisasmAddr(uint32_t addr);
QAction *gotoDisasmAction(QMenu *menu);
void gotoMemAddr(uint32_t addr);
QAction *gotoMemAction(QMenu *menu, bool vat = false);

void handleCtrlClickText(QPlainTextEdit *edit);
void handleCtrlClickLine(QLineEdit *edit);
Expand Down Expand Up @@ -517,6 +519,7 @@ class MainWindow : public QMainWindow {
void memSyncEdit(HexWidget *edit);
void memAsciiToggle(HexWidget *edit);
void memDocksUpdate();
HexWidget *firstMemWidget();
void addMemDock(const QString &magic, int bytes, bool ascii);
void addVisualizerDock(const QString &magic, const QString &config);
void addKeyHistoryDock(const QString &magic, int size);
Expand Down Expand Up @@ -574,6 +577,7 @@ class MainWindow : public QMainWindow {
Qt::CursorShape cursorShape,
int (QSize::*dimension)() const,
Qt::Orientation orientation);
void raiseContainingDock(QWidget *widget);

// Members
Ui::MainWindow *ui = Q_NULLPTR;
Expand Down
4 changes: 4 additions & 0 deletions gui/qt/memorywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,14 @@ void MainWindow::contextMemWidget(const QPoint &pos, uint32_t address) {
QAction *toggleRead = menu.addAction(ACTION_TOGGLE_READ);
QAction *toggleWrite = menu.addAction(ACTION_TOGGLE_WRITE);
QAction *toggleReadWrite = menu.addAction(ACTION_TOGGLE_RW);
menu.addSeparator();
QAction *gotoDisasm = gotoDisasmAction(&menu);

QAction* item = menu.exec(pos);
if (item == copyAddr) {
qApp->clipboard()->setText(addr.toLatin1());
} else if (item == gotoDisasm) {
gotoDisasmAddr(address);
} else if (item == toggleBreak) {
breakAdd(breakNextLabel(), address, true, true, false);
memDocksUpdate();
Expand Down
1 change: 1 addition & 0 deletions gui/qt/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,7 @@ void MainWindow::addKeyHistoryDock(const QString &magic, int size) {
});

dw->setState(m_uiEditMode);
dw->setAttribute(Qt::WA_DeleteOnClose);
addDockWidget(Qt::RightDockWidgetArea, dw);
dw->setObjectName(magic);
dw->setWidget(widget);
Expand Down

0 comments on commit 282539c

Please sign in to comment.