From d7bcde29dc2087be1a55540cacd475ed0e953ff2 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Sat, 20 Jan 2018 11:45:07 -0330 Subject: [PATCH] A different implementation of testing whether debugger can be exited. - basically check whether the current dialog is the 'base' one (ie, the debugger window) - this solution is more robust, in that we don't have to modify every dialog that can appear in the debugger --- src/debugger/Debugger.cxx | 9 +++++++-- src/debugger/Debugger.hxx | 9 +++------ src/debugger/gui/DebuggerDialog.cxx | 1 - src/emucore/EventHandler.cxx | 2 +- src/gui/OptionsDialog.cxx | 4 ---- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/debugger/Debugger.cxx b/src/debugger/Debugger.cxx index 9603f5e59..0eb01abcf 100644 --- a/src/debugger/Debugger.cxx +++ b/src/debugger/Debugger.cxx @@ -64,8 +64,7 @@ Debugger::Debugger(OSystem& osystem, Console& console) mySystem(console.system()), myDialog(nullptr), myWidth(DebuggerDialog::kSmallFontMinW), - myHeight(DebuggerDialog::kSmallFontMinH), - myMenuMode(false) + myHeight(DebuggerDialog::kSmallFontMinH) { // Init parser myParser = make_unique(*this, osystem.settings()); @@ -784,6 +783,12 @@ void Debugger::unlockBankswitchState() myConsole.cartridge().unlockBank(); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool Debugger::canExit() const +{ + return myDialogStack.top() == baseDialog(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Debugger::BuiltinFunction Debugger::ourBuiltinFunctions[NUM_BUILTIN_FUNCS] = { // left joystick: diff --git a/src/debugger/Debugger.hxx b/src/debugger/Debugger.hxx index 7c671c089..76b32e9e5 100644 --- a/src/debugger/Debugger.hxx +++ b/src/debugger/Debugger.hxx @@ -241,11 +241,10 @@ class Debugger : public DialogContainer void unlockBankswitchState(); /** - Used to make sure that debugger cannot be exited while Options dialog is open. - (ugly hack!) + Answers whether the debugger can be exited. Currently this only + happens when no other dialogs are active. */ - void setMenuMode(bool enable) { myMenuMode = enable; }; - bool inMenuMode() { return myMenuMode; }; + bool canExit() const; private: /** @@ -330,8 +329,6 @@ class Debugger : public DialogContainer static BuiltinFunction ourBuiltinFunctions[NUM_BUILTIN_FUNCS]; static PseudoRegister ourPseudoRegisters[NUM_PSEUDO_REGS]; - bool myMenuMode; - private: // rewind/unwind n states uInt16 windStates(uInt16 numStates, bool unwind, string& message); diff --git a/src/debugger/gui/DebuggerDialog.cxx b/src/debugger/gui/DebuggerDialog.cxx index 40fecceec..9c81fcfdf 100644 --- a/src/debugger/gui/DebuggerDialog.cxx +++ b/src/debugger/gui/DebuggerDialog.cxx @@ -174,7 +174,6 @@ void DebuggerDialog::handleCommand(CommandSender* sender, int cmd, break; case kDDOptionsCmd: - instance().debugger().setMenuMode(true); myOptions->open(); loadConfig(); break; diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index 21b14c9e6..7a282657b 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -1275,7 +1275,7 @@ bool EventHandler::eventStateChange(Event::Type type) case Event::DebuggerMode: if(myState == EventHandlerState::EMULATION || myState == EventHandlerState::PAUSE) enterDebugMode(); - else if(myState == EventHandlerState::DEBUGGER && !myOSystem.debugger().inMenuMode()) + else if(myState == EventHandlerState::DEBUGGER && myOSystem.debugger().canExit()) leaveDebugMode(); else handled = false; diff --git a/src/gui/OptionsDialog.cxx b/src/gui/OptionsDialog.cxx index bc919e214..c3c42dfc3 100644 --- a/src/gui/OptionsDialog.cxx +++ b/src/gui/OptionsDialog.cxx @@ -36,7 +36,6 @@ #include "HelpDialog.hxx" #include "AboutDialog.hxx" #include "OptionsDialog.hxx" -#include "Debugger.hxx" #include "Launcher.hxx" #ifdef CHEATCODE_SUPPORT @@ -252,10 +251,7 @@ void OptionsDialog::handleCommand(CommandSender* sender, int cmd, case kExitCmd: if(myMode != emulator) - { - instance().debugger().setMenuMode(false); close(); - } else instance().eventHandler().leaveMenuMode(); break;