From 62cbfc68b9cdfee62a817b69912bc6f191b942ef Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 19 Nov 2022 09:08:09 -0500 Subject: [PATCH] Revert "LibGUI: Update buttons' text/tooltips in Action::set_text" This reverts commit e20756f9f735187f481420947329dfdb9a3418ac. Some buttons, e.g. GUI::ToolbarButton, set text to be used only as a tooltip instead of text on the button itself. This commit forced those buttons to have text on them when their action became set. For most toolbars, this was an invisible side effect; the button icons covered the whole button rect. But the toolbar for EmojiInputDialog has slightly smaller icons, causing an ellipsis to be displayed next to the icon. --- Userland/Libraries/LibGUI/Action.cpp | 3 --- Userland/Libraries/LibGUI/Button.cpp | 19 ------------------- Userland/Libraries/LibGUI/Button.h | 1 - Userland/Libraries/LibGUI/Toolbar.cpp | 12 ++++++++++++ 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/Userland/Libraries/LibGUI/Action.cpp b/Userland/Libraries/LibGUI/Action.cpp index 4b55731e25..76198bf8e0 100644 --- a/Userland/Libraries/LibGUI/Action.cpp +++ b/Userland/Libraries/LibGUI/Action.cpp @@ -275,9 +275,6 @@ 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 7559f15235..20a242569f 100644 --- a/Userland/Libraries/LibGUI/Button.cpp +++ b/Userland/Libraries/LibGUI/Button.cpp @@ -169,25 +169,6 @@ 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 icon) diff --git a/Userland/Libraries/LibGUI/Button.h b/Userland/Libraries/LibGUI/Button.h index 1a66e51390..efdf1b12d6 100644 --- a/Userland/Libraries/LibGUI/Button.h +++ b/Userland/Libraries/LibGUI/Button.h @@ -50,7 +50,6 @@ 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 d65a58fa94..62b16ee581 100644 --- a/Userland/Libraries/LibGUI/Toolbar.cpp +++ b/Userland/Libraries/LibGUI/Toolbar.cpp @@ -51,6 +51,7 @@ 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()); @@ -58,6 +59,17 @@ 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 {