MessageBox.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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_ABSTRACT(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 ExecResult show(Window* parent_window, StringView text, StringView title, Type type = Type::None, InputType input_type = InputType::OK);
  29. static ExecResult show_error(Window* parent_window, StringView text);
  30. static ExecResult ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Time> last_unmodified_timestamp = {});
  31. static ErrorOr<ExecResult> try_show(Window* parent_window, StringView text, StringView title, Type type = Type::None, InputType input_type = InputType::OK);
  32. static ErrorOr<ExecResult> try_show_error(Window* parent_window, StringView text);
  33. static ErrorOr<ExecResult> try_ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Time> last_unmodified_timestamp = {});
  34. static ErrorOr<NonnullRefPtr<MessageBox>> create(Window* parent_window, StringView text, StringView title, Type type = Type::None, InputType input_type = InputType::OK);
  35. void set_text(String);
  36. private:
  37. MessageBox(Window* parent_window, Type type = Type::None, InputType input_type = InputType::OK);
  38. bool should_include_ok_button() const;
  39. bool should_include_cancel_button() const;
  40. bool should_include_yes_button() const;
  41. bool should_include_no_button() const;
  42. ErrorOr<void> build();
  43. ErrorOr<RefPtr<Gfx::Bitmap>> icon() const;
  44. Type m_type { Type::None };
  45. InputType m_input_type { InputType::OK };
  46. RefPtr<GUI::Button> m_ok_button;
  47. RefPtr<GUI::Button> m_yes_button;
  48. RefPtr<GUI::Button> m_no_button;
  49. RefPtr<GUI::Button> m_cancel_button;
  50. RefPtr<Label> m_text_label;
  51. };
  52. }