summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-11-16 07:35:02 -0500
committerLinus Groh <mail@linusgroh.de>2022-11-16 17:23:56 +0000
commit5b31a3dbc7358de2b1a3ae6272be7f3fce0d5445 (patch)
tree0bfd6016831f15e5a38c9beaad384e13e8f1fe50 /Userland/Libraries/LibGUI
parentdb4fa36b583dc06df67538c409bf489617b99ae7 (diff)
downloadserenity-5b31a3dbc7358de2b1a3ae6272be7f3fce0d5445.zip
LibGUI: Allow more programmatic control over GUI::InputBox
This will be needed for WebDriver, which will require constructing and controlling dialogs manually. Currently, InputBox will only set its text value when the OK button is pressed. This changes InputBox to update its text when done(ExecResult::OK) is invoked in any way. This also makes the text_value() method public, allows for setting the text value, and allows for moving-in the initial text value.
Diffstat (limited to 'Userland/Libraries/LibGUI')
-rw-r--r--Userland/Libraries/LibGUI/Dialog.cpp2
-rw-r--r--Userland/Libraries/LibGUI/Dialog.h2
-rw-r--r--Userland/Libraries/LibGUI/InputBox.cpp16
-rw-r--r--Userland/Libraries/LibGUI/InputBox.h9
4 files changed, 23 insertions, 6 deletions
diff --git a/Userland/Libraries/LibGUI/Dialog.cpp b/Userland/Libraries/LibGUI/Dialog.cpp
index 3d6767010a..199ea47326 100644
--- a/Userland/Libraries/LibGUI/Dialog.cpp
+++ b/Userland/Libraries/LibGUI/Dialog.cpp
@@ -115,6 +115,8 @@ void Dialog::done(ExecResult result)
if (!m_event_loop)
return;
m_result = result;
+ on_done(m_result);
+
dbgln("{}: Quit event loop with result {}", *this, to_underlying(result));
m_event_loop->quit(to_underlying(result));
}
diff --git a/Userland/Libraries/LibGUI/Dialog.h b/Userland/Libraries/LibGUI/Dialog.h
index 4f7b869932..a78b9536a3 100644
--- a/Userland/Libraries/LibGUI/Dialog.h
+++ b/Userland/Libraries/LibGUI/Dialog.h
@@ -52,6 +52,8 @@ public:
protected:
explicit Dialog(Window* parent_window, ScreenPosition = ScreenPosition::CenterWithinParent);
+ virtual void on_done(ExecResult) { }
+
private:
OwnPtr<Core::EventLoop> m_event_loop;
ExecResult m_result { ExecResult::Aborted };
diff --git a/Userland/Libraries/LibGUI/InputBox.cpp b/Userland/Libraries/LibGUI/InputBox.cpp
index 0fffa1e9dc..1bc8b9478e 100644
--- a/Userland/Libraries/LibGUI/InputBox.cpp
+++ b/Userland/Libraries/LibGUI/InputBox.cpp
@@ -15,9 +15,9 @@
namespace GUI {
-InputBox::InputBox(Window* parent_window, String& text_value, StringView prompt, StringView title, StringView placeholder, InputType input_type)
+InputBox::InputBox(Window* parent_window, String text_value, StringView prompt, StringView title, StringView placeholder, InputType input_type)
: Dialog(parent_window)
- , m_text_value(text_value)
+ , m_text_value(move(text_value))
, m_prompt(prompt)
, m_placeholder(placeholder)
{
@@ -36,6 +36,17 @@ Dialog::ExecResult InputBox::show(Window* parent_window, String& text_value, Str
return result;
}
+void InputBox::set_text_value(String text_value)
+{
+ m_text_editor->set_text(move(text_value));
+}
+
+void InputBox::on_done(ExecResult result)
+{
+ if (result == ExecResult::OK)
+ m_text_value = m_text_editor->text();
+}
+
void InputBox::build(InputType input_type)
{
auto& widget = set_main_widget<Widget>();
@@ -86,7 +97,6 @@ void InputBox::build(InputType input_type)
m_ok_button->set_text("OK");
m_ok_button->on_click = [this](auto) {
dbgln("GUI::InputBox: OK button clicked");
- m_text_value = m_text_editor->text();
done(ExecResult::OK);
};
m_ok_button->set_default(true);
diff --git a/Userland/Libraries/LibGUI/InputBox.h b/Userland/Libraries/LibGUI/InputBox.h
index f34c542035..2c15bda02f 100644
--- a/Userland/Libraries/LibGUI/InputBox.h
+++ b/Userland/Libraries/LibGUI/InputBox.h
@@ -24,12 +24,15 @@ public:
static ExecResult show(Window* parent_window, String& text_value, StringView prompt, StringView title, StringView placeholder = {}, InputType input_type = InputType::Text);
-private:
- explicit InputBox(Window* parent_window, String& text_value, StringView prompt, StringView title, StringView placeholder, InputType input_type);
+ String const& text_value() const { return m_text_value; }
+ void set_text_value(String text_value);
- String text_value() const { return m_text_value; }
+private:
+ explicit InputBox(Window* parent_window, String text_value, StringView prompt, StringView title, StringView placeholder, InputType input_type);
+ virtual void on_done(ExecResult) override;
void build(InputType input_type);
+
String m_text_value;
String m_prompt;
String m_placeholder;