diff options
author | Mustafa Quraish <mustafaq9@gmail.com> | 2022-01-04 21:35:55 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-05 12:08:20 +0100 |
commit | c03f271bbf76f4497f5290fb4ea2880cad232112 (patch) | |
tree | 3014d625736357a512b4740ef29832c0f2bcd78c | |
parent | 915211252d8e8c9fad736dbd9a7693a9c560afbf (diff) | |
download | serenity-c03f271bbf76f4497f5290fb4ea2880cad232112.zip |
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.
-rw-r--r-- | Userland/Applications/PixelPaint/MainWidget.cpp | 24 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/MainWidget.h | 4 |
2 files changed, 19 insertions, 9 deletions
diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp index 6c04802a80..56f00d606b 100644 --- a/Userland/Applications/PixelPaint/MainWidget.cpp +++ b/Userland/Applications/PixelPaint/MainWidget.cpp @@ -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()) diff --git a/Userland/Applications/PixelPaint/MainWidget.h b/Userland/Applications/PixelPaint/MainWidget.h index fc74b625b6..dc70b6df40 100644 --- a/Userland/Applications/PixelPaint/MainWidget.h +++ b/Userland/Applications/PixelPaint/MainWidget.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Mustafa Quraish <mustafa@serenityos.org> + * Copyright (c) 2021-2022, Mustafa Quraish <mustafa@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -36,6 +36,8 @@ public: void open_image_fd(int fd, String const& path); void create_default_image(); + + bool request_close_editor(); bool request_close(); private: |