From 086a34103d625936af63b729a3d86d0944b971d2 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sat, 6 Oct 2018 18:23:11 -0700 Subject: [PATCH] Qt: Debugger console history --- CHANGES | 1 + src/platform/qt/DebuggerConsole.cpp | 42 +++++++++++++++++++++++++++++ src/platform/qt/DebuggerConsole.h | 5 ++++ 3 files changed, 48 insertions(+) diff --git a/CHANGES b/CHANGES index 90d223a87..b8c91aba5 100644 --- a/CHANGES +++ b/CHANGES @@ -130,6 +130,7 @@ Misc: - GB: Improved SGB2 support - Libretro: Reduce rumble callbacks - Debugger: Minor text fixes + - Qt: Debugger console history 0.7 beta 1: (2018-09-24) - Initial beta for 0.7 diff --git a/src/platform/qt/DebuggerConsole.cpp b/src/platform/qt/DebuggerConsole.cpp index a9c505da8..b7ac06323 100644 --- a/src/platform/qt/DebuggerConsole.cpp +++ b/src/platform/qt/DebuggerConsole.cpp @@ -17,6 +17,8 @@ DebuggerConsole::DebuggerConsole(DebuggerConsoleController* controller, QWidget* { m_ui.setupUi(this); + m_ui.prompt->installEventFilter(this); + connect(m_ui.prompt, &QLineEdit::returnPressed, this, &DebuggerConsole::postLine); connect(controller, &DebuggerConsoleController::log, this, &DebuggerConsole::log); connect(m_ui.breakpoint, &QAbstractButton::clicked, controller, &DebuggerController::attach); @@ -36,7 +38,47 @@ void DebuggerConsole::postLine() { if (line.isEmpty()) { m_consoleController->enterLine(QString("\n")); } else { + m_history.append(line); + m_historyOffset = 0; log(QString("> %1\n").arg(line)); m_consoleController->enterLine(line); } } + +bool DebuggerConsole::eventFilter(QObject*, QEvent* event) { + if (event->type() != QEvent::KeyPress) { + return false; + } + if (m_history.isEmpty()) { + return false; + } + QKeyEvent* keyEvent = static_cast(event); + switch (keyEvent->key()) { + case Qt::Key_Down: + if (m_historyOffset <= 0) { + return false; + } + --m_historyOffset; + break; + case Qt::Key_Up: + if (m_historyOffset >= m_history.size()) { + return false; + } + ++m_historyOffset; + break; + case Qt::Key_End: + m_historyOffset = 0; + break; + case Qt::Key_Home: + m_historyOffset = m_history.size(); + break; + default: + return false; + } + if (m_historyOffset == 0) { + m_ui.prompt->clear(); + } else { + m_ui.prompt->setText(m_history[m_history.size() - m_historyOffset]); + } + return true; +} \ No newline at end of file diff --git a/src/platform/qt/DebuggerConsole.h b/src/platform/qt/DebuggerConsole.h index f4bd4cadb..5fe523c24 100644 --- a/src/platform/qt/DebuggerConsole.h +++ b/src/platform/qt/DebuggerConsole.h @@ -21,8 +21,13 @@ private slots: void log(const QString&); void postLine(); +protected: + bool eventFilter(QObject*, QEvent*) override; + private: Ui::DebuggerConsole m_ui; + QStringList m_history; + int m_historyOffset; DebuggerConsoleController* m_consoleController; };