CodeWidget: Add button that prevents automatic updates to the address, such as navigating to the PC on pause.

This commit is contained in:
TryTwo
2025-07-09 23:00:00 -07:00
parent 43aa7e9b96
commit d53e766d65
4 changed files with 25 additions and 3 deletions

View File

@ -181,11 +181,13 @@ CodeViewWidget::CodeViewWidget()
&CodeViewWidget::OnDebugFontChanged); &CodeViewWidget::OnDebugFontChanged);
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, [this] { connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, [this] {
m_address = m_system.GetPPCState().pc; if (!m_lock_address && Core::GetState(m_system) == Core::State::Paused)
m_address = m_system.GetPPCState().pc;
Update(); Update();
}); });
connect(Host::GetInstance(), &Host::UpdateDisasmDialog, this, [this] { connect(Host::GetInstance(), &Host::UpdateDisasmDialog, this, [this] {
m_address = m_system.GetPPCState().pc; if (!m_lock_address && Core::GetState(m_system) == Core::State::Paused)
m_address = m_system.GetPPCState().pc;
Update(); Update();
}); });
connect(Host::GetInstance(), &Host::PPCSymbolsChanged, this, connect(Host::GetInstance(), &Host::PPCSymbolsChanged, this,
@ -538,6 +540,11 @@ u32 CodeViewWidget::GetAddress() const
return m_address; return m_address;
} }
void CodeViewWidget::OnLockAddress(bool lock)
{
m_lock_address = lock;
}
void CodeViewWidget::SetAddress(u32 address, SetAddressUpdate update) void CodeViewWidget::SetAddress(u32 address, SetAddressUpdate update)
{ {
if (m_address == address) if (m_address == address)

View File

@ -41,6 +41,7 @@ public:
~CodeViewWidget() override; ~CodeViewWidget() override;
u32 GetAddress() const; u32 GetAddress() const;
void OnLockAddress(bool lock);
u32 GetContextAddress() const; u32 GetContextAddress() const;
void SetAddress(u32 address, SetAddressUpdate update); void SetAddress(u32 address, SetAddressUpdate update);
@ -111,6 +112,7 @@ private:
bool m_updating = false; bool m_updating = false;
u32 m_address = 0; u32 m_address = 0;
bool m_lock_address = false;
u32 m_context_address = 0; u32 m_context_address = 0;
std::vector<CodeViewBranch> m_branches; std::vector<CodeViewBranch> m_branches;

View File

@ -18,6 +18,7 @@
#include <QStyleHints> #include <QStyleHints>
#include <QTabWidget> #include <QTabWidget>
#include <QTableWidget> #include <QTableWidget>
#include <QToolButton>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QWidget> #include <QWidget>
@ -31,6 +32,7 @@
#include "Core/System.h" #include "Core/System.h"
#include "DolphinQt/Debugger/BranchWatchDialog.h" #include "DolphinQt/Debugger/BranchWatchDialog.h"
#include "DolphinQt/Host.h" #include "DolphinQt/Host.h"
#include "DolphinQt/Resources.h"
#include "DolphinQt/Settings.h" #include "DolphinQt/Settings.h"
static const QString BOX_SPLITTER_STYLESHEET = QStringLiteral( static const QString BOX_SPLITTER_STYLESHEET = QStringLiteral(
@ -61,7 +63,7 @@ CodeWidget::CodeWidget(QWidget* parent)
[this](bool visible) { setHidden(!visible); }); [this](bool visible) { setHidden(!visible); });
connect(Host::GetInstance(), &Host::UpdateDisasmDialog, this, [this] { connect(Host::GetInstance(), &Host::UpdateDisasmDialog, this, [this] {
if (Core::GetState(m_system) == Core::State::Paused) if (!m_lock_btn->isChecked() && Core::GetState(m_system) == Core::State::Paused)
SetAddress(m_system.GetPPCState().pc, CodeViewWidget::SetAddressUpdate::WithoutUpdate); SetAddress(m_system.GetPPCState().pc, CodeViewWidget::SetAddressUpdate::WithoutUpdate);
Update(); Update();
}); });
@ -109,8 +111,16 @@ void CodeWidget::CreateWidgets()
auto* top_layout = new QHBoxLayout; auto* top_layout = new QHBoxLayout;
m_search_address = new QLineEdit; m_search_address = new QLineEdit;
m_search_address->setPlaceholderText(tr("Search Address")); m_search_address->setPlaceholderText(tr("Search Address"));
m_lock_btn = new QToolButton();
m_lock_btn->setIcon(Resources::GetThemeIcon("pause"));
m_lock_btn->setCheckable(true);
m_lock_btn->setMinimumSize(24, 24);
m_lock_btn->setToolTip(tr("When enabled, prevents automatic updates to the code view."));
m_branch_watch = new QPushButton(tr("Branch Watch")); m_branch_watch = new QPushButton(tr("Branch Watch"));
top_layout->addWidget(m_search_address); top_layout->addWidget(m_search_address);
top_layout->addWidget(m_lock_btn);
top_layout->addWidget(m_branch_watch); top_layout->addWidget(m_branch_watch);
auto* right_layout = new QVBoxLayout; auto* right_layout = new QVBoxLayout;
@ -191,6 +201,7 @@ void CodeWidget::ConnectWidgets()
connect(m_search_address, &QLineEdit::textChanged, this, &CodeWidget::OnSearchAddress); connect(m_search_address, &QLineEdit::textChanged, this, &CodeWidget::OnSearchAddress);
connect(m_search_address, &QLineEdit::returnPressed, this, &CodeWidget::OnSearchAddress); connect(m_search_address, &QLineEdit::returnPressed, this, &CodeWidget::OnSearchAddress);
connect(m_lock_btn, &QPushButton::toggled, m_code_view, &CodeViewWidget::OnLockAddress);
connect(m_search_symbols, &QLineEdit::textChanged, this, &CodeWidget::OnSearchSymbols); connect(m_search_symbols, &QLineEdit::textChanged, this, &CodeWidget::OnSearchSymbols);
connect(m_search_calls, &QLineEdit::textChanged, this, [this] { connect(m_search_calls, &QLineEdit::textChanged, this, [this] {
if (const Common::Symbol* symbol = m_ppc_symbol_db.GetSymbolFromAddr(m_code_view->GetAddress())) if (const Common::Symbol* symbol = m_ppc_symbol_db.GetSymbolFromAddr(m_code_view->GetAddress()))

View File

@ -17,6 +17,7 @@ class QSplitter;
class QListWidget; class QListWidget;
class QPushButton; class QPushButton;
class QTableWidget; class QTableWidget;
class QToolButton;
namespace Common namespace Common
{ {
@ -80,6 +81,7 @@ private:
BranchWatchDialog* m_branch_watch_dialog = nullptr; BranchWatchDialog* m_branch_watch_dialog = nullptr;
QLineEdit* m_search_address; QLineEdit* m_search_address;
QToolButton* m_lock_btn;
QPushButton* m_branch_watch; QPushButton* m_branch_watch;
QLineEdit* m_search_callstack; QLineEdit* m_search_callstack;