Skip to content

Commit

Permalink
allow to select the first 9 matches from the call info via the keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
ftl committed May 26, 2024
1 parent 9b4d0ef commit 0dfd5ca
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
14 changes: 12 additions & 2 deletions core/callinfo/callinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type Callinfo struct {
lastExchange []string
predictedExchange []string
theirExchangeFields []core.ExchangeField

bestMatches []string
}

// DXCCFinder returns a list of matching prefixes for the given string and indicates if there was a match at all.
Expand Down Expand Up @@ -112,6 +114,10 @@ func (c *Callinfo) ContestChanged(contest core.Contest) {
c.view.SetPredictedExchangeFields(c.theirExchangeFields)
}

func (c *Callinfo) BestMatches() []string {
return c.bestMatches
}

func (c *Callinfo) PredictedExchange() []string {
return c.predictedExchange
}
Expand Down Expand Up @@ -167,9 +173,13 @@ func (c *Callinfo) ShowInfo(call string, band core.Band, mode core.Mode, exchang
}

supercheck := c.calculateSupercheck(call)
c.bestMatches = make([]string, 0, len(supercheck))
bestMatch := ""
if len(supercheck) > 0 {
bestMatch = supercheck[0].Callsign.String()
for i, match := range supercheck {
c.bestMatches = append(c.bestMatches, match.Callsign.String())
if i == 0 {
bestMatch = c.bestMatches[0]
}
}

c.showDXCCEntity(entity)
Expand Down
13 changes: 13 additions & 0 deletions core/entry/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type Keyer interface {
// Callinfo functionality used for QSO entry.
type Callinfo interface {
ShowInfo(call string, band core.Band, mode core.Mode, exchange []string)
BestMatches() []string
PredictedExchange() []string
}

Expand Down Expand Up @@ -374,6 +375,17 @@ func (c *Controller) SetActiveField(field core.EntryField) {
c.activeField = field
}

func (c *Controller) SelectMatch(index int) {
matches := c.callinfo.BestMatches()
if index < 0 || index >= len(matches) {
return
}

c.input.callsign = matches[index]
c.enterCallsign(matches[index])
c.showInput()
}

func (c *Controller) Enter(text string) {
switch c.activeField {
case core.CallsignField:
Expand Down Expand Up @@ -968,6 +980,7 @@ func (n *nullLogbook) Log(core.QSO) {}
type nullCallinfo struct{}

func (n *nullCallinfo) ShowInfo(string, core.Band, core.Mode, []string) {}
func (n *nullCallinfo) BestMatches() []string { return []string{} }
func (n *nullCallinfo) PredictedExchange() []string { return []string{} }

type nullBandmap struct{}
Expand Down
20 changes: 18 additions & 2 deletions ui/entryView.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type EntryController interface {
SetActiveField(core.EntryField)

Enter(string)
SelectMatch(int)
SendQuestion()
StopTX()

Expand Down Expand Up @@ -107,7 +108,18 @@ func (v *entryView) addEntryEventHandlers(w *gtk.Widget) {
func (v *entryView) onEntryKeyPress(_ interface{}, event *gdk.Event) bool {
keyEvent := gdk.EventKeyNewFromEvent(event)
ctrl := keyEvent.State()&gdk.CONTROL_MASK != 0
switch keyEvent.KeyVal() {
alt := keyEvent.State()&gdk.MOD1_MASK != 0 // MOD1 = ALT right
key := keyEvent.KeyVal()

switch key {
case gdk.KEY_1, gdk.KEY_2, gdk.KEY_3, gdk.KEY_4, gdk.KEY_5, gdk.KEY_6, gdk.KEY_7, gdk.KEY_8, gdk.KEY_9:
if alt {
index := int(key - gdk.KEY_1)
v.controller.SelectMatch(index)
return true
} else {
return false
}
case gdk.KEY_Tab:
v.controller.GotoNextField()
return true
Expand All @@ -119,7 +131,11 @@ func (v *entryView) onEntryKeyPress(_ interface{}, event *gdk.Event) bool {
}
return true
case gdk.KEY_Return:
v.controller.Log()
if alt {
v.controller.SelectMatch(0)
} else {
v.controller.Log()
}
return true
case gdk.KEY_question:
v.controller.SendQuestion()
Expand Down

0 comments on commit 0dfd5ca

Please sign in to comment.