MessageBox.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. #pragma once
  8. #include <AK/Time.h>
  9. #include <LibGUI/Dialog.h>
  10. namespace GUI {
  11. class MessageBox : public Dialog {
  12. C_OBJECT(MessageBox)
  13. public:
  14. enum class Type {
  15. None,
  16. Information,
  17. Warning,
  18. Error,
  19. Question
  20. };
  21. enum class InputType {
  22. OK,
  23. OKCancel,
  24. YesNo,
  25. YesNoCancel,
  26. };
  27. virtual ~MessageBox() override = default;
  28. static int show(Window* parent_window, StringView text, StringView title, Type type = Type::None, InputType input_type = InputType::OK);
  29. static int show_error(Window* parent_window, StringView text);
  30. static int ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Time> last_unmodified_timestamp = {});
  31. void set_text(String text);
  32. private:
  33. explicit MessageBox(Window* parent_window, StringView text, StringView title, Type type = Type::None, InputType input_type = InputType::OK);
  34. bool should_include_ok_button() const;
  35. bool should_include_cancel_button() const;
  36. bool should_include_yes_button() const;
  37. bool should_include_no_button() const;
  38. void build();
  39. RefPtr<Gfx::Bitmap> icon() const;
  40. String m_text;
  41. Type m_type { Type::None };
  42. InputType m_input_type { InputType::OK };
  43. RefPtr<GUI::Button> m_ok_button;
  44. RefPtr<GUI::Button> m_yes_button;
  45. RefPtr<GUI::Button> m_no_button;
  46. RefPtr<GUI::Button> m_cancel_button;
  47. };
  48. }