From 0dfd5cad77c4b882ea446fee270d21e321d88021 Mon Sep 17 00:00:00 2001 From: Florian Thienel Date: Sun, 26 May 2024 10:50:00 +0200 Subject: [PATCH] allow to select the first 9 matches from the call info via the keyboard --- core/callinfo/callinfo.go | 14 ++++++++++++-- core/entry/entry.go | 13 +++++++++++++ ui/entryView.go | 20 ++++++++++++++++++-- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/core/callinfo/callinfo.go b/core/callinfo/callinfo.go index 228f272..e9e4999 100644 --- a/core/callinfo/callinfo.go +++ b/core/callinfo/callinfo.go @@ -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. @@ -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 } @@ -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) diff --git a/core/entry/entry.go b/core/entry/entry.go index 4c1899e..e653b98 100644 --- a/core/entry/entry.go +++ b/core/entry/entry.go @@ -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 } @@ -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: @@ -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{} diff --git a/ui/entryView.go b/ui/entryView.go index c61c4f2..8ae430c 100644 --- a/ui/entryView.go +++ b/ui/entryView.go @@ -19,6 +19,7 @@ type EntryController interface { SetActiveField(core.EntryField) Enter(string) + SelectMatch(int) SendQuestion() StopTX() @@ -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 @@ -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()