1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:38:11 +00:00

PixelPaint: Ask about unsaved changes for all tabs on close

Now, when trying to close the application, there is a separate prompt
for each open tab with unsaved changes. Each tab is closed after it is
handled appropriately (assuming the user didn't Cancel), this makes it
so that the message box is always asking about the currently active tab,
allowing the user to see that the image contains.

If at any point the user presses "Cancel", all remaining tabs are kept
open.
This commit is contained in:
Mustafa Quraish 2022-01-04 21:35:55 -05:00 committed by Andreas Kling
parent 915211252d
commit c03f271bbf
2 changed files with 19 additions and 9 deletions

View file

@ -64,7 +64,7 @@ MainWidget::MainWidget()
};
m_tab_widget->on_tab_close_click = [&](auto& widget) {
if (request_close()) {
if (request_close_editor()) {
auto& image_editor = verify_cast<PixelPaint::ImageEditor>(widget);
m_tab_widget->deferred_invoke([&] {
m_tab_widget->remove_tab(image_editor);
@ -751,18 +751,16 @@ void MainWidget::create_image_from_clipboard()
m_layer_list_widget->set_selected_layer(layer);
}
bool MainWidget::request_close()
bool MainWidget::request_close_editor()
{
if (m_tab_widget->children().is_empty())
return true;
auto* editor = current_image_editor();
VERIFY(editor);
VERIFY(current_image_editor());
if (!current_image_editor()->undo_stack().is_current_modified()) {
if (!editor->undo_stack().is_current_modified()) {
return true;
}
auto result = GUI::MessageBox::ask_about_unsaved_changes(window(), current_image_editor()->path(), current_image_editor()->undo_stack().last_unmodified_timestamp());
auto result = GUI::MessageBox::ask_about_unsaved_changes(window(), editor->path(), editor->undo_stack().last_unmodified_timestamp());
if (result == GUI::MessageBox::ExecYes) {
m_save_image_action->activate();
@ -775,6 +773,16 @@ bool MainWidget::request_close()
return false;
}
bool MainWidget::request_close()
{
while (!m_tab_widget->children().is_empty()) {
if (!request_close_editor())
return false;
m_tab_widget->remove_tab(*m_tab_widget->active_widget());
}
return true;
}
ImageEditor* MainWidget::current_image_editor()
{
if (!m_tab_widget->active_widget())