1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:57:44 +00:00

Calendar: Ask about unsaved changes when closing the window :^)

The Calendar now asks about unsaved changes in the calendar when
attempting to close the window.
This commit is contained in:
david072 2023-11-17 21:04:40 +01:00 committed by Andrew Kaster
parent 75faa9239a
commit b657fa6f95
3 changed files with 34 additions and 1 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2023, the SerenityOS developers.
* Copyright (c) 2023, David Ganz <david.g.ganz@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -93,10 +94,14 @@ ErrorOr<NonnullRefPtr<CalendarWidget>> CalendarWidget::create(GUI::Window* paren
file_menu->add_separator();
file_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) {
file_menu->add_action(GUI::CommonActions::make_quit_action([&](auto&) {
if (!widget->request_close())
return;
GUI::Application::the()->quit();
}));
widget->m_save_action = save_action;
auto event_menu = parent_window->add_menu("&Event"_string);
event_menu->add_action(add_event_action);
@ -114,6 +119,23 @@ ErrorOr<NonnullRefPtr<CalendarWidget>> CalendarWidget::create(GUI::Window* paren
return widget;
}
bool CalendarWidget::request_close()
{
if (!m_event_calendar->event_manager().is_dirty())
return true;
auto result = GUI::MessageBox::ask_about_unsaved_changes(window(), m_event_calendar->event_manager().current_filename());
if (result == GUI::MessageBox::ExecResult::Yes) {
m_save_action->activate();
return !m_event_calendar->event_manager().is_dirty();
}
if (result == GUI::MessageBox::ExecResult::No)
return true;
return false;
}
void CalendarWidget::create_on_events_change()
{
m_event_calendar->event_manager().on_events_change = [&]() {