From ff8a6d8e59170ec866d7259da956c51dd7cb5be0 Mon Sep 17 00:00:00 2001 From: GeekFiftyFive Date: Wed, 23 Mar 2022 19:25:54 +0000 Subject: [PATCH] PixelPaint: Call set_modified on window Call set_modified on window in order to reflect unsaved changed in the titlebar's close button --- Userland/Applications/PixelPaint/ImageEditor.cpp | 11 +++++++++++ Userland/Applications/PixelPaint/ImageEditor.h | 3 +++ Userland/Applications/PixelPaint/MainWidget.cpp | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/Userland/Applications/PixelPaint/ImageEditor.cpp b/Userland/Applications/PixelPaint/ImageEditor.cpp index 1381153fbd9..72f0574e9f6 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.cpp +++ b/Userland/Applications/PixelPaint/ImageEditor.cpp @@ -50,9 +50,16 @@ ImageEditor::~ImageEditor() void ImageEditor::did_complete_action() { + if (on_modified_change) + on_modified_change(true); m_undo_stack.push(make(*m_image)); } +bool ImageEditor::is_modified() +{ + return undo_stack().is_current_modified(); +} + bool ImageEditor::undo() { if (!m_undo_stack.can_undo()) @@ -580,6 +587,8 @@ void ImageEditor::save_project() return; } undo_stack().set_current_unmodified(); + if (on_modified_change) + on_modified_change(false); } void ImageEditor::save_project_as() @@ -596,6 +605,8 @@ void ImageEditor::save_project_as() set_path(file->filename()); set_loaded_from_image(false); undo_stack().set_current_unmodified(); + if (on_modified_change) + on_modified_change(false); } Result ImageEditor::save_project_to_file(Core::File& file) const diff --git a/Userland/Applications/PixelPaint/ImageEditor.h b/Userland/Applications/PixelPaint/ImageEditor.h index 9d9cc2fa405..88df7cb922e 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.h +++ b/Userland/Applications/PixelPaint/ImageEditor.h @@ -87,6 +87,7 @@ public: Function on_image_mouse_position_change; Function on_leave; + Function on_modified_change; bool request_close(); @@ -110,6 +111,8 @@ public: void set_loaded_from_image(bool); + bool is_modified(); + private: explicit ImageEditor(NonnullRefPtr); diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp index 7455852da8b..abb28a1377d 100644 --- a/Userland/Applications/PixelPaint/MainWidget.cpp +++ b/Userland/Applications/PixelPaint/MainWidget.cpp @@ -88,6 +88,10 @@ MainWidget::MainWidget() m_palette_widget->set_image_editor(&image_editor); m_layer_list_widget->set_image(&image_editor.image()); m_layer_properties_widget->set_layer(image_editor.active_layer()); + window()->set_modified(image_editor.is_modified()); + image_editor.on_modified_change = [this](bool modified) { + window()->set_modified(modified); + }; if (auto* active_tool = m_toolbox->active_tool()) image_editor.set_active_tool(active_tool); m_show_guides_action->set_checked(image_editor.guide_visibility());