From c3c1a9ca1d13340b7570a5cc0b76f274a9b54a4f Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Thu, 5 Aug 2021 11:52:09 +0100 Subject: [PATCH] Solitaire: Get user confirmation to close when there is a active game --- Userland/Games/Solitaire/main.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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);