/* * Copyright (c) 2018-2022, Andreas Kling * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include #include #include namespace GUI { ErrorOr> MessageBox::create(Window* parent_window, StringView text, StringView title, Type type, InputType input_type) { auto box = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) MessageBox(parent_window, type, input_type))); TRY(box->build()); box->set_title(TRY(String::from_utf8(title)).to_deprecated_string()); box->set_text(TRY(String::from_utf8(text))); auto size = box->main_widget()->effective_min_size(); box->resize(TRY(size.width().shrink_value()), TRY(size.height().shrink_value())); return box; } Dialog::ExecResult MessageBox::show(Window* parent_window, StringView text, StringView title, Type type, InputType input_type) { return MUST(try_show(parent_window, text, title, type, input_type)); } ErrorOr MessageBox::try_show(Window* parent_window, StringView text, StringView title, Type type, InputType input_type) { auto box = TRY(MessageBox::create(parent_window, text, title, type, input_type)); if (parent_window) box->set_icon(parent_window->icon()); return box->exec(); } Dialog::ExecResult MessageBox::show_error(Window* parent_window, StringView text) { return MUST(try_show_error(parent_window, text)); } ErrorOr MessageBox::try_show_error(Window* parent_window, StringView text) { return TRY(try_show(parent_window, text, "Error"sv, GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK)); } Dialog::ExecResult MessageBox::ask_about_unsaved_changes(Window* parent_window, StringView path, Optional