diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp index dc092ba5cf..4f3a7e3088 100644 --- a/Applications/FileManager/main.cpp +++ b/Applications/FileManager/main.cpp @@ -164,12 +164,12 @@ int run_in_desktop_mode(RefPtr config, String initial_location auto desktop_view_context_menu = GUI::Menu::construct("Directory View"); auto mkdir_action = GUI::Action::create("New directory...", {}, Gfx::Bitmap::load_from_file("/res/icons/16x16/mkdir.png"), [&](const GUI::Action&) { - auto input_box = GUI::InputBox::construct("Enter name:", "New directory", window); - if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) { + String value; + if (GUI::InputBox::show(value, window, "Enter name:", "New directory") == GUI::InputBox::ExecOK && !value.is_empty()) { auto new_dir_path = LexicalPath::canonicalized_path( String::format("%s/%s", model->root_path().characters(), - input_box->text_value().characters())); + value.characters())); int rc = mkdir(new_dir_path.characters(), 0777); if (rc < 0) { GUI::MessageBox::show(window, String::format("mkdir(\"%s\") failed: %s", new_dir_path.characters(), strerror(errno)), "Error", GUI::MessageBox::Type::Error); @@ -178,12 +178,12 @@ int run_in_desktop_mode(RefPtr config, String initial_location }); auto touch_action = GUI::Action::create("New file...", {}, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"), [&](const GUI::Action&) { - auto input_box = GUI::InputBox::construct("Enter name:", "New file", window); - if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) { + String value; + if (GUI::InputBox::show(value, window, "Enter name:", "New file") == GUI::InputBox::ExecOK && !value.is_empty()) { auto new_file_path = LexicalPath::canonicalized_path( String::format("%s/%s", model->root_path().characters(), - input_box->text_value().characters())); + value.characters())); struct stat st; int rc = stat(new_file_path.characters(), &st); if ((rc < 0 && errno != ENOENT)) { @@ -322,12 +322,12 @@ int run_in_windowed_mode(RefPtr config, String initial_locatio }); auto mkdir_action = GUI::Action::create("New directory...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/mkdir.png"), [&](const GUI::Action&) { - auto input_box = GUI::InputBox::construct("Enter name:", "New directory", window); - if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) { + String value; + if (GUI::InputBox::show(value, window, "Enter name:", "New directory") == GUI::InputBox::ExecOK && !value.is_empty()) { auto new_dir_path = LexicalPath::canonicalized_path( String::format("%s/%s", directory_view.path().characters(), - input_box->text_value().characters())); + value.characters())); int rc = mkdir(new_dir_path.characters(), 0777); if (rc < 0) { GUI::MessageBox::show(window, String::format("mkdir(\"%s\") failed: %s", new_dir_path.characters(), strerror(errno)), "Error", GUI::MessageBox::Type::Error); @@ -338,12 +338,12 @@ int run_in_windowed_mode(RefPtr config, String initial_locatio }); auto touch_action = GUI::Action::create("New file...", { Mod_Ctrl | Mod_Shift, Key_F }, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"), [&](const GUI::Action&) { - auto input_box = GUI::InputBox::construct("Enter name:", "New file", window); - if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) { + String value; + if (GUI::InputBox::show(value, window, "Enter name:", "New file") == GUI::InputBox::ExecOK && !value.is_empty()) { auto new_file_path = LexicalPath::canonicalized_path( String::format("%s/%s", directory_view.path().characters(), - input_box->text_value().characters())); + value.characters())); struct stat st; int rc = stat(new_file_path.characters(), &st); if ((rc < 0 && errno != ENOENT)) { diff --git a/Applications/HexEditor/HexEditorWidget.cpp b/Applications/HexEditor/HexEditorWidget.cpp index 5e978d4004..3c4ff08367 100644 --- a/Applications/HexEditor/HexEditorWidget.cpp +++ b/Applications/HexEditor/HexEditorWidget.cpp @@ -77,9 +77,9 @@ HexEditorWidget::HexEditorWidget() m_save_action->activate(); } - auto input_box = GUI::InputBox::construct("Enter new file size:", "New file size", window()); - if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) { - auto file_size = input_box->text_value().to_int(); + String value; + if (GUI::InputBox::show(value, window(), "Enter new file size:", "New file size") == GUI::InputBox::ExecOK && !value.is_empty()) { + auto file_size = value.to_int(); if (file_size.has_value() && file_size.value() > 0) { m_document_dirty = false; m_editor->set_buffer(ByteBuffer::create_zeroed(file_size.value())); @@ -143,27 +143,27 @@ HexEditorWidget::HexEditorWidget() })); m_goto_decimal_offset_action = GUI::Action::create("Go To Offset (Decimal)...", { Mod_Ctrl | Mod_Shift, Key_G }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png"), [this](const GUI::Action&) { - auto input_box = GUI::InputBox::construct("Enter Decimal offset:", "Go To", window()); - if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) { - auto new_offset = input_box->text_value().to_int(); + String value; + if (GUI::InputBox::show(value, window(), "Enter Decimal offset:", "Go To") == GUI::InputBox::ExecOK && !value.is_empty()) { + auto new_offset = value.to_int(); if (new_offset.has_value()) m_editor->set_position(new_offset.value()); } }); m_goto_hex_offset_action = GUI::Action::create("Go To Offset (Hex)...", { Mod_Ctrl, Key_G }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png"), [this](const GUI::Action&) { - auto input_box = GUI::InputBox::construct("Enter Hex offset:", "Go To", window()); - if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) { - auto new_offset = strtol(input_box->text_value().characters(), nullptr, 16); + String value; + if (GUI::InputBox::show(value, window(), "Enter Hex offset:", "Go To") == GUI::InputBox::ExecOK && !value.is_empty()) { + auto new_offset = strtol(value.characters(), nullptr, 16); m_editor->set_position(new_offset); } }); auto& edit_menu = menubar->add_menu("Edit"); edit_menu.add_action(GUI::Action::create("Fill selection...", { Mod_Ctrl, Key_B }, [&](const GUI::Action&) { - auto input_box = GUI::InputBox::construct("Fill byte (hex):", "Fill Selection", window()); - if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) { - auto fill_byte = strtol(input_box->text_value().characters(), nullptr, 16); + String value; + if (GUI::InputBox::show(value, window(), "Fill byte (hex):", "Fill Selection") == GUI::InputBox::ExecOK && !value.is_empty()) { + auto fill_byte = strtol(value.characters(), nullptr, 16); m_editor->fill_selection(fill_byte); } })); diff --git a/Applications/IRCClient/IRCAppWindow.cpp b/Applications/IRCClient/IRCAppWindow.cpp index 8a01528b6d..be7afdcb00 100644 --- a/Applications/IRCClient/IRCAppWindow.cpp +++ b/Applications/IRCClient/IRCAppWindow.cpp @@ -94,12 +94,11 @@ void IRCAppWindow::setup_client() }; if (m_client->hostname().is_empty()) { - auto input_box = GUI::InputBox::construct("Enter server:", "Connect to server", this); - auto result = input_box->exec(); - if (result == GUI::InputBox::ExecCancel) + String value; + if (GUI::InputBox::show(value, this, "Enter server:", "Connect to server") == GUI::InputBox::ExecCancel) ::exit(0); - m_client->set_server(input_box->text_value(), 6667); + m_client->set_server(value, 6667); } update_title(); bool success = m_client->connect(); @@ -109,9 +108,9 @@ void IRCAppWindow::setup_client() void IRCAppWindow::setup_actions() { m_join_action = GUI::Action::create("Join channel", { Mod_Ctrl, Key_J }, Gfx::Bitmap::load_from_file("/res/icons/16x16/irc-join.png"), [&](auto&) { - auto input_box = GUI::InputBox::construct("Enter channel name:", "Join channel", this); - if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) - m_client->handle_join_action(input_box->text_value()); + String value; + if (GUI::InputBox::show(value, this, "Enter channel name:", "Join channel") == GUI::InputBox::ExecOK && !value.is_empty()) + m_client->handle_join_action(value); }); m_list_channels_action = GUI::Action::create("List channels", Gfx::Bitmap::load_from_file("/res/icons/16x16/irc-list.png"), [&](auto&) { @@ -127,15 +126,15 @@ void IRCAppWindow::setup_actions() }); m_whois_action = GUI::Action::create("Whois user", Gfx::Bitmap::load_from_file("/res/icons/16x16/irc-whois.png"), [&](auto&) { - auto input_box = GUI::InputBox::construct("Enter nickname:", "IRC WHOIS lookup", this); - if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) - m_client->handle_whois_action(input_box->text_value()); + String value; + if (GUI::InputBox::show(value, this, "Enter nickname:", "IRC WHOIS lookup") == GUI::InputBox::ExecOK && !value.is_empty()) + m_client->handle_whois_action(value); }); m_open_query_action = GUI::Action::create("Open query", { Mod_Ctrl, Key_O }, Gfx::Bitmap::load_from_file("/res/icons/16x16/irc-open-query.png"), [&](auto&) { - auto input_box = GUI::InputBox::construct("Enter nickname:", "Open IRC query with...", this); - if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) - m_client->handle_open_query_action(input_box->text_value()); + String value; + if (GUI::InputBox::show(value, this, "Enter nickname:", "Open IRC query with...") == GUI::InputBox::ExecOK && !value.is_empty()) + m_client->handle_open_query_action(value); }); m_close_query_action = GUI::Action::create("Close query", { Mod_Ctrl, Key_D }, Gfx::Bitmap::load_from_file("/res/icons/16x16/irc-close-query.png"), [](auto&) { @@ -143,9 +142,9 @@ void IRCAppWindow::setup_actions() }); m_change_nick_action = GUI::Action::create("Change nickname", Gfx::Bitmap::load_from_file("/res/icons/16x16/irc-nick.png"), [this](auto&) { - auto input_box = GUI::InputBox::construct("Enter nickname:", "Change nickname", this); - if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) - m_client->handle_change_nick_action(input_box->text_value()); + String value; + if (GUI::InputBox::show(value, this, "Enter nickname:", "Change nickname") == GUI::InputBox::ExecOK && !value.is_empty()) + m_client->handle_change_nick_action(value); }); m_change_topic_action = GUI::Action::create("Change topic", Gfx::Bitmap::load_from_file("/res/icons/16x16/irc-topic.png"), [this](auto&) { @@ -153,9 +152,9 @@ void IRCAppWindow::setup_actions() if (!window || window->type() != IRCWindow::Type::Channel) { return; } - auto input_box = GUI::InputBox::construct("Enter topic:", "Change topic", this); - if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) - m_client->handle_change_topic_action(window->channel().name(), input_box->text_value()); + String value; + if (GUI::InputBox::show(value, this, "Enter topic:", "Change topic") == GUI::InputBox::ExecOK && !value.is_empty()) + m_client->handle_change_topic_action(window->channel().name(), value); }); m_invite_user_action = GUI::Action::create("Invite user", Gfx::Bitmap::load_from_file("/res/icons/16x16/irc-invite.png"), [this](auto&) { @@ -163,9 +162,9 @@ void IRCAppWindow::setup_actions() if (!window || window->type() != IRCWindow::Type::Channel) { return; } - auto input_box = GUI::InputBox::construct("Enter nick:", "Invite user", this); - if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) - m_client->handle_invite_user_action(window->channel().name(), input_box->text_value()); + String value; + if (GUI::InputBox::show(value, this, "Enter nick:", "Invite user") == GUI::InputBox::ExecOK && !value.is_empty()) + m_client->handle_invite_user_action(window->channel().name(), value); }); m_banlist_action = GUI::Action::create("Ban list", [this](auto&) { @@ -181,9 +180,9 @@ void IRCAppWindow::setup_actions() if (!window || window->type() != IRCWindow::Type::Channel) { return; } - auto input_box = GUI::InputBox::construct("Enter nick:", "Voice user", this); - if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) - m_client->handle_voice_user_action(window->channel().name(), input_box->text_value()); + String value; + if (GUI::InputBox::show(value, this, "Enter nick:", "Voice user") == GUI::InputBox::ExecOK && !value.is_empty()) + m_client->handle_voice_user_action(window->channel().name(), value); }); m_devoice_user_action = GUI::Action::create("DeVoice user", [this](auto&) { @@ -191,9 +190,9 @@ void IRCAppWindow::setup_actions() if (!window || window->type() != IRCWindow::Type::Channel) { return; } - auto input_box = GUI::InputBox::construct("Enter nick:", "DeVoice user", this); - if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) - m_client->handle_devoice_user_action(window->channel().name(), input_box->text_value()); + String value; + if (GUI::InputBox::show(value, this, "Enter nick:", "DeVoice user") == GUI::InputBox::ExecOK && !value.is_empty()) + m_client->handle_devoice_user_action(window->channel().name(), value); }); m_hop_user_action = GUI::Action::create("Hop user", [this](auto&) { @@ -201,9 +200,9 @@ void IRCAppWindow::setup_actions() if (!window || window->type() != IRCWindow::Type::Channel) { return; } - auto input_box = GUI::InputBox::construct("Enter nick:", "Hop user", this); - if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) - m_client->handle_hop_user_action(window->channel().name(), input_box->text_value()); + String value; + if (GUI::InputBox::show(value, this, "Enter nick:", "Hop user") == GUI::InputBox::ExecOK && !value.is_empty()) + m_client->handle_hop_user_action(window->channel().name(), value); }); m_dehop_user_action = GUI::Action::create("DeHop user", [this](auto&) { @@ -211,9 +210,9 @@ void IRCAppWindow::setup_actions() if (!window || window->type() != IRCWindow::Type::Channel) { return; } - auto input_box = GUI::InputBox::construct("Enter nick:", "DeHop user", this); - if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) - m_client->handle_dehop_user_action(window->channel().name(), input_box->text_value()); + String value; + if (GUI::InputBox::show(value, this, "Enter nick:", "DeHop user") == GUI::InputBox::ExecOK && !value.is_empty()) + m_client->handle_dehop_user_action(window->channel().name(), value); }); m_op_user_action = GUI::Action::create("Op user", [this](auto&) { @@ -221,9 +220,9 @@ void IRCAppWindow::setup_actions() if (!window || window->type() != IRCWindow::Type::Channel) { return; } - auto input_box = GUI::InputBox::construct("Enter nick:", "Op user", this); - if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) - m_client->handle_op_user_action(window->channel().name(), input_box->text_value()); + String value; + if (GUI::InputBox::show(value, this, "Enter nick:", "Op user") == GUI::InputBox::ExecOK && !value.is_empty()) + m_client->handle_op_user_action(window->channel().name(), value); }); m_deop_user_action = GUI::Action::create("DeOp user", [this](auto&) { @@ -231,9 +230,9 @@ void IRCAppWindow::setup_actions() if (!window || window->type() != IRCWindow::Type::Channel) { return; } - auto input_box = GUI::InputBox::construct("Enter nick:", "DeOp user", this); - if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) - m_client->handle_deop_user_action(window->channel().name(), input_box->text_value()); + String value; + if (GUI::InputBox::show(value, this, "Enter nick:", "DeOp user") == GUI::InputBox::ExecOK && !value.is_empty()) + m_client->handle_deop_user_action(window->channel().name(), value); }); m_kick_user_action = GUI::Action::create("Kick user", [this](auto&) { @@ -241,11 +240,12 @@ void IRCAppWindow::setup_actions() if (!window || window->type() != IRCWindow::Type::Channel) { return; } - auto input_box = GUI::InputBox::construct("Enter nick:", "Kick user", this); - auto reason_box = GUI::InputBox::construct("Enter reason:", "Reason", this); - if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) - if (reason_box->exec() == GUI::InputBox::ExecOK) - m_client->handle_kick_user_action(window->channel().name(), input_box->text_value(), reason_box->text_value().characters()); + String nick_value; + if (GUI::InputBox::show(nick_value, this, "Enter nick:", "Kick user") != GUI::InputBox::ExecOK || nick_value.is_empty()) + return; + String reason_value; + if (GUI::InputBox::show(reason_value, this, "Enter reason:", "Reason") == GUI::InputBox::ExecOK) + m_client->handle_kick_user_action(window->channel().name(), nick_value, reason_value.characters()); }); m_cycle_channel_action = GUI::Action::create("Cycle channel", [this](auto&) { diff --git a/Applications/IRCClient/IRCWindow.cpp b/Applications/IRCClient/IRCWindow.cpp index 8dbf3009d4..26f6c62936 100644 --- a/Applications/IRCClient/IRCWindow.cpp +++ b/Applications/IRCClient/IRCWindow.cpp @@ -96,7 +96,6 @@ IRCWindow::IRCWindow(IRCClient& client, void* owner, Type type, const String& na auto nick = channel().member_model()->nick_at(member_view.selection().first()); if (nick.is_empty()) return; - auto input_box = GUI::InputBox::construct("Enter reason:", "Reason"); m_client.handle_voice_user_action(m_name.characters(), m_client.nick_without_prefix(nick.characters())); })); @@ -143,9 +142,9 @@ IRCWindow::IRCWindow(IRCClient& client, void* owner, Type type, const String& na return; if (IRCClient::is_nick_prefix(nick[0])) nick = nick.substring(1, nick.length() - 1); - auto input_box = GUI::InputBox::construct("Enter reason:", "Reason"); - if (input_box->exec() == GUI::InputBox::ExecOK) - m_client.handle_kick_user_action(m_name.characters(), m_client.nick_without_prefix(nick.characters()), input_box->text_value()); + String value; + if (GUI::InputBox::show(value, window(), "Enter reason:", "Reason") == GUI::InputBox::ExecOK) + m_client.handle_kick_user_action(m_name.characters(), m_client.nick_without_prefix(nick.characters()), value); })); auto& context_ctcp_menu = m_context_menu->add_submenu("CTCP"); diff --git a/Applications/KeyboardMapper/KeyboardMapperWidget.cpp b/Applications/KeyboardMapper/KeyboardMapperWidget.cpp index c4eca7c29f..72283e19aa 100644 --- a/Applications/KeyboardMapper/KeyboardMapperWidget.cpp +++ b/Applications/KeyboardMapper/KeyboardMapperWidget.cpp @@ -66,10 +66,8 @@ void KeyboardMapperWidget::create_frame() tmp_button.set_enabled(keys[i].enabled); tmp_button.on_click = [&]() { - auto input_box = GUI::InputBox::construct("New Character:", "Select Character", window()); - if (input_box->exec() == GUI::InputBox::ExecOK) { - auto value = input_box->text_value(); - + String value; + if (GUI::InputBox::show(value, window(), "New Character:", "Select Character") == GUI::InputBox::ExecOK) { int i = m_keys.find_first_index(&tmp_button).value_or(0); ASSERT(i > 0); diff --git a/DevTools/HackStudio/Debugger/DebugInfoWidget.cpp b/DevTools/HackStudio/Debugger/DebugInfoWidget.cpp index 7ef5299dac..2b310fa7dd 100644 --- a/DevTools/HackStudio/Debugger/DebugInfoWidget.cpp +++ b/DevTools/HackStudio/Debugger/DebugInfoWidget.cpp @@ -84,11 +84,10 @@ DebugInfoWidget::DebugInfoWidget() if (!is_valid_index(index)) return; - auto input = GUI::InputBox::construct("Enter new value:", "Set variable value", window()); - - if (input->exec() == GUI::InputBox::ExecOK) { + String value; + if (GUI::InputBox::show(value, window(), "Enter new value:", "Set variable value") == GUI::InputBox::ExecOK) { auto& model = static_cast(*m_variables_view->model()); - model.set_variable_value(index, input->text_value(), window()); + model.set_variable_value(index, value, window()); } }; } diff --git a/DevTools/HackStudio/main.cpp b/DevTools/HackStudio/main.cpp index 13f2937c44..a270ae50c4 100644 --- a/DevTools/HackStudio/main.cpp +++ b/DevTools/HackStudio/main.cpp @@ -203,10 +203,9 @@ int main(int argc, char** argv) }; auto new_action = GUI::Action::create("Add new file to project...", { Mod_Ctrl, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"), [&](const GUI::Action&) { - auto input_box = GUI::InputBox::construct("Enter name of new file:", "Add new file to project", g_window); - if (input_box->exec() == GUI::InputBox::ExecCancel) + String filename; + if (GUI::InputBox::show(filename, g_window, "Enter name of new file:", "Add new file to project") != GUI::InputBox::ExecOK) return; - auto filename = input_box->text_value(); auto file = Core::File::construct(filename); if (!file->open((Core::IODevice::OpenMode)(Core::IODevice::WriteOnly | Core::IODevice::MustBeNew))) { GUI::MessageBox::show(g_window, String::format("Failed to create '%s'", filename.characters()), "Error", GUI::MessageBox::Type::Error); diff --git a/Libraries/LibGUI/FilePicker.cpp b/Libraries/LibGUI/FilePicker.cpp index 8cc3f4c0fa..7ec373e2a1 100644 --- a/Libraries/LibGUI/FilePicker.cpp +++ b/Libraries/LibGUI/FilePicker.cpp @@ -152,11 +152,11 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, Options options, const toolbar.add_separator(); auto mkdir_action = Action::create("New directory...", Gfx::Bitmap::load_from_file("/res/icons/16x16/mkdir.png"), [this](const Action&) { - auto& input_box = add("Enter name:", "New directory"); - if (input_box.exec() == InputBox::ExecOK && !input_box.text_value().is_empty()) { + String value; + if (InputBox::show(value, this, "Enter name:", "New directory") == InputBox::ExecOK && !value.is_empty()) { auto new_dir_path = LexicalPath(String::format("%s/%s", m_model->root_path().characters(), - input_box.text_value().characters())) + value.characters())) .string(); int rc = mkdir(new_dir_path.characters(), 0777); if (rc < 0) { diff --git a/Libraries/LibGUI/InputBox.cpp b/Libraries/LibGUI/InputBox.cpp index e8322a68cc..388437751e 100644 --- a/Libraries/LibGUI/InputBox.cpp +++ b/Libraries/LibGUI/InputBox.cpp @@ -34,7 +34,7 @@ namespace GUI { -InputBox::InputBox(const StringView& prompt, const StringView& title, GUI::Window* parent_window) +InputBox::InputBox(Window* parent_window, const StringView& prompt, const StringView& title) : Dialog(parent_window) , m_prompt(prompt) { @@ -46,6 +46,14 @@ InputBox::~InputBox() { } +int InputBox::show(String& text_value, Window* parent_window, const StringView& prompt, const StringView& title) +{ + auto box = InputBox::construct(parent_window, prompt, title); + auto result = box->exec(); + text_value = box->text_value(); + return result; +} + void InputBox::build() { auto& widget = set_main_widget(); diff --git a/Libraries/LibGUI/InputBox.h b/Libraries/LibGUI/InputBox.h index 4df9917eee..1eb7c490d6 100644 --- a/Libraries/LibGUI/InputBox.h +++ b/Libraries/LibGUI/InputBox.h @@ -33,12 +33,15 @@ namespace GUI { class InputBox : public Dialog { C_OBJECT(InputBox) public: - explicit InputBox(const StringView& prompt, const StringView& title, Window* parent_window = nullptr); virtual ~InputBox() override; + static int show(String& text_value, Window* parent_window, const StringView& prompt, const StringView& title); + +private: + explicit InputBox(Window* parent_window, const StringView& prompt, const StringView& title); + String text_value() const { return m_text_value; } -private: void build(); String m_prompt; String m_text_value; diff --git a/Libraries/LibGUI/TextEditor.cpp b/Libraries/LibGUI/TextEditor.cpp index ae0749d093..414b03462f 100644 --- a/Libraries/LibGUI/TextEditor.cpp +++ b/Libraries/LibGUI/TextEditor.cpp @@ -87,10 +87,9 @@ void TextEditor::create_actions() if (is_multi_line()) { m_go_to_line_action = Action::create( "Go to line...", { Mod_Ctrl, Key_L }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png"), [this](auto&) { - auto input_box = InputBox::construct("Line:", "Go to line", window()); - auto result = input_box->exec(); - if (result == InputBox::ExecOK) { - auto line_number = input_box->text_value().to_uint(); + String value; + if (InputBox::show(value, window(), "Line:", "Go to line") == InputBox::ExecOK) { + auto line_number = value.to_uint(); if (line_number.has_value()) set_cursor(line_number.value() - 1, 0); }