mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 13:47:42 +00:00
LibGUI: Verify NonemptyText InputBox doesn't result in an empty string
This commit is contained in:
parent
506c26acce
commit
71f5bbab42
2 changed files with 19 additions and 6 deletions
|
@ -19,10 +19,11 @@ InputBox::InputBox(Window* parent_window, DeprecatedString text_value, StringVie
|
||||||
: Dialog(parent_window)
|
: Dialog(parent_window)
|
||||||
, m_text_value(move(text_value))
|
, m_text_value(move(text_value))
|
||||||
, m_prompt(prompt)
|
, m_prompt(prompt)
|
||||||
|
, m_input_type(input_type)
|
||||||
, m_placeholder(placeholder)
|
, m_placeholder(placeholder)
|
||||||
{
|
{
|
||||||
set_title(title);
|
set_title(title);
|
||||||
build(input_type);
|
build();
|
||||||
}
|
}
|
||||||
|
|
||||||
Dialog::ExecResult InputBox::show(Window* parent_window, DeprecatedString& text_value, StringView prompt, StringView title, InputType input_type, StringView placeholder)
|
Dialog::ExecResult InputBox::show(Window* parent_window, DeprecatedString& text_value, StringView prompt, StringView title, InputType input_type, StringView placeholder)
|
||||||
|
@ -43,11 +44,22 @@ void InputBox::set_text_value(DeprecatedString text_value)
|
||||||
|
|
||||||
void InputBox::on_done(ExecResult result)
|
void InputBox::on_done(ExecResult result)
|
||||||
{
|
{
|
||||||
if (result == ExecResult::OK)
|
if (result == ExecResult::OK) {
|
||||||
m_text_value = m_text_editor->text();
|
m_text_value = m_text_editor->text();
|
||||||
|
|
||||||
|
switch (m_input_type) {
|
||||||
|
case InputType::Text:
|
||||||
|
case InputType::Password:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case InputType::NonemptyText:
|
||||||
|
VERIFY(!m_text_value.is_empty());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputBox::build(InputType input_type)
|
void InputBox::build()
|
||||||
{
|
{
|
||||||
auto widget = set_main_widget<Widget>().release_value_but_fixme_should_propagate_errors();
|
auto widget = set_main_widget<Widget>().release_value_but_fixme_should_propagate_errors();
|
||||||
|
|
||||||
|
@ -69,7 +81,7 @@ void InputBox::build(InputType input_type)
|
||||||
auto& label = label_editor_container.add<Label>(m_prompt);
|
auto& label = label_editor_container.add<Label>(m_prompt);
|
||||||
label.set_preferred_width(text_width);
|
label.set_preferred_width(text_width);
|
||||||
|
|
||||||
switch (input_type) {
|
switch (m_input_type) {
|
||||||
case InputType::Text:
|
case InputType::Text:
|
||||||
case InputType::NonemptyText:
|
case InputType::NonemptyText:
|
||||||
m_text_editor = label_editor_container.add<TextBox>();
|
m_text_editor = label_editor_container.add<TextBox>();
|
||||||
|
@ -114,7 +126,7 @@ void InputBox::build(InputType input_type)
|
||||||
};
|
};
|
||||||
m_text_editor->set_focus(true);
|
m_text_editor->set_focus(true);
|
||||||
|
|
||||||
if (input_type == InputType::NonemptyText) {
|
if (m_input_type == InputType::NonemptyText) {
|
||||||
m_text_editor->on_change = [this] {
|
m_text_editor->on_change = [this] {
|
||||||
m_ok_button->set_enabled(!m_text_editor->text().is_empty());
|
m_ok_button->set_enabled(!m_text_editor->text().is_empty());
|
||||||
};
|
};
|
||||||
|
|
|
@ -32,10 +32,11 @@ private:
|
||||||
explicit InputBox(Window* parent_window, DeprecatedString text_value, StringView prompt, StringView title, InputType input_type, StringView placeholder);
|
explicit InputBox(Window* parent_window, DeprecatedString text_value, StringView prompt, StringView title, InputType input_type, StringView placeholder);
|
||||||
|
|
||||||
virtual void on_done(ExecResult) override;
|
virtual void on_done(ExecResult) override;
|
||||||
void build(InputType input_type);
|
void build();
|
||||||
|
|
||||||
DeprecatedString m_text_value;
|
DeprecatedString m_text_value;
|
||||||
DeprecatedString m_prompt;
|
DeprecatedString m_prompt;
|
||||||
|
InputType m_input_type;
|
||||||
DeprecatedString m_placeholder;
|
DeprecatedString m_placeholder;
|
||||||
|
|
||||||
RefPtr<Button> m_ok_button;
|
RefPtr<Button> m_ok_button;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue