mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 10:27:34 +00:00
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.
This commit is contained in:
parent
f8a0365002
commit
153218ed76
3 changed files with 18 additions and 1 deletions
|
@ -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({});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,6 +85,9 @@ public:
|
||||||
DeprecatedString text() const { return m_text; }
|
DeprecatedString text() const { return m_text; }
|
||||||
void set_text(DeprecatedString);
|
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; }
|
DeprecatedString const& status_tip() const { return m_status_tip; }
|
||||||
void set_status_tip(DeprecatedString status_tip) { m_status_tip = move(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);
|
void for_each_menu_item(Callback);
|
||||||
|
|
||||||
DeprecatedString m_text;
|
DeprecatedString m_text;
|
||||||
|
Optional<DeprecatedString> m_tooltip;
|
||||||
DeprecatedString m_status_tip;
|
DeprecatedString m_status_tip;
|
||||||
RefPtr<Gfx::Bitmap const> m_icon;
|
RefPtr<Gfx::Bitmap const> m_icon;
|
||||||
Shortcut m_shortcut;
|
Shortcut m_shortcut;
|
||||||
|
|
|
@ -71,7 +71,7 @@ private:
|
||||||
DeprecatedString tooltip(Action const& action) const
|
DeprecatedString tooltip(Action const& action) const
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.append(action.text());
|
builder.append(action.tooltip());
|
||||||
if (action.shortcut().is_valid()) {
|
if (action.shortcut().is_valid()) {
|
||||||
builder.append(" ("sv);
|
builder.append(" ("sv);
|
||||||
builder.append(action.shortcut().to_deprecated_string());
|
builder.append(action.shortcut().to_deprecated_string());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue