mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:07:46 +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
|
@ -5,6 +5,7 @@
|
|||
#include <AK/Retainable.h>
|
||||
#include <AK/Retained.h>
|
||||
#include <SharedGraphics/GraphicsBitmap.h>
|
||||
#include <LibGUI/GShortcut.h>
|
||||
|
||||
class GAction : public Retainable<GAction> {
|
||||
public:
|
||||
|
@ -20,9 +21,14 @@ public:
|
|||
{
|
||||
return adopt(*new GAction(text, move(icon), move(callback)));
|
||||
}
|
||||
static Retained<GAction> create(const String& text, const GShortcut& shortcut, RetainPtr<GraphicsBitmap>&& icon, Function<void(const GAction&)> callback)
|
||||
{
|
||||
return adopt(*new GAction(text, shortcut, move(icon), move(callback)));
|
||||
}
|
||||
~GAction();
|
||||
|
||||
String text() const { return m_text; }
|
||||
GShortcut shortcut() const { return m_shortcut; }
|
||||
String custom_data() const { return m_custom_data; }
|
||||
const GraphicsBitmap* icon() const { return m_icon.ptr(); }
|
||||
|
||||
|
@ -32,11 +38,13 @@ public:
|
|||
|
||||
private:
|
||||
GAction(const String& text, Function<void(const GAction&)> = nullptr);
|
||||
GAction(const String& text, const GShortcut&, RetainPtr<GraphicsBitmap>&& icon, Function<void(const GAction&)> = nullptr);
|
||||
GAction(const String& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(const GAction&)> = nullptr);
|
||||
GAction(const String& text, const String& custom_data = String(), Function<void(const GAction&)> = nullptr);
|
||||
|
||||
String m_text;
|
||||
String m_custom_data;
|
||||
RetainPtr<GraphicsBitmap> m_icon;
|
||||
GShortcut m_shortcut;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue