MessageBox.h 1.5 KB

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