MCPcopy Index your code
hub / github.com/g3n/engine / AttribCheckMenuShortcut

Function AttribCheckMenuShortcut

gui/builder.go:767–811  ·  view source on GitHub ↗

AttribCheckMenuShortcut checks and converts attribute describing menu shortcut key

(b *Builder, am map[string]interface{}, fname string)

Source from the content-addressed store, hash-verified

765
766// AttribCheckMenuShortcut checks and converts attribute describing menu shortcut key
767func AttribCheckMenuShortcut(b *Builder, am map[string]interface{}, fname string) error {
768
769 v := am[fname]
770 if v == nil {
771 return nil
772 }
773 vs, ok := v.(string)
774 if !ok {
775 return b.err(am, fname, "Not a string")
776 }
777 sc := strings.Trim(vs, " ")
778 if sc == "" {
779 return nil
780 }
781 parts := strings.Split(sc, "+")
782 var mods window.ModifierKey
783 for i := 0; i < len(parts)-1; i++ {
784 switch parts[i] {
785 case "Shift":
786 mods |= window.ModShift
787 case "Ctrl":
788 mods |= window.ModControl
789 case "Alt":
790 mods |= window.ModAlt
791 default:
792 return b.err(am, fname, "Invalid shortcut:"+sc)
793 }
794 }
795 // The last part must be a key
796 keyname := parts[len(parts)-1]
797 var keycode int
798 found := false
799 for kcode, kname := range mapKeyText {
800 if kname == keyname {
801 keycode = int(kcode)
802 found = true
803 break
804 }
805 }
806 if !found {
807 return b.err(am, fname, "Invalid shortcut:"+sc)
808 }
809 am[fname] = []int{int(mods), keycode}
810 return nil
811}
812
813// AttribCheckListMap checks and converts attribute to []map[string]interface{}
814func AttribCheckListMap(b *Builder, am map[string]interface{}, fname string) error {

Callers

nothing calls this directly

Calls 2

errMethod · 0.80
SplitMethod · 0.80

Tested by

no test coverage detected