InputBox.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, networkException <networkexception@serenityos.org>
  4. * Copyright (c) 2022, the SerenityOS developers.
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <LibGUI/Dialog.h>
  10. namespace GUI {
  11. enum class InputType {
  12. Text,
  13. NonemptyText,
  14. Password
  15. };
  16. class InputBox : public Dialog {
  17. C_OBJECT_ABSTRACT(InputBox)
  18. public:
  19. virtual ~InputBox() override = default;
  20. static ExecResult show(Window* parent_window, String& text_value, StringView prompt, StringView title, InputType input_type = InputType::Text, StringView placeholder = {});
  21. static ErrorOr<ExecResult> try_show(Window* parent_window, String& text_value, StringView prompt, StringView title, InputType input_type = InputType::Text, StringView placeholder = {});
  22. static ErrorOr<NonnullRefPtr<InputBox>> create(Window* parent_window, String text_value, StringView prompt, StringView title, InputType input_type);
  23. String const& text_value() const { return m_text_value; }
  24. void set_text_value(String);
  25. void set_placeholder(StringView);
  26. private:
  27. InputBox(Window* parent_window, String text_value, String title, String prompt, InputType input_type);
  28. virtual void on_done(ExecResult) override;
  29. ErrorOr<void> build();
  30. String m_text_value;
  31. String m_prompt;
  32. InputType m_input_type;
  33. RefPtr<Button> m_ok_button;
  34. RefPtr<Button> m_cancel_button;
  35. RefPtr<TextEditor> m_text_editor;
  36. RefPtr<Label> m_prompt_label;
  37. };
  38. }