Serenity Operating System
at master 61 lines 1.6 kB view raw
1/* 2 * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org> 3 * Copyright (c) 2022, the SerenityOS developers. 4 * 5 * SPDX-License-Identifier: BSD-2-Clause 6 */ 7 8#pragma once 9 10#include <AK/Time.h> 11#include <LibGUI/Dialog.h> 12 13namespace GUI { 14 15class MessageBox : public Dialog { 16 C_OBJECT(MessageBox) 17public: 18 enum class Type { 19 None, 20 Information, 21 Warning, 22 Error, 23 Question 24 }; 25 26 enum class InputType { 27 OK, 28 OKCancel, 29 YesNo, 30 YesNoCancel, 31 }; 32 33 virtual ~MessageBox() override = default; 34 35 static ExecResult show(Window* parent_window, StringView text, StringView title, Type type = Type::None, InputType input_type = InputType::OK); 36 static ExecResult show_error(Window* parent_window, StringView text); 37 static ExecResult ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Time> last_unmodified_timestamp = {}); 38 39 void set_text(DeprecatedString text); 40 41private: 42 explicit MessageBox(Window* parent_window, StringView text, StringView title, Type type = Type::None, InputType input_type = InputType::OK); 43 44 bool should_include_ok_button() const; 45 bool should_include_cancel_button() const; 46 bool should_include_yes_button() const; 47 bool should_include_no_button() const; 48 void build(); 49 RefPtr<Gfx::Bitmap> icon() const; 50 51 DeprecatedString m_text; 52 Type m_type { Type::None }; 53 InputType m_input_type { InputType::OK }; 54 55 RefPtr<GUI::Button> m_ok_button; 56 RefPtr<GUI::Button> m_yes_button; 57 RefPtr<GUI::Button> m_no_button; 58 RefPtr<GUI::Button> m_cancel_button; 59}; 60 61}