summaryrefslogtreecommitdiff
path: root/Userland/Applications
diff options
context:
space:
mode:
authorMustafa Quraish <mustafaq9@gmail.com>2022-01-07 17:49:18 -0500
committerAndreas Kling <kling@serenityos.org>2022-01-09 00:19:47 +0100
commit6c60bf7537bf68578399af46a1005d62b6c762ce (patch)
tree44fe16aea746fecd1f00a79904096ceedface9bb /Userland/Applications
parentc2b3bab984865796dee3c385b50cb601f84f7363 (diff)
downloadserenity-6c60bf7537bf68578399af46a1005d62b6c762ce.zip
PixelPaint: Move `request_close_editor()` logic inside `ImageEditor`
This allows us to request any specific editor to close itself. Earlier, this could only be done for the currently active editor, so trying to close inactive tabs would not work properly.
Diffstat (limited to 'Userland/Applications')
-rw-r--r--Userland/Applications/PixelPaint/ImageEditor.cpp18
-rw-r--r--Userland/Applications/PixelPaint/ImageEditor.h2
-rw-r--r--Userland/Applications/PixelPaint/MainWidget.cpp30
-rw-r--r--Userland/Applications/PixelPaint/MainWidget.h1
4 files changed, 25 insertions, 26 deletions
diff --git a/Userland/Applications/PixelPaint/ImageEditor.cpp b/Userland/Applications/PixelPaint/ImageEditor.cpp
index 8c560b1fab..3aa2fb92e8 100644
--- a/Userland/Applications/PixelPaint/ImageEditor.cpp
+++ b/Userland/Applications/PixelPaint/ImageEditor.cpp
@@ -700,6 +700,24 @@ void ImageEditor::image_select_layer(Layer* layer)
set_active_layer(layer);
}
+bool ImageEditor::request_close()
+{
+ if (!undo_stack().is_current_modified())
+ return true;
+
+ auto result = GUI::MessageBox::ask_about_unsaved_changes(window(), path(), undo_stack().last_unmodified_timestamp());
+
+ if (result == GUI::MessageBox::ExecYes) {
+ save_project();
+ return true;
+ }
+
+ if (result == GUI::MessageBox::ExecNo)
+ return true;
+
+ return false;
+}
+
void ImageEditor::save_project()
{
if (path().is_empty()) {
diff --git a/Userland/Applications/PixelPaint/ImageEditor.h b/Userland/Applications/PixelPaint/ImageEditor.h
index fd8cf7ca47..2f17914b84 100644
--- a/Userland/Applications/PixelPaint/ImageEditor.h
+++ b/Userland/Applications/PixelPaint/ImageEditor.h
@@ -109,6 +109,8 @@ public:
Gfx::FloatPoint image_position_to_editor_position(Gfx::IntPoint const&) const;
Gfx::FloatPoint editor_position_to_image_position(Gfx::IntPoint const&) const;
+ bool request_close();
+
void save_project_as();
void save_project();
diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp
index bd4dfc1f73..86044c9745 100644
--- a/Userland/Applications/PixelPaint/MainWidget.cpp
+++ b/Userland/Applications/PixelPaint/MainWidget.cpp
@@ -64,8 +64,8 @@ MainWidget::MainWidget()
};
m_tab_widget->on_tab_close_click = [&](auto& widget) {
- if (request_close_editor()) {
- auto& image_editor = verify_cast<PixelPaint::ImageEditor>(widget);
+ auto& image_editor = verify_cast<PixelPaint::ImageEditor>(widget);
+ if (image_editor.request_close()) {
m_tab_widget->deferred_invoke([&] {
m_tab_widget->remove_tab(image_editor);
if (m_tab_widget->children().size() == 1) {
@@ -728,32 +728,12 @@ void MainWidget::create_image_from_clipboard()
m_layer_list_widget->set_selected_layer(layer);
}
-bool MainWidget::request_close_editor()
-{
- auto* editor = current_image_editor();
- VERIFY(editor);
-
- if (!editor->undo_stack().is_current_modified()) {
- return true;
- }
-
- 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();
- return true;
- }
-
- if (result == GUI::MessageBox::ExecNo)
- return true;
-
- return false;
-}
-
bool MainWidget::request_close()
{
while (!m_tab_widget->children().is_empty()) {
- if (!request_close_editor())
+ auto* editor = current_image_editor();
+ VERIFY(editor);
+ if (!editor->request_close())
return false;
m_tab_widget->remove_tab(*m_tab_widget->active_widget());
}
diff --git a/Userland/Applications/PixelPaint/MainWidget.h b/Userland/Applications/PixelPaint/MainWidget.h
index dc70b6df40..cc1e8b4158 100644
--- a/Userland/Applications/PixelPaint/MainWidget.h
+++ b/Userland/Applications/PixelPaint/MainWidget.h
@@ -37,7 +37,6 @@ public:
void open_image_fd(int fd, String const& path);
void create_default_image();
- bool request_close_editor();
bool request_close();
private: