From b2d61b1d3ac670b28cb5f0136c142d09837c2a79 Mon Sep 17 00:00:00 2001 From: Colin Kinloch Date: Sat, 3 Feb 2024 18:30:36 +0000 Subject: [PATCH] Add Ctrl+Q to quit --- src/gui/doAction.cpp | 5 +++++ src/gui/gui.cpp | 23 ++++++++++------------- src/gui/gui.h | 3 ++- src/gui/guiConst.cpp | 1 + src/main.cpp | 2 +- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/gui/doAction.cpp b/src/gui/doAction.cpp index 4f350c93d..f07e0a8c3 100644 --- a/src/gui/doAction.cpp +++ b/src/gui/doAction.cpp @@ -83,6 +83,11 @@ void FurnaceGUI::doAction(int what) { doRedo(); } break; + case GUI_ACTION_QUIT: + { + requestQuit(); + } + break; case GUI_ACTION_PLAY_TOGGLE: if (e->isPlaying() && !e->isStepping()) { stop(); diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 56ac43a9c..ef885a338 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -3672,12 +3672,8 @@ bool FurnaceGUI::loop() { // used for MIDI wake up break; case SDL_QUIT: - if (modified) { - showWarning("Unsaved changes! Save changes before quitting?",GUI_WARN_QUIT); - } else { - quit=true; + if (requestQuit()) return true; - } break; } } @@ -4327,12 +4323,8 @@ bool FurnaceGUI::loop() { doAction(GUI_ACTION_OPEN_BACKUP); } ImGui::Separator(); - if (ImGui::MenuItem("exit")) { - if (modified) { - showWarning("Unsaved changes! Save before quitting?",GUI_WARN_QUIT); - } else { - quit=true; - } + if (ImGui::MenuItem("exit...",BIND_FOR(GUI_ACTION_QUIT))) { + requestQuit(); } ImGui::EndDisabled(); ImGui::EndMenu(); @@ -7253,8 +7245,13 @@ bool FurnaceGUI::finish() { return true; } -void FurnaceGUI::requestQuit() { - quit=true; +bool FurnaceGUI::requestQuit() { + if (modified) { + showWarning("Unsaved changes! Save changes before quitting?",GUI_WARN_QUIT); + } else { + quit=true; + } + return quit; } FurnaceGUI::FurnaceGUI(): diff --git a/src/gui/gui.h b/src/gui/gui.h index 2c7966e4a..8562467c0 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -582,6 +582,7 @@ enum FurnaceGUIActions { GUI_ACTION_EXPORT, GUI_ACTION_UNDO, GUI_ACTION_REDO, + GUI_ACTION_QUIT, GUI_ACTION_PLAY_TOGGLE, GUI_ACTION_PLAY, GUI_ACTION_STOP, @@ -2659,7 +2660,7 @@ class FurnaceGUI { bool loop(); bool finish(); bool init(); - void requestQuit(); + bool requestQuit(); FurnaceGUI(); }; diff --git a/src/gui/guiConst.cpp b/src/gui/guiConst.cpp index eaa3996b2..e5b428530 100644 --- a/src/gui/guiConst.cpp +++ b/src/gui/guiConst.cpp @@ -548,6 +548,7 @@ const FurnaceGUIActionDef guiActions[GUI_ACTION_MAX]={ #else D("REDO", "Redo", FURKMOD_CMD|SDLK_y), #endif + D("QUIT", "Exit", FURKMOD_CMD|SDLK_q), D("PLAY_TOGGLE", "Play/Stop (toggle)", SDLK_RETURN), D("PLAY", "Play", 0), D("STOP", "Stop", 0), diff --git a/src/main.cpp b/src/main.cpp index 3b23068e6..12f77e662 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,7 +39,7 @@ typedef HRESULT (WINAPI *SPDA)(PROCESS_DPI_AWARENESS); #include #include -struct sigaction termsa; +struct sigaction termsa = {0}; #endif #include "cli/cli.h"