2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2022-09-12 16:06:24 +02:00
|
|
|
* Copyright (c) 2021, networkException <networkexception@serenityos.org>
|
2022-02-26 10:50:04 -07:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2019-03-19 01:41:00 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2020-02-06 20:33:02 +01:00
|
|
|
#include <LibGUI/Dialog.h>
|
2019-03-19 01:41:00 +01:00
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
namespace GUI {
|
2019-03-19 02:20:00 +01:00
|
|
|
|
2021-07-24 22:59:39 -06:00
|
|
|
enum class InputType {
|
|
|
|
|
Text,
|
2023-01-14 15:14:47 -07:00
|
|
|
NonemptyText,
|
2021-07-24 22:59:39 -06:00
|
|
|
Password
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
class InputBox : public Dialog {
|
2023-04-16 16:02:07 -04:00
|
|
|
C_OBJECT_ABSTRACT(InputBox)
|
2019-03-19 01:41:00 +01:00
|
|
|
public:
|
2022-02-26 10:50:04 -07:00
|
|
|
virtual ~InputBox() override = default;
|
2019-03-19 01:41:00 +01:00
|
|
|
|
2023-04-16 16:02:07 -04:00
|
|
|
static ExecResult show(Window* parent_window, String& text_value, StringView prompt, StringView title, InputType input_type = InputType::Text, StringView placeholder = {});
|
|
|
|
|
static ErrorOr<ExecResult> try_show(Window* parent_window, String& text_value, StringView prompt, StringView title, InputType input_type = InputType::Text, StringView placeholder = {});
|
|
|
|
|
static ErrorOr<NonnullRefPtr<InputBox>> create(Window* parent_window, String text_value, StringView prompt, StringView title, InputType input_type);
|
2019-03-19 01:41:00 +01:00
|
|
|
|
2023-04-16 16:02:07 -04:00
|
|
|
String const& text_value() const { return m_text_value; }
|
|
|
|
|
void set_text_value(String);
|
|
|
|
|
|
|
|
|
|
void set_placeholder(StringView);
|
2020-07-16 07:54:42 -06:00
|
|
|
|
2022-11-16 07:35:02 -05:00
|
|
|
private:
|
2023-04-16 16:02:07 -04:00
|
|
|
InputBox(Window* parent_window, String text_value, String title, String prompt, InputType input_type);
|
2020-07-16 07:54:42 -06:00
|
|
|
|
2022-11-16 07:35:02 -05:00
|
|
|
virtual void on_done(ExecResult) override;
|
2023-04-16 16:02:07 -04:00
|
|
|
ErrorOr<void> build();
|
2022-11-16 07:35:02 -05:00
|
|
|
|
2023-04-16 16:02:07 -04:00
|
|
|
String m_text_value;
|
|
|
|
|
String m_prompt;
|
2022-12-31 17:52:09 +01:00
|
|
|
InputType m_input_type;
|
2019-03-19 02:20:00 +01:00
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
RefPtr<Button> m_ok_button;
|
|
|
|
|
RefPtr<Button> m_cancel_button;
|
|
|
|
|
RefPtr<TextEditor> m_text_editor;
|
2023-04-16 16:02:07 -04:00
|
|
|
RefPtr<Label> m_prompt_label;
|
2019-03-19 01:41:00 +01:00
|
|
|
};
|
2020-02-02 15:07:41 +01:00
|
|
|
|
|
|
|
|
}
|