From 490d385d015a4f1c475dfbbc1e14fb469baa4970 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 4 Jan 2022 17:56:10 +0100 Subject: [PATCH] PixelPaint: Use GUI::MessageBox::ask_about_unsaved_changes() To make the last-saved-at timestamp show up correctly, we also now mark the editor's undo stack as unmodified on save. --- Userland/Applications/PixelPaint/ImageEditor.h | 2 ++ Userland/Applications/PixelPaint/MainWidget.cpp | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Userland/Applications/PixelPaint/ImageEditor.h b/Userland/Applications/PixelPaint/ImageEditor.h index 4a1701588b..3bbaae35c6 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.h +++ b/Userland/Applications/PixelPaint/ImageEditor.h @@ -43,6 +43,8 @@ public: bool undo(); bool redo(); + auto& undo_stack() { return *m_undo_stack; } + void add_guide(NonnullRefPtr guide) { m_guides.append(guide); } void remove_guide(Guide const& guide) { diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp index 10c499b317..7d7997a405 100644 --- a/Userland/Applications/PixelPaint/MainWidget.cpp +++ b/Userland/Applications/PixelPaint/MainWidget.cpp @@ -143,6 +143,7 @@ void MainWidget::initialize_menubar(GUI::Window& window) return; } editor->image().set_path(*save_result.chosen_file); + editor->undo_stack().set_current_unmodified(); }); m_save_image_action = GUI::CommonActions::make_save_action([&](auto&) { @@ -161,6 +162,7 @@ void MainWidget::initialize_menubar(GUI::Window& window) GUI::MessageBox::show_error(&window, String::formatted("Could not save {}: {}", *response.chosen_file, result.error())); return; } + editor->undo_stack().set_current_unmodified(); }); file_menu.add_action(*m_new_image_action); @@ -748,10 +750,12 @@ bool MainWidget::request_close() if (m_tab_widget->children().is_empty()) return true; - auto result = GUI::MessageBox::show(window(), "Save before closing?", "Save changes", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNoCancel); + VERIFY(current_image_editor()); + + auto result = GUI::MessageBox::ask_about_unsaved_changes(window(), current_image_editor()->image().path(), current_image_editor()->undo_stack().last_unmodified_timestamp()); if (result == GUI::MessageBox::ExecYes) { - m_save_image_as_action->activate(); + m_save_image_action->activate(); return true; }