From 9263e7c62fc657cef94133b82a2c80a301145bf4 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Sat, 20 Jan 2018 10:53:54 +0100 Subject: [PATCH] refactored ESC key handling prevent exiting debugger from within Options Dialog (hack) --- src/debugger/Debugger.cxx | 3 +- src/debugger/Debugger.hxx | 9 ++++++ src/debugger/gui/DebuggerDialog.cxx | 1 + src/emucore/EventHandler.cxx | 48 ++++++++++++++++++----------- src/gui/InputTextDialog.cxx | 1 - src/gui/OptionsDialog.cxx | 4 +++ 6 files changed, 46 insertions(+), 20 deletions(-) diff --git a/src/debugger/Debugger.cxx b/src/debugger/Debugger.cxx index 95da6a018..9603f5e59 100644 --- a/src/debugger/Debugger.cxx +++ b/src/debugger/Debugger.cxx @@ -64,7 +64,8 @@ Debugger::Debugger(OSystem& osystem, Console& console) mySystem(console.system()), myDialog(nullptr), myWidth(DebuggerDialog::kSmallFontMinW), - myHeight(DebuggerDialog::kSmallFontMinH) + myHeight(DebuggerDialog::kSmallFontMinH), + myMenuMode(false) { // Init parser myParser = make_unique(*this, osystem.settings()); diff --git a/src/debugger/Debugger.hxx b/src/debugger/Debugger.hxx index 0324cbdc0..7c671c089 100644 --- a/src/debugger/Debugger.hxx +++ b/src/debugger/Debugger.hxx @@ -240,6 +240,13 @@ class Debugger : public DialogContainer void lockBankswitchState(); void unlockBankswitchState(); + /** + Used to make sure that debugger cannot be exited while Options dialog is open. + (ugly hack!) + */ + void setMenuMode(bool enable) { myMenuMode = enable; }; + bool inMenuMode() { return myMenuMode; }; + private: /** Save state of each debugger subsystem and, by default, mark all @@ -323,6 +330,8 @@ 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 9c81fcfdf..40fecceec 100644 --- a/src/debugger/gui/DebuggerDialog.cxx +++ b/src/debugger/gui/DebuggerDialog.cxx @@ -174,6 +174,7 @@ 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 ccbe190a5..21b14c9e6 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -614,11 +614,36 @@ void EventHandler::handleKeyEvent(StellaKey key, StellaMod mod, bool state) // Don't pass the key on if we've already taken care of it if(handled) return; - // Handle keys which switch eventhandler state // Arrange the logic to take advantage of short-circuit evaluation - if(!(StellaModTest::isControl(mod) || StellaModTest::isShift(mod) || StellaModTest::isAlt(mod)) && - !state && eventStateChange(myKeyTable[key][kEmulationMode])) - return; + if(!(StellaModTest::isControl(mod) || StellaModTest::isShift(mod) || StellaModTest::isAlt(mod))) + { + // special handling for Escape key + if(state && key == KBDK_ESCAPE) + { + if(myState == EventHandlerState::PAUSE) + { + setEventState(EventHandlerState::EMULATION); + return; + } + else if(myState == EventHandlerState::CMDMENU || + myState == EventHandlerState::TIMEMACHINE) + { + leaveMenuMode(); + return; + } + // TODO: this currently does not work, because it exits the search dialog too + // How can we identify if the focus is in a different dialog? + /*else if(myState == EventHandlerState::DEBUGGER && !myOSystem.debugger().inMenuMode()) + { + leaveDebugMode(); + return; + }*/ + } + + // Handle keys which switch eventhandler state + if(!state && eventStateChange(myKeyTable[key][kEmulationMode])) + return; + } // Otherwise, let the event handler deal with it switch(myState) @@ -1250,25 +1275,12 @@ bool EventHandler::eventStateChange(Event::Type type) case Event::DebuggerMode: if(myState == EventHandlerState::EMULATION || myState == EventHandlerState::PAUSE) enterDebugMode(); - else if(myState == EventHandlerState::DEBUGGER) + else if(myState == EventHandlerState::DEBUGGER && !myOSystem.debugger().inMenuMode()) leaveDebugMode(); else handled = false; break; - case Event::LauncherMode: - if (myState == EventHandlerState::PAUSE || - myState == EventHandlerState::TIMEMACHINE) - setEventState(EventHandlerState::EMULATION); - else if(myState == EventHandlerState::CMDMENU) - leaveMenuMode(); - // TODO: this currently does not work, because it exits all open dialogs too - /*else if(myState == EventHandlerState::DEBUGGER) - leaveDebugMode();*/ - else - handled = false; - break; - default: handled = false; } diff --git a/src/gui/InputTextDialog.cxx b/src/gui/InputTextDialog.cxx index a23a70422..858287cf1 100644 --- a/src/gui/InputTextDialog.cxx +++ b/src/gui/InputTextDialog.cxx @@ -216,7 +216,6 @@ void InputTextDialog::handleCommand(CommandSender* sender, int cmd, Dialog::handleCommand(sender, GuiObject::kCloseCmd, data, id); break; - default: Dialog::handleCommand(sender, cmd, data, id); break; diff --git a/src/gui/OptionsDialog.cxx b/src/gui/OptionsDialog.cxx index c3c42dfc3..bc919e214 100644 --- a/src/gui/OptionsDialog.cxx +++ b/src/gui/OptionsDialog.cxx @@ -36,6 +36,7 @@ #include "HelpDialog.hxx" #include "AboutDialog.hxx" #include "OptionsDialog.hxx" +#include "Debugger.hxx" #include "Launcher.hxx" #ifdef CHEATCODE_SUPPORT @@ -251,7 +252,10 @@ void OptionsDialog::handleCommand(CommandSender* sender, int cmd, case kExitCmd: if(myMode != emulator) + { + instance().debugger().setMenuMode(false); close(); + } else instance().eventHandler().leaveMenuMode(); break;