-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
shortcut.go
48 lines (42 loc) · 1.01 KB
/
shortcut.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package desktop
import (
"runtime"
"strings"
"fyne.io/fyne"
)
// Declare conformity with Shortcut interface
var _ fyne.Shortcut = (*CustomShortcut)(nil)
// CustomShortcut describes a shortcut desktop event.
type CustomShortcut struct {
fyne.KeyName
Modifier
}
// ShortcutName returns the shortcut name associated to the event
func (cs *CustomShortcut) ShortcutName() string {
id := &strings.Builder{}
id.WriteString("CustomDesktop:")
id.WriteString(modifierToString(cs.Modifier))
id.WriteString("+")
id.WriteString(string(cs.KeyName))
return id.String()
}
func modifierToString(mods Modifier) string {
s := []string{}
if (mods & ShiftModifier) != 0 {
s = append(s, string("Shift"))
}
if (mods & ControlModifier) != 0 {
s = append(s, string("Control"))
}
if (mods & AltModifier) != 0 {
s = append(s, string("Alt"))
}
if (mods & SuperModifier) != 0 {
if runtime.GOOS == "darwin" {
s = append(s, string("Command"))
} else {
s = append(s, string("Super"))
}
}
return strings.Join(s, "+")
}