summaryrefslogtreecommitdiff
path: root/Userland/Games
diff options
context:
space:
mode:
authorJamie Mansfield <jmansfield@cadixdev.org>2021-08-05 11:52:09 +0100
committerAndreas Kling <kling@serenityos.org>2021-08-06 01:12:32 +0200
commitc3c1a9ca1d13340b7570a5cc0b76f274a9b54a4f (patch)
tree341efb1e2c83ffeb6e03e165093f1380c6df55cc /Userland/Games
parent779316d468734d092acf4be64982ec225aeeb762 (diff)
downloadserenity-c3c1a9ca1d13340b7570a5cc0b76f274a9b54a4f.zip
Solitaire: Get user confirmation to close when there is a active game
Diffstat (limited to 'Userland/Games')
-rw-r--r--Userland/Games/Solitaire/main.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/Userland/Games/Solitaire/main.cpp b/Userland/Games/Solitaire/main.cpp
index c879c225ed..7bec5ccf4d 100644
--- a/Userland/Games/Solitaire/main.cpp
+++ b/Userland/Games/Solitaire/main.cpp
@@ -150,6 +150,24 @@ int main(int argc, char** argv)
statusbar.set_text(2, "Timer starts after your first move");
};
+ window->on_close_request = [&]() {
+ auto game_in_progress = timer->is_active();
+ if (game_in_progress) {
+ auto result = GUI::MessageBox::show(window,
+ "A game is still in progress, are you sure you would like to quit?",
+ "Game in progress",
+ GUI::MessageBox::Type::Warning,
+ GUI::MessageBox::InputType::YesNo);
+
+ if (result == GUI::MessageBox::ExecYes)
+ return GUI::Window::CloseRequestDecision::Close;
+ else
+ return GUI::Window::CloseRequestDecision::StayOpen;
+ }
+
+ return GUI::Window::CloseRequestDecision::Close;
+ };
+
GUI::ActionGroup draw_setting_actions;
draw_setting_actions.set_exclusive(true);