Skip to content

Commit

Permalink
add shortcut to go to the highest value spot
Browse files Browse the repository at this point in the history
  • Loading branch information
ftl committed Nov 12, 2023
1 parent 88b6246 commit 14ef328
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 7 deletions.
4 changes: 4 additions & 0 deletions core/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,10 @@ func (c *Controller) MarkInBandmap() {
c.Entry.MarkInBandmap()
}

func (c *Controller) GotoHighestValueSpot() {
c.Bandmap.GotoHighestValueEntry()
}

func (c *Controller) GotoNearestSpot() {
c.Bandmap.GotoNearestEntry()
}
Expand Down
23 changes: 21 additions & 2 deletions core/bandmap/bandmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Callinfo interface {
var defaultWeights = core.BandmapWeights{
TotalPoints: 1,
TotalMultis: 1,
AgeSeconds: -0.01,
AgeSeconds: -0.001,
Spots: 0,
Source: 0,
}
Expand Down Expand Up @@ -318,6 +318,12 @@ func (m *Bandmap) SelectByCallsign(call callsign.Callsign) bool {
return <-result
}

func (m *Bandmap) GotoHighestValueEntry() {
m.findAndSelectNextVisibleEntryBy(core.BandmapByDescendingValue, func(entry core.BandmapEntry) bool {
return entry.Frequency != m.activeFrequency && entry.Source != core.WorkedSpot
})
}

func (m *Bandmap) GotoNearestEntry() {
m.findAndSelectNextVisibleEntry(func(entry core.BandmapEntry) bool {
return entry.Frequency != m.activeFrequency && entry.Source != core.WorkedSpot
Expand Down Expand Up @@ -345,8 +351,21 @@ func (m *Bandmap) findAndSelectNextVisibleEntry(f func(entry core.BandmapEntry)
}
}

func (m *Bandmap) findAndSelectNextVisibleEntryBy(order core.BandmapOrder, f func(entry core.BandmapEntry) bool) {
m.do <- func() {
entry, found := m.nextVisibleEntryBy(order, f)
if found {
m.entries.Select(entry.Index)
}
}
}

func (m *Bandmap) nextVisibleEntry(frequency core.Frequency, f func(core.BandmapEntry) bool) (core.BandmapEntry, bool) {
entries := m.entries.AllBy(core.BandmapByDistance(frequency))
return m.nextVisibleEntryBy(core.BandmapByDistance(frequency), f)
}

func (m *Bandmap) nextVisibleEntryBy(order core.BandmapOrder, f func(core.BandmapEntry) bool) (core.BandmapEntry, bool) {
entries := m.entries.AllBy(order)
for i := 0; i < len(entries); i++ {
entry := entries[i]
if !m.entryVisible(entry) {
Expand Down
4 changes: 4 additions & 0 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,10 @@ func BandmapByDistance(referenceFrequency Frequency) BandmapOrder {
}
}

func BandmapByDescendingValue(a, b BandmapEntry) bool {
return a.Info.WeightedValue > b.Info.WeightedValue
}

type BandmapWeights struct {
TotalPoints float64
TotalMultis float64
Expand Down
9 changes: 9 additions & 0 deletions ui/glade/contest.glade
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,15 @@ THE SOFTWARE.
<property name="can-focus">False</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuBandmapGotoHighestValueSpot">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Go to Highest Value Spot</property>
<property name="use-underline">True</property>
<accelerator key="n" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuBandmapGotoNearestSpot">
<property name="visible">True</property>
Expand Down
18 changes: 13 additions & 5 deletions ui/mainMenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type MainMenuController interface {
SwitchToSPWorkmode()
SwitchToRunWorkmode()
MarkInBandmap()
GotoHighestValueSpot()
GotoNearestSpot()
GotoNextSpotUp()
GotoNextSpotDown()
Expand Down Expand Up @@ -66,11 +67,12 @@ type mainMenu struct {
editSP *gtk.RadioMenuItem
editRun *gtk.RadioMenuItem

bandmapMark *gtk.MenuItem
bandmapGotoNearestSpot *gtk.MenuItem
bandmapGotoNextSpotUp *gtk.MenuItem
bandmapGotoNextSpotDown *gtk.MenuItem
bandmapSendSpotsToTci *gtk.CheckMenuItem
bandmapMark *gtk.MenuItem
bandmapGotoHighestValueSpot *gtk.MenuItem
bandmapGotoNearestSpot *gtk.MenuItem
bandmapGotoNextSpotUp *gtk.MenuItem
bandmapGotoNextSpotDown *gtk.MenuItem
bandmapSendSpotsToTci *gtk.CheckMenuItem

windowCallinfo *gtk.MenuItem
windowScore *gtk.MenuItem
Expand Down Expand Up @@ -106,6 +108,7 @@ func setupMainMenu(builder *gtk.Builder, setAcceptFocus AcceptFocusFunc) *mainMe
result.editSP = getUI(builder, "menuEditSP").(*gtk.RadioMenuItem)
result.editRun = getUI(builder, "menuEditRun").(*gtk.RadioMenuItem)
result.bandmapMark = getUI(builder, "menuBandmapMark").(*gtk.MenuItem)
result.bandmapGotoHighestValueSpot = getUI(builder, "menuBandmapGotoHighestValueSpot").(*gtk.MenuItem)
result.bandmapGotoNearestSpot = getUI(builder, "menuBandmapGotoNearestSpot").(*gtk.MenuItem)
result.bandmapGotoNextSpotUp = getUI(builder, "menuBandmapGotoNextSpotUp").(*gtk.MenuItem)
result.bandmapGotoNextSpotDown = getUI(builder, "menuBandmapGotoNextSpotDown").(*gtk.MenuItem)
Expand Down Expand Up @@ -138,6 +141,7 @@ func setupMainMenu(builder *gtk.Builder, setAcceptFocus AcceptFocusFunc) *mainMe
result.editSP.Connect("toggled", result.onSP)
result.editRun.Connect("toggled", result.onRun)
result.bandmapMark.Connect("activate", result.onMarkInBandmap)
result.bandmapGotoHighestValueSpot.Connect("activate", result.onGotoHighestValueSpot)
result.bandmapGotoNearestSpot.Connect("activate", result.onGotoNearestSpot)
result.bandmapGotoNextSpotUp.Connect("activate", result.onGotoNextSpotUp)
result.bandmapGotoNextSpotDown.Connect("activate", result.onGotoNextSpotDown)
Expand Down Expand Up @@ -271,6 +275,10 @@ func (m *mainMenu) onMarkInBandmap() {
m.controller.MarkInBandmap()
}

func (m *mainMenu) onGotoHighestValueSpot() {
m.controller.GotoHighestValueSpot()
}

func (m *mainMenu) onGotoNearestSpot() {
m.controller.GotoNearestSpot()
}
Expand Down

0 comments on commit 14ef328

Please sign in to comment.