MessageBox.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 FileSystemAccessServer {
  11. class ConnectionFromClient;
  12. }
  13. namespace GUI {
  14. class MessageBox : public Dialog {
  15. C_OBJECT_ABSTRACT(MessageBox)
  16. public:
  17. enum class Type {
  18. None,
  19. Information,
  20. Warning,
  21. Error,
  22. Question
  23. };
  24. enum class InputType {
  25. OK,
  26. OKCancel,
  27. YesNo,
  28. YesNoCancel,
  29. };
  30. virtual ~MessageBox() override = default;
  31. static ExecResult show(Window* parent_window, StringView text, StringView title, Type type = Type::None, InputType input_type = InputType::OK);
  32. static ExecResult show_error(Window* parent_window, StringView text);
  33. static ExecResult ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<MonotonicTime> last_unmodified_timestamp = {});
  34. static ErrorOr<ExecResult> try_show(Badge<FileSystemAccessServer::ConnectionFromClient>, i32 window_server_client_id, i32 parent_window_id, StringView text, StringView title);
  35. static ErrorOr<ExecResult> try_show(Window* parent_window, StringView text, StringView title, Type type = Type::None, InputType input_type = InputType::OK);
  36. static ErrorOr<ExecResult> try_show_error(Window* parent_window, StringView text);
  37. static ErrorOr<ExecResult> try_ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<MonotonicTime> last_unmodified_timestamp = {});
  38. static ErrorOr<NonnullRefPtr<MessageBox>> create(Window* parent_window, StringView text, StringView title, Type type = Type::None, InputType input_type = InputType::OK);
  39. void set_text(String);
  40. private:
  41. MessageBox(Window* parent_window, Type type = Type::None, InputType input_type = InputType::OK);
  42. bool should_include_ok_button() const;
  43. bool should_include_cancel_button() const;
  44. bool should_include_yes_button() const;
  45. bool should_include_no_button() const;
  46. ErrorOr<void> build();
  47. ErrorOr<RefPtr<Gfx::Bitmap>> icon() const;
  48. Type m_type { Type::None };
  49. InputType m_input_type { InputType::OK };
  50. RefPtr<GUI::Button> m_ok_button;
  51. RefPtr<GUI::Button> m_yes_button;
  52. RefPtr<GUI::Button> m_no_button;
  53. RefPtr<GUI::Button> m_cancel_button;
  54. RefPtr<Label> m_text_label;
  55. };
  56. }