LibGUI+Userland: Use action text as a fallback in Action::status_tip()

Many applications already do this in their code. This change will simply
move the logic to a single function to stop repeating ourselves!
This commit is contained in:
Karol Kosek 2023-06-04 12:10:25 +02:00 committed by Sam Atkins
parent 2029750519
commit 4b169cf25f
Notes: sideshowbarker 2024-07-17 00:59:43 +09:00
13 changed files with 21 additions and 48 deletions

View file

@ -649,10 +649,7 @@ ErrorOr<int> run_in_windowed_mode(DeprecatedString const& initial_location, Depr
auto& statusbar = *widget->find_descendant_of_type_named<GUI::Statusbar>("statusbar");
GUI::Application::the()->on_action_enter = [&statusbar](GUI::Action& action) {
auto text = action.status_tip();
if (text.is_empty())
text = Gfx::parse_ampersand_string(action.text());
statusbar.set_override_text(move(text));
statusbar.set_override_text(action.status_tip());
};
GUI::Application::the()->on_action_leave = [&statusbar](GUI::Action&) {

View file

@ -647,10 +647,7 @@ ErrorOr<void> MainWidget::create_widgets()
};
GUI::Application::the()->on_action_enter = [this](GUI::Action& action) {
auto text = action.status_tip();
if (text.is_empty())
text = Gfx::parse_ampersand_string(action.text());
m_statusbar->set_override_text(move(text));
m_statusbar->set_override_text(action.status_tip());
};
GUI::Application::the()->on_action_leave = [this](GUI::Action&) {

View file

@ -16,7 +16,6 @@
#include <LibGUI/MessageBox.h>
#include <LibGUI/Statusbar.h>
#include <LibGUI/Window.h>
#include <LibGfx/Painter.h>
#include <LibMain/Main.h>
ErrorOr<int> serenity_main(Main::Arguments arguments)
@ -61,10 +60,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto& statusbar = *main_widget->find_descendant_of_type_named<GUI::Statusbar>("statusbar");
app->on_action_enter = [&statusbar](GUI::Action& action) {
auto text = action.status_tip();
if (text.is_empty())
text = Gfx::parse_ampersand_string(action.text());
statusbar.set_override_text(move(text));
statusbar.set_override_text(action.status_tip());
};
app->on_action_leave = [&statusbar](GUI::Action&) {

View file

@ -37,7 +37,6 @@
#include <LibGUI/ToolbarContainer.h>
#include <LibGUI/VimEditingEngine.h>
#include <LibGfx/Font/Font.h>
#include <LibGfx/Painter.h>
#include <LibJS/SyntaxHighlighter.h>
#include <LibMarkdown/Document.h>
#include <LibMarkdown/SyntaxHighlighter.h>
@ -236,10 +235,7 @@ MainWidget::MainWidget()
m_statusbar->segment(2).set_menu(m_line_column_statusbar_menu);
GUI::Application::the()->on_action_enter = [this](GUI::Action& action) {
auto text = action.status_tip();
if (text.is_empty())
text = Gfx::parse_ampersand_string(action.text());
m_statusbar->set_override_text(move(text));
m_statusbar->set_override_text(action.status_tip());
};
GUI::Application::the()->on_action_leave = [this](GUI::Action&) {

View file

@ -156,10 +156,7 @@ ErrorOr<NonnullRefPtr<HackStudioWidget>> HackStudioWidget::create(DeprecatedStri
widget->update_statusbar();
GUI::Application::the()->on_action_enter = [widget](GUI::Action& action) {
auto text = action.status_tip();
if (text.is_empty())
text = Gfx::parse_ampersand_string(action.text());
widget->m_statusbar->set_override_text(move(text));
widget->m_statusbar->set_override_text(action.status_tip());
};
GUI::Application::the()->on_action_leave = [widget](GUI::Action&) {

View file

@ -250,10 +250,7 @@ ErrorOr<void> MainWidget::setup()
m_statusbar->segment(2).set_fixed_width(font().width("Ln 0,000 Col 000"sv) + font().max_glyph_width());
GUI::Application::the()->on_action_enter = [this](GUI::Action& action) {
auto text = action.status_tip();
if (text.is_empty())
text = Gfx::parse_ampersand_string(action.text());
m_statusbar->set_override_text(move(text));
m_statusbar->set_override_text(action.status_tip());
};
GUI::Application::the()->on_action_leave = [this](GUI::Action&) {

View file

@ -22,7 +22,6 @@
#include <LibGUI/MessageBox.h>
#include <LibGUI/Statusbar.h>
#include <LibGUI/Window.h>
#include <LibGfx/Painter.h>
#include <LibMain/Main.h>
#include <stdio.h>
#include <time.h>
@ -76,10 +75,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto statusbar = main_widget->find_descendant_of_type_named<GUI::Statusbar>("statusbar");
app->on_action_enter = [&](GUI::Action& action) {
auto text = action.status_tip();
if (text.is_empty())
text = Gfx::parse_ampersand_string(action.text());
statusbar->set_override_text(move(text));
statusbar->set_override_text(action.status_tip());
};
app->on_action_leave = [&](GUI::Action&) {

View file

@ -93,10 +93,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto statusbar = main_widget->find_descendant_of_type_named<GUI::Statusbar>("statusbar");
app->on_action_enter = [&](GUI::Action& action) {
auto text = action.status_tip();
if (text.is_empty())
text = Gfx::parse_ampersand_string(action.text());
statusbar->set_override_text(move(text));
statusbar->set_override_text(action.status_tip());
};
app->on_action_leave = [&](GUI::Action&) {

View file

@ -66,10 +66,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
};
app->on_action_enter = [&](GUI::Action& action) {
auto text = action.status_tip();
if (text.is_empty())
text = Gfx::parse_ampersand_string(action.text());
statusbar.set_override_text(move(text));
statusbar.set_override_text(action.status_tip());
};
app->on_action_leave = [&](GUI::Action&) {

View file

@ -95,10 +95,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
statusbar.set_text(2, TRY("Time: 00:00:00"_string));
app->on_action_enter = [&](GUI::Action& action) {
auto text = action.status_tip();
if (text.is_empty())
text = Gfx::parse_ampersand_string(action.text());
statusbar.set_override_text(move(text));
statusbar.set_override_text(action.status_tip());
};
app->on_action_leave = [&](GUI::Action&) {

View file

@ -142,10 +142,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
statusbar.set_text(2, TRY("Time: 00:00:00"_string));
app->on_action_enter = [&](GUI::Action& action) {
auto text = action.status_tip();
if (text.is_empty())
text = Gfx::parse_ampersand_string(action.text());
statusbar.set_override_text(move(text));
statusbar.set_override_text(action.status_tip());
};
app->on_action_leave = [&](GUI::Action&) {

View file

@ -11,6 +11,7 @@
#include <LibGUI/Button.h>
#include <LibGUI/MenuItem.h>
#include <LibGUI/Window.h>
#include <LibGfx/Painter.h>
namespace GUI {
@ -314,4 +315,12 @@ void Action::set_tooltip(DeprecatedString tooltip)
});
}
DeprecatedString Action::status_tip() const
{
if (!m_status_tip.is_empty())
return m_status_tip;
return Gfx::parse_ampersand_string(m_text);
}
}

View file

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