From 282539cf30bd9dd91f02ae9d94473d9592312474 Mon Sep 17 00:00:00 2001 From: Brendan Fletcher Date: Tue, 13 Aug 2024 02:27:29 -0400 Subject: [PATCH] Raise/focus docks for Goto actions, and create them if UI edit mode is enabled --- gui/qt/debugger.cpp | 61 ++++++++++++++++++++++++++++++++++------- gui/qt/mainwindow.cpp | 17 ++++++++++-- gui/qt/mainwindow.h | 4 +++ gui/qt/memorywidget.cpp | 4 +++ gui/qt/settings.cpp | 1 + 5 files changed, 74 insertions(+), 13 deletions(-) diff --git a/gui/qt/debugger.cpp b/gui/qt/debugger.cpp index 46f5fc811..1c4042de5 100644 --- a/gui/qt/debugger.cpp +++ b/gui/qt/debugger.cpp @@ -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()) { uint32_t offset = address - edit->getBase(); if (offset < edit->getSize()) { - 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; @@ -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); @@ -2579,9 +2610,9 @@ 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) { @@ -2589,7 +2620,7 @@ void MainWindow::contextVat(const QPoint &posa) { } else if (item == gotoVat) { gotoMemAddr(hex2int(vatAddr)); } else if (item == gotoDisasm) { - disasmUpdateAddr(hex2int(addr) + 4, false); + gotoDisasmAddr(hex2int(addr) + 4); } } @@ -2604,6 +2635,16 @@ void MainWindow::memDocksUpdate() { } } +HexWidget *MainWindow::firstMemWidget() { + if (!m_docksMemory.isEmpty()) { + QWidget *dock = findChild(m_docksMemory.first()); + if (dock != Q_NULLPTR) { + return dock->findChild(); + } + } + return Q_NULLPTR; +} + //------------------------------------------------ // Stepping //------------------------------------------------ diff --git a/gui/qt/mainwindow.cpp b/gui/qt/mainwindow.cpp index fb1575036..ec5fdd25d 100644 --- a/gui/qt/mainwindow.cpp +++ b/gui/qt/mainwindow.cpp @@ -985,6 +985,17 @@ bool MainWindow::redistributeDocks(const QPoint &pos, const QPoint &offset, return false; } +void MainWindow::raiseContainingDock(QWidget *widget) { + QWidget *dock = findSelfOrParent(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); @@ -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); @@ -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); diff --git a/gui/qt/mainwindow.h b/gui/qt/mainwindow.h index 21daef92a..07ebfa126 100644 --- a/gui/qt/mainwindow.h +++ b/gui/qt/mainwindow.h @@ -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); @@ -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); @@ -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; diff --git a/gui/qt/memorywidget.cpp b/gui/qt/memorywidget.cpp index f183fedd1..6804a4772 100644 --- a/gui/qt/memorywidget.cpp +++ b/gui/qt/memorywidget.cpp @@ -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(); diff --git a/gui/qt/settings.cpp b/gui/qt/settings.cpp index 36565240c..62d8dc7e2 100644 --- a/gui/qt/settings.cpp +++ b/gui/qt/settings.cpp @@ -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);