InputBox.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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(InputBox)
  18. public:
  19. virtual ~InputBox() override = default;
  20. static ExecResult show(Window* parent_window, DeprecatedString& text_value, StringView prompt, StringView title, InputType input_type = InputType::Text, StringView placeholder = {});
  21. DeprecatedString const& text_value() const { return m_text_value; }
  22. void set_text_value(DeprecatedString text_value);
  23. private:
  24. explicit InputBox(Window* parent_window, DeprecatedString text_value, StringView prompt, StringView title, InputType input_type, StringView placeholder);
  25. virtual void on_done(ExecResult) override;
  26. void build();
  27. DeprecatedString m_text_value;
  28. DeprecatedString m_prompt;
  29. InputType m_input_type;
  30. DeprecatedString m_placeholder;
  31. RefPtr<Button> m_ok_button;
  32. RefPtr<Button> m_cancel_button;
  33. RefPtr<TextEditor> m_text_editor;
  34. };
  35. }