From a3ddba4191a685c38d972b9fa026e13b7807382d Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Sun, 10 Sep 2023 16:44:32 +0200 Subject: [PATCH] Userland: Port GUI::Application::show_tooltip() to String This most importantly gets rid of a chain of "String to DeprecatedString to String" transformations when setting a tooltip from GUI::Widget's set_tooltip function. --- Userland/Applications/Maps/MapWidget.cpp | 2 +- Userland/Applications/PixelPaint/Tools/GuideTool.cpp | 4 ++-- Userland/DevTools/Profiler/TimelineTrack.cpp | 2 +- Userland/Libraries/LibGUI/Application.cpp | 8 ++++---- Userland/Libraries/LibGUI/Application.h | 4 ++-- Userland/Libraries/LibGUI/Widget.cpp | 2 +- Userland/Libraries/LibWebView/OutOfProcessWebView.cpp | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Userland/Applications/Maps/MapWidget.cpp b/Userland/Applications/Maps/MapWidget.cpp index d5cdd75141..462b63fd0a 100644 --- a/Userland/Applications/Maps/MapWidget.cpp +++ b/Userland/Applications/Maps/MapWidget.cpp @@ -187,7 +187,7 @@ void MapWidget::mousemove_event(GUI::MouseEvent& event) marker_image->height() }; if (marker_rect.contains(event.x(), event.y())) { - GUI::Application::the()->show_tooltip(marker.tooltip.value().to_deprecated_string(), this); + GUI::Application::the()->show_tooltip(marker.tooltip.value(), this); return; } } diff --git a/Userland/Applications/PixelPaint/Tools/GuideTool.cpp b/Userland/Applications/PixelPaint/Tools/GuideTool.cpp index 54a904887f..3c932a471e 100644 --- a/Userland/Applications/PixelPaint/Tools/GuideTool.cpp +++ b/Userland/Applications/PixelPaint/Tools/GuideTool.cpp @@ -74,7 +74,7 @@ void GuideTool::on_mousedown(Layer*, MouseEvent& event) if (m_selected_guide) { m_guide_origin = m_selected_guide->offset(); - GUI::Application::the()->show_tooltip_immediately(DeprecatedString::formatted("{}", m_guide_origin), GUI::Application::the()->tooltip_source_widget()); + GUI::Application::the()->show_tooltip_immediately(MUST(String::number(m_guide_origin)), GUI::Application::the()->tooltip_source_widget()); } } @@ -120,7 +120,7 @@ void GuideTool::on_mousemove(Layer*, MouseEvent& event) m_selected_guide->set_offset(new_offset); - GUI::Application::the()->show_tooltip_immediately(DeprecatedString::formatted("{}", new_offset), GUI::Application::the()->tooltip_source_widget()); + GUI::Application::the()->show_tooltip_immediately(MUST(String::number(new_offset)), GUI::Application::the()->tooltip_source_widget()); editor()->update(); } diff --git a/Userland/DevTools/Profiler/TimelineTrack.cpp b/Userland/DevTools/Profiler/TimelineTrack.cpp index 600f1817d6..3588b8c880 100644 --- a/Userland/DevTools/Profiler/TimelineTrack.cpp +++ b/Userland/DevTools/Profiler/TimelineTrack.cpp @@ -130,7 +130,7 @@ void TimelineTrack::mousemove_event(GUI::MouseEvent& event) Gfx::IntRect hoverable_rect { x - hoverable_padding, frame_thickness(), hoverable_padding * 2, height() - frame_thickness() * 2 }; if (hoverable_rect.contains_horizontally(event.x())) { auto const& data = signpost.data.template get(); - GUI::Application::the()->show_tooltip_immediately(DeprecatedString::formatted("{}, {}", data.string, data.arg), this); + GUI::Application::the()->show_tooltip_immediately(MUST(String::formatted("{}, {}", data.string, data.arg)), this); hovering_a_signpost = true; return IterationDecision::Break; } diff --git a/Userland/Libraries/LibGUI/Application.cpp b/Userland/Libraries/LibGUI/Application.cpp index 2c2979bcca..1e061e43af 100644 --- a/Userland/Libraries/LibGUI/Application.cpp +++ b/Userland/Libraries/LibGUI/Application.cpp @@ -25,9 +25,9 @@ class Application::TooltipWindow final : public Window { C_OBJECT(TooltipWindow); public: - void set_tooltip(DeprecatedString const& tooltip) + void set_tooltip(String tooltip) { - m_label->set_text(String::from_deprecated_string(tooltip).release_value_but_fixme_should_propagate_errors()); + m_label->set_text(move(tooltip)); int tooltip_width = m_label->effective_min_size().width().as_int() + 10; int line_count = m_label->text().count("\n"sv); int font_size = m_label->font().pixel_size_rounded_up(); @@ -152,7 +152,7 @@ Action* Application::action_for_shortcut(Shortcut const& shortcut) const return (*it).value; } -void Application::show_tooltip(DeprecatedString tooltip, Widget const* tooltip_source_widget) +void Application::show_tooltip(String tooltip, Widget const* tooltip_source_widget) { if (!Desktop::the().system_effects().tooltips()) return; @@ -173,7 +173,7 @@ void Application::show_tooltip(DeprecatedString tooltip, Widget const* tooltip_s } } -void Application::show_tooltip_immediately(DeprecatedString tooltip, Widget const* tooltip_source_widget) +void Application::show_tooltip_immediately(String tooltip, Widget const* tooltip_source_widget) { if (!Desktop::the().system_effects().tooltips()) return; diff --git a/Userland/Libraries/LibGUI/Application.h b/Userland/Libraries/LibGUI/Application.h index dd3ca40451..ba27d165ec 100644 --- a/Userland/Libraries/LibGUI/Application.h +++ b/Userland/Libraries/LibGUI/Application.h @@ -41,8 +41,8 @@ public: void register_global_shortcut_action(Badge, Action&); void unregister_global_shortcut_action(Badge, Action&); - void show_tooltip(DeprecatedString, Widget const* tooltip_source_widget); - void show_tooltip_immediately(DeprecatedString, Widget const* tooltip_source_widget); + void show_tooltip(String, Widget const* tooltip_source_widget); + void show_tooltip_immediately(String, Widget const* tooltip_source_widget); void hide_tooltip(); Widget const* tooltip_source_widget() { return m_tooltip_source_widget; } diff --git a/Userland/Libraries/LibGUI/Widget.cpp b/Userland/Libraries/LibGUI/Widget.cpp index 06044c490b..77bbf50157 100644 --- a/Userland/Libraries/LibGUI/Widget.cpp +++ b/Userland/Libraries/LibGUI/Widget.cpp @@ -1122,7 +1122,7 @@ void Widget::set_tooltip(String tooltip) void Widget::show_or_hide_tooltip() { if (has_tooltip()) - Application::the()->show_tooltip(m_tooltip.to_deprecated_string(), this); + Application::the()->show_tooltip(m_tooltip, this); else Application::the()->hide_tooltip(); } diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp index 0f3edf5f36..2e1132b86c 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp @@ -65,7 +65,7 @@ OutOfProcessWebView::OutOfProcessWebView() }; on_enter_tooltip_area = [](auto, auto tooltip) { - GUI::Application::the()->show_tooltip(tooltip, nullptr); + GUI::Application::the()->show_tooltip(MUST(String::from_deprecated_string(tooltip)), nullptr); }; on_leave_tooltip_area = []() {