summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibGUI/Action.cpp3
-rw-r--r--Userland/Libraries/LibGUI/Button.cpp19
-rw-r--r--Userland/Libraries/LibGUI/Button.h1
-rw-r--r--Userland/Libraries/LibGUI/Toolbar.cpp12
4 files changed, 23 insertions, 12 deletions
diff --git a/Userland/Libraries/LibGUI/Action.cpp b/Userland/Libraries/LibGUI/Action.cpp
index 6f99e40711..6dbd04616d 100644
--- a/Userland/Libraries/LibGUI/Action.cpp
+++ b/Userland/Libraries/LibGUI/Action.cpp
@@ -241,6 +241,9 @@ void Action::set_text(String text)
if (m_text == text)
return;
m_text = move(text);
+ for_each_toolbar_button([&](auto& button) {
+ button.set_text_from_action();
+ });
for_each_menu_item([&](auto& menu_item) {
menu_item.update_from_action({});
});
diff --git a/Userland/Libraries/LibGUI/Button.cpp b/Userland/Libraries/LibGUI/Button.cpp
index 20a242569f..7559f15235 100644
--- a/Userland/Libraries/LibGUI/Button.cpp
+++ b/Userland/Libraries/LibGUI/Button.cpp
@@ -169,6 +169,25 @@ void Button::set_action(Action& action)
set_checkable(action.is_checkable());
if (action.is_checkable())
set_checked(action.is_checked());
+ set_text_from_action();
+}
+
+static String create_tooltip_for_action(Action const& action)
+{
+ StringBuilder builder;
+ builder.append(action.text());
+ if (action.shortcut().is_valid()) {
+ builder.append(" ("sv);
+ builder.append(action.shortcut().to_string());
+ builder.append(')');
+ }
+ return builder.to_string();
+}
+
+void Button::set_text_from_action()
+{
+ set_text(action()->text());
+ set_tooltip(create_tooltip_for_action(*action()));
}
void Button::set_icon(RefPtr<Gfx::Bitmap> icon)
diff --git a/Userland/Libraries/LibGUI/Button.h b/Userland/Libraries/LibGUI/Button.h
index efdf1b12d6..1a66e51390 100644
--- a/Userland/Libraries/LibGUI/Button.h
+++ b/Userland/Libraries/LibGUI/Button.h
@@ -50,6 +50,7 @@ public:
Action* action() { return m_action; }
Action const* action() const { return m_action; }
void set_action(Action&);
+ void set_text_from_action();
virtual bool is_uncheckable() const override;
diff --git a/Userland/Libraries/LibGUI/Toolbar.cpp b/Userland/Libraries/LibGUI/Toolbar.cpp
index 62b16ee581..d65a58fa94 100644
--- a/Userland/Libraries/LibGUI/Toolbar.cpp
+++ b/Userland/Libraries/LibGUI/Toolbar.cpp
@@ -51,7 +51,6 @@ private:
if (action.group() && action.group()->is_exclusive())
set_exclusive(true);
set_action(action);
- set_tooltip(tooltip(action));
set_focus_policy(FocusPolicy::NoFocus);
if (action.icon())
set_icon(action.icon());
@@ -59,17 +58,6 @@ private:
set_text(action.text());
set_button_style(Gfx::ButtonStyle::Coolbar);
}
- String tooltip(Action const& action) const
- {
- StringBuilder builder;
- builder.append(action.text());
- if (action.shortcut().is_valid()) {
- builder.append(" ("sv);
- builder.append(action.shortcut().to_string());
- builder.append(')');
- }
- return builder.to_string();
- }
virtual void enter_event(Core::Event& event) override
{