Преглед на файлове

LibGUI: Store text using the new String class in the AbstractButton

This change also adds non-deprecated text() and set_text() functions and
helper constructors for Button, CheckBox, and RadioButton to call the
strings directly.

The whole codebase at this point is still using the deprecated string
functions, which the class will quietly convert to a new String.
Karol Kosek преди 2 години
родител
ревизия
fca29eae09

+ 8 - 3
Userland/Libraries/LibGUI/AbstractButton.cpp

@@ -15,9 +15,9 @@
 
 namespace GUI {
 
-AbstractButton::AbstractButton(DeprecatedString text)
+AbstractButton::AbstractButton(String text)
 {
-    set_text_deprecated(move(text));
+    set_text(move(text));
 
     set_focus_policy(GUI::FocusPolicy::StrongFocus);
     set_background_role(Gfx::ColorRole::Button);
@@ -34,7 +34,12 @@ AbstractButton::AbstractButton(DeprecatedString text)
     REGISTER_BOOL_PROPERTY("exclusive", is_exclusive, set_exclusive);
 }
 
-void AbstractButton::set_text_deprecated(DeprecatedString text)
+void AbstractButton::set_text_deprecated(DeprecatedString deprecated_text)
+{
+    set_text(String::from_deprecated_string(deprecated_text).release_value_but_fixme_should_propagate_errors());
+}
+
+void AbstractButton::set_text(String text)
 {
     if (m_text == text)
         return;

+ 6 - 3
Userland/Libraries/LibGUI/AbstractButton.h

@@ -7,6 +7,7 @@
 
 #pragma once
 
+#include <AK/String.h>
 #include <LibGUI/Widget.h>
 #include <LibGfx/TextWrapping.h>
 
@@ -21,7 +22,9 @@ public:
     Function<void(bool)> on_checked;
 
     virtual void set_text_deprecated(DeprecatedString);
-    DeprecatedString const& text_deprecated() const { return m_text; }
+    DeprecatedString text_deprecated() const { return m_text.to_deprecated_string(); }
+    virtual void set_text(String);
+    String const& text() const { return m_text; }
 
     bool is_exclusive() const { return m_exclusive; }
     void set_exclusive(bool b) { m_exclusive = b; }
@@ -47,7 +50,7 @@ public:
     void set_auto_repeat_interval(int interval) { m_auto_repeat_interval = interval; }
 
 protected:
-    explicit AbstractButton(DeprecatedString = {});
+    explicit AbstractButton(String = {});
 
     virtual void mousedown_event(MouseEvent&) override;
     virtual void mousemove_event(MouseEvent&) override;
@@ -62,7 +65,7 @@ protected:
     void paint_text(Painter&, Gfx::IntRect const&, Gfx::Font const&, Gfx::TextAlignment, Gfx::TextWrapping = Gfx::TextWrapping::DontWrap);
 
 private:
-    DeprecatedString m_text;
+    String m_text;
     bool m_checked { false };
     bool m_checkable { false };
     bool m_hovered { false };

+ 6 - 1
Userland/Libraries/LibGUI/Button.cpp

@@ -20,7 +20,12 @@ REGISTER_WIDGET(GUI, DialogButton)
 
 namespace GUI {
 
-Button::Button(DeprecatedString text)
+Button::Button(DeprecatedString deprecated_text)
+    : Button(String::from_deprecated_string(deprecated_text).release_value_but_fixme_should_propagate_errors())
+{
+}
+
+Button::Button(String text)
     : AbstractButton(move(text))
 {
     set_min_size({ 40, 22 });

+ 7 - 2
Userland/Libraries/LibGUI/Button.h

@@ -68,7 +68,8 @@ public:
     virtual Optional<UISize> calculated_min_size() const override;
 
 protected:
-    explicit Button(DeprecatedString text = {});
+    explicit Button(DeprecatedString text);
+    explicit Button(String text = {});
     virtual void mousedown_event(MouseEvent&) override;
     virtual void mousemove_event(MouseEvent&) override;
     virtual void paint_event(PaintEvent&) override;
@@ -91,7 +92,11 @@ class DialogButton final : public Button {
 
 public:
     virtual ~DialogButton() override {};
-    explicit DialogButton(DeprecatedString text = {})
+    explicit DialogButton(DeprecatedString deprecated_text)
+        : DialogButton(String::from_deprecated_string(deprecated_text).release_value_but_fixme_should_propagate_errors())
+    {
+    }
+    explicit DialogButton(String text = {})
         : Button(move(text))
     {
         set_fixed_width(80);

+ 6 - 1
Userland/Libraries/LibGUI/CheckBox.cpp

@@ -20,7 +20,12 @@ static constexpr int s_box_width = 13;
 static constexpr int s_box_height = 13;
 static constexpr int s_horizontal_padding = 6;
 
-CheckBox::CheckBox(DeprecatedString text)
+CheckBox::CheckBox(DeprecatedString deprecated_text)
+    : CheckBox(String::from_deprecated_string(deprecated_text).release_value_but_fixme_should_propagate_errors())
+{
+}
+
+CheckBox::CheckBox(String text)
     : AbstractButton(move(text))
 {
     REGISTER_BOOL_PROPERTY("autosize", is_autosize, set_autosize);

+ 2 - 1
Userland/Libraries/LibGUI/CheckBox.h

@@ -30,7 +30,8 @@ public:
     void set_checkbox_position(CheckBoxPosition value) { m_checkbox_position = value; }
 
 protected:
-    explicit CheckBox(DeprecatedString = {});
+    explicit CheckBox(DeprecatedString);
+    explicit CheckBox(String = {});
 
 private:
     void size_to_fit();

+ 5 - 0
Userland/Libraries/LibGUI/RadioButton.cpp

@@ -17,6 +17,11 @@ REGISTER_WIDGET(GUI, RadioButton)
 namespace GUI {
 
 RadioButton::RadioButton(DeprecatedString text)
+    : RadioButton(String::from_deprecated_string(text).release_value_but_fixme_should_propagate_errors())
+{
+}
+
+RadioButton::RadioButton(String text)
     : AbstractButton(move(text))
 {
     set_exclusive(true);

+ 2 - 1
Userland/Libraries/LibGUI/RadioButton.h

@@ -22,7 +22,8 @@ public:
     virtual Optional<UISize> calculated_min_size() const override;
 
 protected:
-    explicit RadioButton(DeprecatedString text = {});
+    explicit RadioButton(DeprecatedString text);
+    explicit RadioButton(String text = {});
     virtual void paint_event(PaintEvent&) override;
 
 private: