mirror of
https://github.com/RGBCube/serenity
synced 2025-07-14 17:57:34 +00:00
LibGUI+WindowServer: Add app-global keyboard shortcuts.
This patch adds a GShortcut class. Each GAction can have a GShortcut which will cause the event loop to listen for that key combination app-globally and activate the event in case it's pressed. The shortcut will also be displayed when the action is added to a menu. Use this to hook up Alt+Up with the "open parent directory" action in the FileManager app. :^)
This commit is contained in:
parent
5c0fca0a95
commit
596a5ce5a4
17 changed files with 263 additions and 17 deletions
|
@ -29,8 +29,13 @@ int WSMenu::width() const
|
|||
{
|
||||
int longest = 0;
|
||||
for (auto& item : m_items) {
|
||||
if (item->type() == WSMenuItem::Text)
|
||||
longest = max(longest, font().width(item->text()));
|
||||
if (item->type() == WSMenuItem::Text) {
|
||||
int item_width = font().width(item->text());
|
||||
if (!item->shortcut_text().is_empty())
|
||||
item_width += padding_between_text_and_shortcut() + font().width(item->shortcut_text());
|
||||
|
||||
longest = max(longest, item_width);
|
||||
}
|
||||
}
|
||||
|
||||
return max(longest, rect_in_menubar().width()) + horizontal_padding();
|
||||
|
@ -91,6 +96,9 @@ void WSMenu::draw()
|
|||
text_color = Color::White;
|
||||
}
|
||||
painter.draw_text(item->rect().translated(left_padding(), 0), item->text(), TextAlignment::CenterLeft, text_color);
|
||||
if (!item->shortcut_text().is_empty()) {
|
||||
painter.draw_text(item->rect().translated(-right_padding(), 0), item->shortcut_text(), TextAlignment::CenterRight, text_color);
|
||||
}
|
||||
} else if (item->type() == WSMenuItem::Separator) {
|
||||
Point p1(1, item->rect().center().y());
|
||||
Point p2(width() - 2, item->rect().center().y());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue