mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:07:44 +00:00
LibGUI: Show action shortcut in ToolBarButton tooltip
This commit is contained in:
parent
50b76e4cc7
commit
8e1bda0e9d
1 changed files with 14 additions and 1 deletions
|
@ -24,6 +24,8 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/String.h>
|
||||||
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibGUI/Action.h>
|
#include <LibGUI/Action.h>
|
||||||
#include <LibGUI/ActionGroup.h>
|
#include <LibGUI/ActionGroup.h>
|
||||||
#include <LibGUI/BoxLayout.h>
|
#include <LibGUI/BoxLayout.h>
|
||||||
|
@ -65,7 +67,7 @@ private:
|
||||||
if (action.group() && action.group()->is_exclusive())
|
if (action.group() && action.group()->is_exclusive())
|
||||||
set_exclusive(true);
|
set_exclusive(true);
|
||||||
set_action(action);
|
set_action(action);
|
||||||
set_tooltip(action.text());
|
set_tooltip(tooltip(action));
|
||||||
set_focus_policy(FocusPolicy::TabFocus);
|
set_focus_policy(FocusPolicy::TabFocus);
|
||||||
if (action.icon())
|
if (action.icon())
|
||||||
set_icon(action.icon());
|
set_icon(action.icon());
|
||||||
|
@ -74,6 +76,17 @@ private:
|
||||||
set_button_style(Gfx::ButtonStyle::CoolBar);
|
set_button_style(Gfx::ButtonStyle::CoolBar);
|
||||||
set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||||
}
|
}
|
||||||
|
String tooltip(const Action& action) const
|
||||||
|
{
|
||||||
|
StringBuilder builder;
|
||||||
|
builder.append(action.text());
|
||||||
|
if (action.shortcut().is_valid()) {
|
||||||
|
builder.append(" (");
|
||||||
|
builder.append(action.shortcut().to_string());
|
||||||
|
builder.append(")");
|
||||||
|
}
|
||||||
|
return builder.to_string();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void ToolBar::add_action(Action& action)
|
void ToolBar::add_action(Action& action)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue