MCPcopy
hub / github.com/g3n/engine / SetShortcut

Method SetShortcut

gui/menu.go:612–653  ·  view source on GitHub ↗

SetShortcut sets the keyboard shortcut of this menu item

(mods window.ModifierKey, key window.Key)

Source from the content-addressed store, hash-verified

610
611// SetShortcut sets the keyboard shortcut of this menu item
612func (mi *MenuItem) SetShortcut(mods window.ModifierKey, key window.Key) *MenuItem {
613
614 if mapKeyText[key] == "" {
615 panic("Invalid menu shortcut key")
616 }
617 mi.keyMods = mods
618 mi.keyCode = key
619
620 // If parent menu is a menu bar, nothing more to do
621 if mi.menu.bar {
622 return mi
623 }
624
625 // Builds shortcut text
626 text := ""
627 if mi.keyMods&window.ModShift != 0 {
628 text = mapKeyModifier[window.ModShift]
629 }
630 if mi.keyMods&window.ModControl != 0 {
631 if text != "" {
632 text += "+"
633 }
634 text += mapKeyModifier[window.ModControl]
635 }
636 if mi.keyMods&window.ModAlt != 0 {
637 if text != "" {
638 text += "+"
639 }
640 text += mapKeyModifier[window.ModAlt]
641 }
642 if text != "" {
643 text += "+"
644 }
645 text += mapKeyText[key]
646
647 // Creates and adds shortcut label
648 mi.shortcut = NewLabel(text)
649 mi.Panel.Add(mi.shortcut)
650 mi.update()
651 mi.menu.recalc()
652 return mi
653}
654
655// SetSubmenu sets an associated sub menu item for this menu item
656func (mi *MenuItem) SetSubmenu(smi *MenuItem) *MenuItem {

Callers 1

buildMenuFunction · 0.80

Calls 4

updateMethod · 0.95
NewLabelFunction · 0.85
AddMethod · 0.45
recalcMethod · 0.45

Tested by

no test coverage detected