diff options
author | Alexander Neumann <an2048@gmail.com> | 2019-05-06 10:50:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-06 10:50:35 +0200 |
commit | 771ecad6dce9495720ca1a87a670c0d90fbedc5f (patch) | |
tree | 40e0a114cab9e18f0235429a00979ee4647b88cf | |
parent | Merge pull request #504 from zx2c4-forks/jd/tooltip-length (diff) | |
parent | actionlist: provide means of attaching shortcuts to windows (diff) | |
download | wireguard-windows-771ecad6dce9495720ca1a87a670c0d90fbedc5f.tar.xz wireguard-windows-771ecad6dce9495720ca1a87a670c0d90fbedc5f.zip |
Merge pull request #506 from zx2c4-forks/jd/shortcutaction
actionlist: provide means of attaching shortcuts to windows
-rw-r--r-- | actionlist.go | 14 |
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() + } + }) +} |