diff --git a/core/entry/entry.go b/core/entry/entry.go index fd341f1..7574fc0 100644 --- a/core/entry/entry.go +++ b/core/entry/entry.go @@ -424,23 +424,24 @@ func (c *Controller) bandEntered(band core.Band) { } func (c *Controller) VFOFrequencyChanged(frequency core.Frequency) { - if c.editing { - return - } - if c.selectedFrequency == frequency { - return - } - jump := math.Abs(float64(c.selectedFrequency-frequency)) > float64(jumpThreshold) - c.selectedFrequency = frequency - c.view.SetFrequency(c.selectedFrequency) + c.asyncRunner(func() { + if c.editing { + return + } + if c.selectedFrequency == frequency { + return + } + jump := math.Abs(float64(c.selectedFrequency-frequency)) > float64(jumpThreshold) + c.selectedFrequency = frequency - if jump { - c.asyncRunner(func() { + c.view.SetFrequency(frequency) + + if jump { c.Clear() c.activeField = core.CallsignField c.view.SetActiveField(c.activeField) - }) - } + } + }) } func (c *Controller) bandSelected(s string) { @@ -453,15 +454,17 @@ func (c *Controller) bandSelected(s string) { } func (c *Controller) VFOBandChanged(band core.Band) { - if c.editing { - return - } - if band == core.NoBand || band == c.selectedBand { - return - } - c.selectedBand = band - c.input.band = c.selectedBand.String() - c.view.SetBand(c.input.band) + c.asyncRunner(func() { + if c.editing { + return + } + if band == core.NoBand || band == c.selectedBand { + return + } + c.selectedBand = band + c.input.band = c.selectedBand.String() + c.view.SetBand(c.input.band) + }) } func (c *Controller) modeSelected(s string) { @@ -478,7 +481,7 @@ func (c *Controller) modeSelected(s string) { } func (c *Controller) generateReportForMode(mode core.Mode) { - generatedReport := defaultReportForMode(c.selectedMode) + generatedReport := defaultReportForMode(mode) myIndex := c.myReportExchangeField.Field.ExchangeIndex() if myIndex > 0 { c.input.myReport = generatedReport @@ -505,15 +508,17 @@ func defaultReportForMode(mode core.Mode) string { } func (c *Controller) VFOModeChanged(mode core.Mode) { - if c.editing { - return - } - if mode == core.NoMode || mode == c.selectedMode { - return - } - c.selectedMode = mode - c.input.mode = c.selectedMode.String() - c.view.SetMode(c.input.mode) + c.asyncRunner(func() { + if c.editing { + return + } + if mode == core.NoMode || mode == c.selectedMode { + return + } + c.selectedMode = mode + c.input.mode = c.selectedMode.String() + c.view.SetMode(c.input.mode) + }) } func (c *Controller) SendQuestion() { diff --git a/core/entry/entry_test.go b/core/entry/entry_test.go index 8533a7a..e47496f 100644 --- a/core/entry/entry_test.go +++ b/core/entry/entry_test.go @@ -587,7 +587,7 @@ func TestEntryController_EditQSO(t *testing.T) { log.Activate() log.On("Log", changedQSO).Once() - log.On("LastExchange").Return([]string{"599", "001", ""}).Once() + log.On("LastExchange").Return([]string{"599", "001", ""}).Times(2) log.On("NextNumber").Return(core.QSONumber(35)) controller.Log() @@ -603,7 +603,7 @@ func setupEntryTest() (core.Clock, *mocked.Log, *mocked.QSOList, *mocked.EntryVi qsoList := new(mocked.QSOList) view := new(mocked.EntryView) settings := &testSettings{myCall: "DL0ABC"} - controller := NewController(settings, clock, qsoList, new(nullBandmap), testIgnoreAsync) + controller := NewController(settings, clock, qsoList, new(nullBandmap), testRunSync) vfo := &testVFO{controller} controller.SetVFO(vfo) controller.SetLogbook(log) @@ -621,7 +621,7 @@ func setupEntryTestWithClassicExchangeFields() (core.Clock, *mocked.Log, *mocked view := new(mocked.EntryView) exchangeFields := []conval.ExchangeField{{conval.RSTProperty}, {conval.SerialNumberProperty}, {conval.GenericTextProperty}} settings := &testSettings{myCall: "DL0ABC", exchangeFields: exchangeFields, exchangeValues: []string{"599", "", ""}, generateSerialExchange: true} - controller := NewController(settings, clock, qsoList, new(nullBandmap), testIgnoreAsync) + controller := NewController(settings, clock, qsoList, new(nullBandmap), testRunSync) vfo := &testVFO{controller} controller.SetVFO(vfo) controller.SetLogbook(log) @@ -643,7 +643,7 @@ func setupEntryTestWithExchangeFields(exchangeFieldCount int) (core.Clock, *mock exchangeFields[i] = conval.ExchangeField{conval.GenericTextProperty} } settings := &testSettings{myCall: "DL0ABC", exchangeFields: exchangeFields, exchangeValues: exchangeValues} - controller := NewController(settings, clock, qsoList, new(nullBandmap), testIgnoreAsync) + controller := NewController(settings, clock, qsoList, new(nullBandmap), testRunSync) vfo := &testVFO{controller} controller.SetVFO(vfo) controller.SetLogbook(log) @@ -692,6 +692,8 @@ func (s *testSettings) Contest() core.Contest { func testIgnoreAsync(f func()) {} +func testRunSync(f func()) { f() } + func fieldDefinition(fields ...conval.ExchangeField) *conval.Definition { return &conval.Definition{ Exchange: []conval.ExchangeDefinition{ diff --git a/ui/entryView.go b/ui/entryView.go index 8ae430c..b90b735 100644 --- a/ui/entryView.go +++ b/ui/entryView.go @@ -208,9 +208,7 @@ func (v *entryView) setTextWithoutChangeEvent(f func(string), value string) { } func (v *entryView) SetUTC(text string) { - runAsync(func() { - v.utc.SetText(text) - }) + v.utc.SetText(text) } func (v *entryView) SetMyCall(text string) { @@ -218,9 +216,7 @@ func (v *entryView) SetMyCall(text string) { } func (v *entryView) SetFrequency(frequency core.Frequency) { - runAsync(func() { - v.frequency.SetText(fmt.Sprintf("%.2f kHz", frequency/1000.0)) - }) + v.frequency.SetText(fmt.Sprintf("%.2f kHz", frequency/1000.0)) } func (v *entryView) SetCallsign(text string) { @@ -236,15 +232,11 @@ func (v *entryView) SetTheirExchange(index int, text string) { } func (v *entryView) SetBand(text string) { - runAsync(func() { - v.setTextWithoutChangeEvent(func(s string) { v.band.SetActiveID(s) }, text) - }) + v.setTextWithoutChangeEvent(func(s string) { v.band.SetActiveID(s) }, text) } func (v *entryView) SetMode(text string) { - runAsync(func() { - v.setTextWithoutChangeEvent(func(s string) { v.mode.SetActiveID(s) }, text) - }) + v.setTextWithoutChangeEvent(func(s string) { v.mode.SetActiveID(s) }, text) } func (v *entryView) SetMyExchange(index int, text string) {