Skip to content

Commit

Permalink
add shortcuts for the keyer macros
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Thienel <[email protected]>
  • Loading branch information
ftl committed Dec 8, 2024
1 parent 1c8bd11 commit edb45b9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fyneui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (a *application) activate() {
a.controller = app.NewController(a.version, clock.New(), a.app, a.runAsync, configuration, a.sponsors)
a.controller.Startup()

a.shortcuts = setupShortcuts(a.controller)
a.shortcuts = setupShortcuts(a.controller, a.controller.Keyer)
a.qsoList = setupQSOList()
a.keyerControl = setupKeyerControl()
a.statusBar = setupStatusBar()
Expand Down
30 changes: 29 additions & 1 deletion fyneui/shortcuts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ const (
OpenShortcut ShortcutID = "open"
OpenSettingsShortcut ShortcutID = "open_settings"
QuitShortcut ShortcutID = "quit"

SendMacroF1Shortcut ShortcutID = "macro_f1"
SendMacroF2Shortcut ShortcutID = "macro_f2"
SendMacroF3Shortcut ShortcutID = "macro_f3"
SendMacroF4Shortcut ShortcutID = "macro_f4"
StopTXShortcut ShortcutID = "stop_tx"
)

type ShortcutConsumer interface {
AddShortcut(fyne.Shortcut, func(shortcut fyne.Shortcut))
SetOnTypedKey(func(*fyne.KeyEvent))
}

type Shortcut struct {
Expand All @@ -40,11 +47,16 @@ type ShortcutController interface {
}

type Shortcuts struct {
controller ShortcutController
keyerController KeyerController

shortcuts map[ShortcutID]*Shortcut
}

func setupShortcuts(controller ShortcutController) *Shortcuts {
func setupShortcuts(controller ShortcutController, keyerController KeyerController) *Shortcuts {
return &Shortcuts{
controller: controller,
keyerController: keyerController,
shortcuts: map[ShortcutID]*Shortcut{
OpenShortcut: {
ID: OpenShortcut,
Expand Down Expand Up @@ -73,4 +85,20 @@ func (s *Shortcuts) AddTo(consumer ShortcutConsumer) {
for _, shortcut := range s.shortcuts {
shortcut.AddTo(consumer)
}
consumer.SetOnTypedKey(s.onTypedKey)
}

func (s *Shortcuts) onTypedKey(key *fyne.KeyEvent) {
switch key.Name {
case fyne.KeyF1:
s.keyerController.Send(0)
case fyne.KeyF2:
s.keyerController.Send(1)
case fyne.KeyF3:
s.keyerController.Send(2)
case fyne.KeyF4:
s.keyerController.Send(3)
case fyne.KeyEscape:
s.keyerController.Stop()
}
}

0 comments on commit edb45b9

Please sign in to comment.