summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-05-05 17:02:13 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-05-05 17:04:17 +0200
commitf4b19ab6e6d067cf176e3a2b8888b8dd2b9f618c (patch)
tree11e72b3e805caa520e0bb14541ffa5146351e371
parentMerge branch 'master' of github.com:lxn/walk (diff)
downloadwireguard-windows-f4b19ab6e6d067cf176e3a2b8888b8dd2b9f618c.tar.xz
wireguard-windows-f4b19ab6e6d067cf176e3a2b8888b8dd2b9f618c.zip
actionlist: provide means of attaching shortcuts to windows
Prior, only shortcuts for main menus worked. With this, it's possible to attach context menu shortcuts or toolbar shortcuts to arbitrary window objects. This isn't super elegant -- it'd be nice were this done automatically. But even in the automatic case, it's possible that folks might want to attach shortcuts to additional windows beyond the one that has the toolbar or context menu. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--actionlist.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/actionlist.go b/actionlist.go
index c15880eb..508faf31 100644
--- a/actionlist.go
+++ b/actionlist.go
@@ -174,3 +174,17 @@ func (l *ActionList) updateSeparatorVisibility() error {
return nil
}
+
+func (l *ActionList) AttachShortcuts(w Window) {
+ shortcuts := make(map[Shortcut]*Action, len(l.actions))
+ for _, action := range l.actions {
+ if action.Shortcut().Key != 0 {
+ shortcuts[action.Shortcut()] = action
+ }
+ }
+ w.KeyDown().Attach(func(key Key) {
+ if action, ok := shortcuts[Shortcut{ModifiersDown(), key}]; ok {
+ action.raiseTriggered()
+ }
+ })
+}