SetShortcut sets the keyboard shortcut of this menu item
(mods window.ModifierKey, key window.Key)
| 610 | |
| 611 | // SetShortcut sets the keyboard shortcut of this menu item |
| 612 | func (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 |
| 656 | func (mi *MenuItem) SetSubmenu(smi *MenuItem) *MenuItem { |