diff options
author | thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> | 2023-04-16 16:02:07 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-04-18 10:05:21 +0200 |
commit | 02a9e5d3f681bbf3c6157d368e95ad3183b200be (patch) | |
tree | e8c1d278cd1863fbeff9900500a040370140b728 /Userland/Applications | |
parent | 9c2bcffe83ae92c8c710e7ed34dd4ee82710a76a (diff) | |
download | serenity-02a9e5d3f681bbf3c6157d368e95ad3183b200be.zip |
LibGUI+Userland: Improve error and font handling for InputBox
Adds fallible factories, ports DeprecatedString, and rebuilds the
layout to accomodate system font changes.
Diffstat (limited to 'Userland/Applications')
10 files changed, 29 insertions, 29 deletions
diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp index 65f4335549..5495256728 100644 --- a/Userland/Applications/Browser/BrowserWindow.cpp +++ b/Userland/Applications/Browser/BrowserWindow.cpp @@ -308,11 +308,11 @@ void BrowserWindow::build_menus() m_change_homepage_action = GUI::Action::create( "Set Homepage URL...", g_icon_bag.go_home, [this](auto&) { - auto homepage_url = Config::read_string("Browser"sv, "Preferences"sv, "Home"sv, "about:blank"sv); + String homepage_url = String::from_deprecated_string(Config::read_string("Browser"sv, "Preferences"sv, "Home"sv, "about:blank"sv)).release_value_but_fixme_should_propagate_errors(); if (GUI::InputBox::show(this, homepage_url, "Enter URL"sv, "Change homepage URL"sv) == GUI::InputBox::ExecResult::OK) { if (URL(homepage_url).is_valid()) { Config::write_string("Browser"sv, "Preferences"sv, "Home"sv, homepage_url); - Browser::g_home_url = homepage_url; + Browser::g_home_url = homepage_url.to_deprecated_string(); } else { GUI::MessageBox::show_error(this, "The URL you have entered is not valid"sv); } @@ -439,13 +439,13 @@ void BrowserWindow::build_menus() add_user_agent("Safari iOS Mobile", "Mozilla/5.0 (iPhone; CPU iPhone OS 14_4_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1"); auto custom_user_agent = GUI::Action::create_checkable("Custom...", [this](auto& action) { - DeprecatedString user_agent; + String user_agent; 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; } - active_tab().view().debug_request("spoof-user-agent", user_agent); - action.set_status_tip(user_agent); + active_tab().view().debug_request("spoof-user-agent", user_agent.to_deprecated_string()); + action.set_status_tip(user_agent.to_deprecated_string()); }); spoof_user_agent_menu.add_action(custom_user_agent); m_user_agent_spoof_actions.add_action(custom_user_agent); @@ -530,22 +530,22 @@ 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; + String search_engine; 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; } - auto argument_count = search_engine.count("{}"sv); + auto argument_count = AK::StringUtils::count(search_engine, "{}"sv); if (argument_count != 1) { GUI::MessageBox::show(this, "Invalid format, must contain '{}' once!"sv, "Error"sv, GUI::MessageBox::Type::Error); m_disable_search_engine_action->activate(); return; } - g_search_engine = search_engine; + g_search_engine = search_engine.to_deprecated_string(); Config::write_string("Browser"sv, "Preferences"sv, "SearchEngine"sv, g_search_engine); - action.set_status_tip(search_engine); + action.set_status_tip(search_engine.to_deprecated_string()); }); search_engine_menu.add_action(custom_search_engine_action); m_search_engine_actions.add_action(custom_search_engine_action); diff --git a/Userland/Applications/BrowserSettings/ContentFilterSettingsWidget.cpp b/Userland/Applications/BrowserSettings/ContentFilterSettingsWidget.cpp index 435db8e5cf..6ef9631db6 100644 --- a/Userland/Applications/BrowserSettings/ContentFilterSettingsWidget.cpp +++ b/Userland/Applications/BrowserSettings/ContentFilterSettingsWidget.cpp @@ -116,10 +116,10 @@ ContentFilterSettingsWidget::ContentFilterSettingsWidget() m_enable_content_filtering_checkbox->on_checked = [&](auto) { set_modified(true); }; m_add_new_domain_button->on_click = [&](unsigned) { - DeprecatedString text; + String text; 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)); + m_domain_list_model->add_domain(move(text).to_deprecated_string()); set_modified(true); } }; diff --git a/Userland/Applications/CharacterMap/CharacterMapWidget.cpp b/Userland/Applications/CharacterMap/CharacterMapWidget.cpp index fa889e6b43..59c80781ee 100644 --- a/Userland/Applications/CharacterMap/CharacterMapWidget.cpp +++ b/Userland/Applications/CharacterMap/CharacterMapWidget.cpp @@ -69,7 +69,7 @@ CharacterMapWidget::CharacterMapWidget() m_next_glyph_action->set_status_tip("Seek the next visible glyph"); 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; + String input; 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()) diff --git a/Userland/Applications/FileManager/DirectoryView.cpp b/Userland/Applications/FileManager/DirectoryView.cpp index ddfba640f6..3866f3f84c 100644 --- a/Userland/Applications/FileManager/DirectoryView.cpp +++ b/Userland/Applications/FileManager/DirectoryView.cpp @@ -568,7 +568,7 @@ void DirectoryView::handle_selection_change() 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; + String value; 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); @@ -580,7 +580,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; + String value; 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; diff --git a/Userland/Applications/FileManager/main.cpp b/Userland/Applications/FileManager/main.cpp index 3724bf9d82..d878e6847f 100644 --- a/Userland/Applications/FileManager/main.cpp +++ b/Userland/Applications/FileManager/main.cpp @@ -223,7 +223,7 @@ void do_create_link(Vector<DeprecatedString> const& selected_file_paths, GUI::Wi void do_create_archive(Vector<DeprecatedString> const& selected_file_paths, GUI::Window* window) { - DeprecatedString archive_name; + String archive_name; if (GUI::InputBox::show(window, archive_name, "Enter name:"sv, "Create Archive"sv) != GUI::InputBox::ExecResult::OK) return; @@ -237,7 +237,7 @@ void do_create_archive(Vector<DeprecatedString> const& selected_file_paths, GUI: path_builder.append(".zip"sv); } else { path_builder.append(archive_name); - if (!archive_name.ends_with(".zip"sv)) + if (!AK::StringUtils::ends_with(archive_name, ".zip"sv, CaseSensitivity::CaseSensitive)) path_builder.append(".zip"sv); } auto output_path = path_builder.to_deprecated_string(); diff --git a/Userland/Applications/FontEditor/MainWidget.cpp b/Userland/Applications/FontEditor/MainWidget.cpp index 9c2ef6fe17..407c7dd294 100644 --- a/Userland/Applications/FontEditor/MainWidget.cpp +++ b/Userland/Applications/FontEditor/MainWidget.cpp @@ -242,7 +242,7 @@ ErrorOr<void> MainWidget::create_actions() m_show_system_emoji_action->set_status_tip("Show or hide system emoji"); 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; + String input; 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()) diff --git a/Userland/Applications/HexEditor/HexEditorWidget.cpp b/Userland/Applications/HexEditor/HexEditorWidget.cpp index 653a355c42..712db290a5 100644 --- a/Userland/Applications/HexEditor/HexEditorWidget.cpp +++ b/Userland/Applications/HexEditor/HexEditorWidget.cpp @@ -99,9 +99,9 @@ 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; + String 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) { - auto file_size = value.to_uint(); + auto file_size = AK::StringUtils::convert_to_uint(value); if (!file_size.has_value()) { GUI::MessageBox::show(window(), "Invalid file size entered."sv, "Error"sv, GUI::MessageBox::Type::Error); return; @@ -242,9 +242,9 @@ HexEditorWidget::HexEditorWidget() m_copy_as_c_code_action->set_enabled(false); m_fill_selection_action = GUI::Action::create("Fill &Selection...", { Mod_Ctrl, Key_B }, [&](const GUI::Action&) { - DeprecatedString value; + String value; 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 fill_byte = strtol(value.bytes_as_string_view().characters_without_null_termination(), nullptr, 16); auto result = m_editor->fill_selection(fill_byte); if (result.is_error()) GUI::MessageBox::show_error(window(), DeprecatedString::formatted("{}", result.error())); diff --git a/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.cpp b/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.cpp index 849494b414..a830081c26 100644 --- a/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.cpp +++ b/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.cpp @@ -55,7 +55,7 @@ void KeyboardMapperWidget::create_frame() tmp_button.set_enabled(keys[i].enabled); tmp_button.on_click = [this, &tmp_button]() { - DeprecatedString value; + String value; if (GUI::InputBox::show(window(), value, "New Character:"sv, "Select Character"sv) == GUI::InputBox::ExecResult::OK) { int i = m_keys.find_first_index(&tmp_button).value_or(0); VERIFY(i > 0); @@ -63,13 +63,13 @@ void KeyboardMapperWidget::create_frame() auto index = keys[i].map_index; VERIFY(index > 0); - tmp_button.set_text(String::from_deprecated_string(value).release_value_but_fixme_should_propagate_errors()); + tmp_button.set_text(value); u32* map = map_from_name(m_current_map_name); - if (value.length() == 0) + if (value.is_empty()) map[index] = '\0'; // Empty string else - map[index] = value[0]; + map[index] = value.bytes().at(0); window()->set_modified(true); } diff --git a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp index 3a11e3c32a..b5a316121e 100644 --- a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp +++ b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp @@ -373,7 +373,7 @@ PDF::PDFErrorOr<void> PDFViewerWidget::try_open_file(StringView path, NonnullOwn auto document = TRY(PDF::Document::create(m_buffer)); if (auto sh = document->security_handler(); sh && !sh->has_user_password()) { - DeprecatedString password; + String password; while (true) { auto result = GUI::InputBox::show(window(), password, "Password"sv, "Password required"sv, GUI::InputType::Password); if (result == GUI::Dialog::ExecResult::OK diff --git a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp index 897ccb2037..c8ca139905 100644 --- a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp +++ b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp @@ -100,16 +100,16 @@ SpreadsheetWidget::SpreadsheetWidget(GUI::Window& parent_window, Vector<NonnullR auto* sheet_ptr = m_tab_context_menu_sheet_view->sheet_if_available(); VERIFY(sheet_ptr); // How did we get here without a sheet? auto& sheet = *sheet_ptr; - DeprecatedString new_name; + String new_name; if (GUI::InputBox::show(window(), new_name, DeprecatedString::formatted("New name for '{}'", sheet.name()), "Rename sheet"sv) == GUI::Dialog::ExecResult::OK) { sheet.set_name(new_name); sheet.update(); - m_tab_widget->set_tab_title(static_cast<GUI::Widget&>(*m_tab_context_menu_sheet_view), String::from_deprecated_string(new_name).release_value_but_fixme_should_propagate_errors()); + m_tab_widget->set_tab_title(static_cast<GUI::Widget&>(*m_tab_context_menu_sheet_view), new_name); } }); m_tab_context_menu->add_action(*m_rename_action); m_tab_context_menu->add_action(GUI::Action::create("Add new sheet...", Gfx::Bitmap::load_from_file("/res/icons/16x16/new-tab.png"sv).release_value_but_fixme_should_propagate_errors(), [this](auto&) { - DeprecatedString name; + String name; if (GUI::InputBox::show(window(), name, "Name for new sheet"sv, "Create sheet"sv) == GUI::Dialog::ExecResult::OK) { Vector<NonnullRefPtr<Sheet>> new_sheets; new_sheets.append(m_workbook->add_sheet(name)); |