mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
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:
parent
2029750519
commit
4b169cf25f
13 changed files with 21 additions and 48 deletions
|
@ -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&) {
|
||||
|
|
|
@ -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&) {
|
||||
|
|
|
@ -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&) {
|
||||
|
|
|
@ -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&) {
|
||||
|
|
|
@ -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&) {
|
||||
|
|
|
@ -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&) {
|
||||
|
|
|
@ -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&) {
|
||||
|
|
|
@ -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&) {
|
||||
|
|
|
@ -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&) {
|
||||
|
|
|
@ -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&) {
|
||||
|
|
|
@ -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&) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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; }
|
||||
|
|
Loading…
Add table
Reference in a new issue