summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-03-04 12:50:28 -0500
committerAndreas Kling <kling@serenityos.org>2023-03-05 20:21:57 +0100
commit153218ed76b2e02e36147fe575185d48f5990489 (patch)
tree44fee267aa2cf3845c8396c7c30ac66e5fc2d5b9 /Userland
parentf8a03650020215883d4287cd400ac44fb96624ca (diff)
downloadserenity-153218ed76b2e02e36147fe575185d48f5990489.zip
LibGUI: Allow overriding toolbar button tooltips
The EmojiInputDialog, for example, will want its toolbar buttons to have a tooltip which differs from its text. If no tooltip override has been provided, we fall back to the button text still.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGUI/Action.cpp13
-rw-r--r--Userland/Libraries/LibGUI/Action.h4
-rw-r--r--Userland/Libraries/LibGUI/Toolbar.cpp2
3 files changed, 18 insertions, 1 deletions
diff --git a/Userland/Libraries/LibGUI/Action.cpp b/Userland/Libraries/LibGUI/Action.cpp
index 7c6863b519..0ec136b4b1 100644
--- a/Userland/Libraries/LibGUI/Action.cpp
+++ b/Userland/Libraries/LibGUI/Action.cpp
@@ -296,4 +296,17 @@ void Action::set_text(DeprecatedString text)
});
}
+void Action::set_tooltip(DeprecatedString tooltip)
+{
+ if (m_tooltip == tooltip)
+ return;
+ m_tooltip = move(tooltip);
+ for_each_toolbar_button([&](auto& button) {
+ button.set_tooltip(*m_tooltip);
+ });
+ for_each_menu_item([&](auto& menu_item) {
+ menu_item.update_from_action({});
+ });
+}
+
}
diff --git a/Userland/Libraries/LibGUI/Action.h b/Userland/Libraries/LibGUI/Action.h
index 8225977b7c..f876f0371f 100644
--- a/Userland/Libraries/LibGUI/Action.h
+++ b/Userland/Libraries/LibGUI/Action.h
@@ -85,6 +85,9 @@ public:
DeprecatedString text() const { return m_text; }
void set_text(DeprecatedString);
+ DeprecatedString tooltip() const { return m_tooltip.value_or(m_text); }
+ void set_tooltip(DeprecatedString);
+
DeprecatedString const& status_tip() const { return m_status_tip; }
void set_status_tip(DeprecatedString status_tip) { m_status_tip = move(status_tip); }
@@ -144,6 +147,7 @@ private:
void for_each_menu_item(Callback);
DeprecatedString m_text;
+ Optional<DeprecatedString> m_tooltip;
DeprecatedString m_status_tip;
RefPtr<Gfx::Bitmap const> m_icon;
Shortcut m_shortcut;
diff --git a/Userland/Libraries/LibGUI/Toolbar.cpp b/Userland/Libraries/LibGUI/Toolbar.cpp
index bf1ef4f83c..50c2cd9aed 100644
--- a/Userland/Libraries/LibGUI/Toolbar.cpp
+++ b/Userland/Libraries/LibGUI/Toolbar.cpp
@@ -71,7 +71,7 @@ private:
DeprecatedString tooltip(Action const& action) const
{
StringBuilder builder;
- builder.append(action.text());
+ builder.append(action.tooltip());
if (action.shortcut().is_valid()) {
builder.append(" ("sv);
builder.append(action.shortcut().to_deprecated_string());