LibGUI+Userland: Switch order of parameters for InputBox::show

Because usage of the input_type parameter is now higher than of the
placeholder parameter, this makes for a cleaner API.
This commit is contained in:
Karol Baraniecki 2022-12-30 21:13:54 +01:00 committed by Andrew Kaster
parent 8095d9276b
commit 506c26acce
Notes: sideshowbarker 2024-07-17 01:27:18 +09:00
13 changed files with 20 additions and 20 deletions

View file

@ -438,7 +438,7 @@ void BrowserWindow::build_menus()
auto custom_user_agent = GUI::Action::create_checkable("Custom...", [this](auto& action) {
DeprecatedString user_agent;
if (GUI::InputBox::show(this, user_agent, "Enter User Agent:"sv, "Custom User Agent"sv, {}, GUI::InputType::NonemptyText) != GUI::InputBox::ExecResult::OK) {
if (GUI::InputBox::show(this, user_agent, "Enter User Agent:"sv, "Custom User Agent"sv, GUI::InputType::NonemptyText) != GUI::InputBox::ExecResult::OK) {
m_disable_user_agent_spoofing->activate();
return;
}
@ -529,7 +529,7 @@ ErrorOr<void> BrowserWindow::load_search_engines(GUI::Menu& settings_menu)
auto custom_search_engine_action = GUI::Action::create_checkable("Custom...", [&](auto& action) {
DeprecatedString search_engine;
if (GUI::InputBox::show(this, search_engine, "Enter URL template:"sv, "Custom Search Engine"sv, "https://host/search?q={}"sv, GUI::InputType::NonemptyText) != GUI::InputBox::ExecResult::OK) {
if (GUI::InputBox::show(this, search_engine, "Enter URL template:"sv, "Custom Search Engine"sv, GUI::InputType::NonemptyText, "https://host/search?q={}"sv) != GUI::InputBox::ExecResult::OK) {
m_disable_search_engine_action->activate();
return;
}

View file

@ -119,7 +119,7 @@ ContentFilterSettingsWidget::ContentFilterSettingsWidget()
m_add_new_domain_button->on_click = [&](unsigned) {
DeprecatedString text;
if (GUI::InputBox::show(window(), text, "Enter domain name"sv, "Add domain to Content Filter"sv, {}, GUI::InputType::NonemptyText) == GUI::Dialog::ExecResult::OK) {
if (GUI::InputBox::show(window(), text, "Enter domain name"sv, "Add domain to Content Filter"sv, GUI::InputType::NonemptyText) == GUI::Dialog::ExecResult::OK) {
m_domain_list_model->add_domain(move(text));
set_modified(true);
}

View file

@ -70,7 +70,7 @@ CharacterMapWidget::CharacterMapWidget()
m_go_to_glyph_action = GUI::Action::create("Go to glyph...", { Mod_Ctrl, Key_G }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-to.png"sv).release_value_but_fixme_should_propagate_errors(), [&](auto&) {
DeprecatedString input;
if (GUI::InputBox::show(window(), input, "Hexadecimal:"sv, "Go to glyph"sv, {}, GUI::InputType::NonemptyText) == GUI::InputBox::ExecResult::OK) {
if (GUI::InputBox::show(window(), input, "Hexadecimal:"sv, "Go to glyph"sv, GUI::InputType::NonemptyText) == GUI::InputBox::ExecResult::OK) {
auto maybe_code_point = AK::StringUtils::convert_to_uint_from_hex(input);
if (!maybe_code_point.has_value())
return;

View file

@ -577,7 +577,7 @@ void DirectoryView::setup_actions()
{
m_mkdir_action = GUI::Action::create("&New Directory...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/mkdir.png"sv).release_value_but_fixme_should_propagate_errors(), [&](GUI::Action const&) {
DeprecatedString value;
if (GUI::InputBox::show(window(), value, "Enter name:"sv, "New directory"sv, {}, GUI::InputType::NonemptyText) == GUI::InputBox::ExecResult::OK) {
if (GUI::InputBox::show(window(), value, "Enter name:"sv, "New directory"sv, GUI::InputType::NonemptyText) == GUI::InputBox::ExecResult::OK) {
auto new_dir_path = LexicalPath::canonicalized_path(DeprecatedString::formatted("{}/{}", path(), value));
int rc = mkdir(new_dir_path.characters(), 0777);
if (rc < 0) {
@ -589,7 +589,7 @@ void DirectoryView::setup_actions()
m_touch_action = GUI::Action::create("New &File...", { Mod_Ctrl | Mod_Shift, Key_F }, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"sv).release_value_but_fixme_should_propagate_errors(), [&](GUI::Action const&) {
DeprecatedString value;
if (GUI::InputBox::show(window(), value, "Enter name:"sv, "New file"sv, {}, GUI::InputType::NonemptyText) == GUI::InputBox::ExecResult::OK) {
if (GUI::InputBox::show(window(), value, "Enter name:"sv, "New file"sv, GUI::InputType::NonemptyText) == GUI::InputBox::ExecResult::OK) {
auto new_file_path = LexicalPath::canonicalized_path(DeprecatedString::formatted("{}/{}", path(), value));
struct stat st;
int rc = stat(new_file_path.characters(), &st);

View file

@ -243,7 +243,7 @@ ErrorOr<void> MainWidget::create_actions()
m_go_to_glyph_action = GUI::Action::create("&Go to Glyph...", { Mod_Ctrl, Key_G }, TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/go-to.png"sv)), [&](auto&) {
DeprecatedString input;
if (GUI::InputBox::show(window(), input, "Hexadecimal:"sv, "Go to glyph"sv, {}, GUI::InputType::NonemptyText) == GUI::InputBox::ExecResult::OK) {
if (GUI::InputBox::show(window(), input, "Hexadecimal:"sv, "Go to glyph"sv, GUI::InputType::NonemptyText) == GUI::InputBox::ExecResult::OK) {
auto maybe_code_point = AK::StringUtils::convert_to_uint_from_hex(input);
if (!maybe_code_point.has_value())
return;

View file

@ -100,7 +100,7 @@ HexEditorWidget::HexEditorWidget()
m_new_action = GUI::Action::create("New", { Mod_Ctrl, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"sv).release_value_but_fixme_should_propagate_errors(), [this](const GUI::Action&) {
DeprecatedString value;
if (request_close() && GUI::InputBox::show(window(), value, "Enter new file size:"sv, "New file size"sv, {}, GUI::InputType::NonemptyText) == GUI::InputBox::ExecResult::OK) {
if (request_close() && GUI::InputBox::show(window(), value, "Enter new file size:"sv, "New file size"sv, GUI::InputType::NonemptyText) == GUI::InputBox::ExecResult::OK) {
auto file_size = value.to_uint();
if (!file_size.has_value()) {
GUI::MessageBox::show(window(), "Invalid file size entered."sv, "Error"sv, GUI::MessageBox::Type::Error);
@ -243,7 +243,7 @@ HexEditorWidget::HexEditorWidget()
m_fill_selection_action = GUI::Action::create("Fill &Selection...", { Mod_Ctrl, Key_B }, [&](const GUI::Action&) {
DeprecatedString value;
if (GUI::InputBox::show(window(), value, "Fill byte (hex):"sv, "Fill Selection"sv, {}, GUI::InputType::NonemptyText) == GUI::InputBox::ExecResult::OK) {
if (GUI::InputBox::show(window(), value, "Fill byte (hex):"sv, "Fill Selection"sv, GUI::InputType::NonemptyText) == GUI::InputBox::ExecResult::OK) {
auto fill_byte = strtol(value.characters(), nullptr, 16);
auto result = m_editor->fill_selection(fill_byte);
if (result.is_error())

View file

@ -370,7 +370,7 @@ PDF::PDFErrorOr<void> PDFViewerWidget::try_open_file(StringView path, NonnullOwn
if (auto sh = document->security_handler(); sh && !sh->has_user_password()) {
DeprecatedString password;
while (true) {
auto result = GUI::InputBox::show(window(), password, "Password"sv, "Password required"sv, {}, GUI::InputType::Password);
auto result = GUI::InputBox::show(window(), password, "Password"sv, "Password required"sv, GUI::InputType::Password);
if (result == GUI::Dialog::ExecResult::OK
&& document->security_handler()->try_provide_user_password(password))
break;

View file

@ -119,7 +119,7 @@ GalleryWidget::GalleryWidget()
m_input_button->on_click = [&](auto) {
DeprecatedString value;
if (GUI::InputBox::show(window(), value, "Enter input:"sv, "Input"sv, {}, GUI::InputType::NonemptyText) == GUI::InputBox::ExecResult::OK)
if (GUI::InputBox::show(window(), value, "Enter input:"sv, "Input"sv, GUI::InputType::NonemptyText) == GUI::InputBox::ExecResult::OK)
m_text_editor->set_text(value);
};

View file

@ -76,7 +76,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(settings_menu->try_add_action(GUI::Action::create("Set &Word Length", [&](auto&) {
auto word_length = Config::read_i32("MasterWord"sv, ""sv, "word_length"sv, 5);
auto word_length_string = DeprecatedString::number(word_length);
if (GUI::InputBox::show(window, word_length_string, "Word length:"sv, "MasterWord"sv, {}, GUI::InputType::NonemptyText) == GUI::InputBox::ExecResult::OK) {
if (GUI::InputBox::show(window, word_length_string, "Word length:"sv, "MasterWord"sv, GUI::InputType::NonemptyText) == GUI::InputBox::ExecResult::OK) {
auto maybe_word_length = word_length_string.template to_uint();
if (!maybe_word_length.has_value() || maybe_word_length.value() < shortest_word || maybe_word_length.value() > longest_word) {
GUI::MessageBox::show(window, DeprecatedString::formatted("Please enter a number between {} and {}.", shortest_word, longest_word), "MasterWord"sv);
@ -92,7 +92,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(settings_menu->try_add_action(GUI::Action::create("Set &Number Of Guesses", [&](auto&) {
auto max_guesses = Config::read_i32("MasterWord"sv, ""sv, "max_guesses"sv, 5);
auto max_guesses_string = DeprecatedString::number(max_guesses);
if (GUI::InputBox::show(window, max_guesses_string, "Maximum number of guesses:"sv, "MasterWord"sv, {}, GUI::InputType::NonemptyText) == GUI::InputBox::ExecResult::OK) {
if (GUI::InputBox::show(window, max_guesses_string, "Maximum number of guesses:"sv, "MasterWord"sv, GUI::InputType::NonemptyText) == GUI::InputBox::ExecResult::OK) {
auto maybe_max_guesses = max_guesses_string.template to_uint();
if (!maybe_max_guesses.has_value() || maybe_max_guesses.value() < 1 || maybe_max_guesses.value() > 20) {
GUI::MessageBox::show(window, "Please enter a number between 1 and 20."sv, "MasterWord"sv);

View file

@ -163,7 +163,7 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, StringView filename, St
auto mkdir_action = Action::create(
"New directory...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/mkdir.png"sv).release_value_but_fixme_should_propagate_errors(), [this](Action const&) {
DeprecatedString value;
if (InputBox::show(this, value, "Enter name:"sv, "New directory"sv, {}, GUI::InputType::NonemptyText) == InputBox::ExecResult::OK) {
if (InputBox::show(this, value, "Enter name:"sv, "New directory"sv, GUI::InputType::NonemptyText) == InputBox::ExecResult::OK) {
auto new_dir_path = LexicalPath::canonicalized_path(DeprecatedString::formatted("{}/{}", m_model->root_path(), value));
int rc = mkdir(new_dir_path.characters(), 0777);
if (rc < 0) {

View file

@ -15,7 +15,7 @@
namespace GUI {
InputBox::InputBox(Window* parent_window, DeprecatedString text_value, StringView prompt, StringView title, StringView placeholder, InputType input_type)
InputBox::InputBox(Window* parent_window, DeprecatedString text_value, StringView prompt, StringView title, InputType input_type, StringView placeholder)
: Dialog(parent_window)
, m_text_value(move(text_value))
, m_prompt(prompt)
@ -25,9 +25,9 @@ InputBox::InputBox(Window* parent_window, DeprecatedString text_value, StringVie
build(input_type);
}
Dialog::ExecResult InputBox::show(Window* parent_window, DeprecatedString& text_value, StringView prompt, StringView title, StringView placeholder, InputType input_type)
Dialog::ExecResult InputBox::show(Window* parent_window, DeprecatedString& text_value, StringView prompt, StringView title, InputType input_type, StringView placeholder)
{
auto box = InputBox::construct(parent_window, text_value, prompt, title, placeholder, input_type);
auto box = InputBox::construct(parent_window, text_value, prompt, title, input_type, placeholder);
box->set_resizable(false);
if (parent_window)
box->set_icon(parent_window->icon());

View file

@ -23,13 +23,13 @@ class InputBox : public Dialog {
public:
virtual ~InputBox() override = default;
static ExecResult show(Window* parent_window, DeprecatedString& text_value, StringView prompt, StringView title, StringView placeholder = {}, InputType input_type = InputType::Text);
static ExecResult show(Window* parent_window, DeprecatedString& text_value, StringView prompt, StringView title, InputType input_type = InputType::Text, StringView placeholder = {});
DeprecatedString const& text_value() const { return m_text_value; }
void set_text_value(DeprecatedString text_value);
private:
explicit InputBox(Window* parent_window, DeprecatedString text_value, StringView prompt, StringView title, StringView placeholder, InputType input_type);
explicit InputBox(Window* parent_window, DeprecatedString text_value, StringView prompt, StringView title, InputType input_type, StringView placeholder);
virtual void on_done(ExecResult) override;
void build(InputType input_type);

View file

@ -367,7 +367,7 @@ void OutOfProcessWebView::notify_server_did_request_confirm(Badge<WebContentClie
void OutOfProcessWebView::notify_server_did_request_prompt(Badge<WebContentClient>, DeprecatedString const& message, DeprecatedString const& default_)
{
m_dialog = GUI::InputBox::construct(window(), default_, message, "Prompt"sv, StringView {}, GUI::InputType::Text);
m_dialog = GUI::InputBox::construct(window(), default_, message, "Prompt"sv, GUI::InputType::Text, StringView {});
m_dialog->set_icon(window()->icon());
if (m_dialog->exec() == GUI::InputBox::ExecResult::OK)