LibGUI+Userland: Port StatusBar::set_override_text() to String

This commit is contained in:
Karol Kosek 2023-06-04 11:00:35 +02:00 committed by Sam Atkins
parent 5234a30731
commit 92ff12a0d0
Notes: sideshowbarker 2024-07-17 06:51:48 +09:00
8 changed files with 17 additions and 17 deletions

View file

@ -1433,7 +1433,7 @@ void MainWidget::update_status_bar(DeprecatedString appended_text)
builder.append(" "sv);
builder.append(appended_text);
}
m_statusbar->set_override_text(builder.to_deprecated_string());
m_statusbar->set_override_text(builder.to_string().release_value_but_fixme_should_propagate_errors());
}
}

View file

@ -405,9 +405,9 @@ void Game::let_player_play_card()
auto& player = current_player();
if (&player == &m_players[0])
on_status_change("Select a card to play.");
on_status_change("Select a card to play."_string.release_value_but_fixme_should_propagate_errors());
else
on_status_change(DeprecatedString::formatted("Waiting for {} to play a card...", player));
on_status_change(String::formatted("Waiting for {} to play a card...", player).release_value_but_fixme_should_propagate_errors());
if (player.is_human) {
m_human_can_play = true;
@ -455,7 +455,7 @@ void Game::advance_game()
if (m_state == State::Play && game_ended()) {
m_state = State::GameEnded;
on_status_change("Game ended.");
on_status_change("Game ended."_string.release_value_but_fixme_should_propagate_errors());
advance_game();
return;
}
@ -699,7 +699,7 @@ void Game::card_clicked_during_play(size_t card_index, Card& card)
card.set_inverted(true);
update(card.rect());
m_inverted_card = card;
on_status_change(DeprecatedString::formatted("You can't play this card: {}", explanation));
on_status_change(String::formatted("You can't play this card: {}", explanation).release_value_but_fixme_should_propagate_errors());
continue_game_after_delay();
return;
}

View file

@ -28,7 +28,7 @@ public:
void setup(DeprecatedString player_name, int hand_number = 0);
Function<void(DeprecatedString const&)> on_status_change;
Function<void(String const&)> on_status_change;
private:
Game();

View file

@ -61,7 +61,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
DeprecatedString player_name = Config::read_string("Hearts"sv, ""sv, "player_name"sv, "Gunnar"sv);
game.on_status_change = [&](const AK::StringView& status) {
game.on_status_change = [&](String const& status) {
statusbar.set_override_text(status);
};

View file

@ -315,12 +315,15 @@ void Action::set_tooltip(DeprecatedString tooltip)
});
}
DeprecatedString Action::status_tip() const
Optional<String> Action::status_tip() const
{
if (!m_status_tip.is_empty())
return m_status_tip.to_deprecated_string();
return m_status_tip;
return Gfx::parse_ampersand_string(m_text);
auto maybe_parsed_action_text = String::from_deprecated_string(Gfx::parse_ampersand_string(m_text));
if (maybe_parsed_action_text.is_error())
return {};
return maybe_parsed_action_text.release_value();
}
}

View file

@ -89,7 +89,7 @@ public:
DeprecatedString tooltip() const { return m_tooltip.value_or(m_text); }
void set_tooltip(DeprecatedString);
DeprecatedString status_tip() const;
Optional<String> status_tip() const;
void set_status_tip(String status_tip) { m_status_tip = move(status_tip); }
Shortcut const& shortcut() const { return m_shortcut; }

View file

@ -116,12 +116,9 @@ void Statusbar::set_text(size_t index, String text)
update_segment(index);
}
void Statusbar::set_override_text(DeprecatedString override_text)
void Statusbar::set_override_text(Optional<String> override_text)
{
if (override_text.is_null())
m_segments[0]->m_override_text = {};
else
m_segments[0]->m_override_text = String::from_deprecated_string(override_text).release_value_but_fixme_should_propagate_errors();
m_segments[0]->m_override_text = move(override_text);
update_segment(0);
}

View file

@ -22,7 +22,7 @@ public:
String text(size_t index = 0) const;
void set_text(String);
void set_text(size_t index, String);
void set_override_text(DeprecatedString);
void set_override_text(Optional<String>);
class Segment final : public Button {
C_OBJECT(Segment)