diff --git a/Userland/Libraries/LibGUI/MessageBox.cpp b/Userland/Libraries/LibGUI/MessageBox.cpp index 08e2ce3f72..cfb967a06a 100644 --- a/Userland/Libraries/LibGUI/MessageBox.cpp +++ b/Userland/Libraries/LibGUI/MessageBox.cpp @@ -1,9 +1,10 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2022, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -26,6 +27,25 @@ int MessageBox::show_error(Window* parent_window, StringView text) return show(parent_window, text, "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK); } +int MessageBox::ask_about_unsaved_changes(Window* parent_window, StringView path) +{ + String text; + if (path.is_empty()) + text = "Save changes to untitled document before closing?"; + else + text = String::formatted("Save changes to '{}' before closing?", LexicalPath::basename(path)); + + auto box = MessageBox::construct(parent_window, text, "Unsaved changes", Type::Warning, InputType::YesNoCancel); + if (parent_window) + box->set_icon(parent_window->icon()); + + box->m_yes_button->set_text(path.is_empty() ? "Save As..." : "Save"); + box->m_no_button->set_text("Close"); + box->m_cancel_button->set_text("Cancel"); + + return box->exec(); +} + MessageBox::MessageBox(Window* parent_window, StringView text, StringView title, Type type, InputType input_type) : Dialog(parent_window) , m_text(text) @@ -119,7 +139,7 @@ void MessageBox::build() constexpr int button_width = 80; int button_count = 0; - auto add_button = [&](String label, Dialog::ExecResult result) { + auto add_button = [&](String label, Dialog::ExecResult result) -> GUI::Button& { auto& button = button_container.add