add context menu items to bulk set/unset favorite

This commit is contained in:
Drew Weymouth
2023-04-29 10:44:44 -07:00
parent c138be381e
commit 5b6b6b4fe2
+23 -6
View File
@@ -282,6 +282,15 @@ func (t *Tracklist) onShowContextMenu(e *fyne.PointEvent, trackIdx int) {
t.OnAddToPlaylist(t.selectedTrackIDs())
}
}))
t.ctxMenu.Items = append(t.ctxMenu.Items, fyne.NewMenuItemSeparator())
t.ctxMenu.Items = append(t.ctxMenu.Items,
fyne.NewMenuItem("Set favorite", func() {
t.onSetFavorites(t.selectedTracks(), true, true)
}))
t.ctxMenu.Items = append(t.ctxMenu.Items,
fyne.NewMenuItem("Unset favorite", func() {
t.onSetFavorites(t.selectedTracks(), false, true)
}))
if len(t.AuxiliaryMenuItems) > 0 {
t.ctxMenu.Items = append(t.ctxMenu.Items, fyne.NewMenuItemSeparator())
t.ctxMenu.Items = append(t.ctxMenu.Items, t.AuxiliaryMenuItems...)
@@ -291,18 +300,26 @@ func (t *Tracklist) onShowContextMenu(e *fyne.PointEvent, trackIdx int) {
}
func (t *Tracklist) onSetFavorite(trackID string, fav bool) {
// update our own track model
t.tracksMutex.RLock()
tr := sharedutil.FindTrackByID(trackID, t.Tracks)
t.tracksMutex.RUnlock()
if fav {
tr.Starred = time.Now()
} else {
tr.Starred = time.Time{}
t.onSetFavorites([]*subsonic.Child{tr}, fav, false)
}
func (t *Tracklist) onSetFavorites(tracks []*subsonic.Child, fav bool, needRefresh bool) {
for _, tr := range tracks {
if fav {
tr.Starred = time.Now()
} else {
tr.Starred = time.Time{}
}
}
if needRefresh {
t.Refresh()
}
// notify listener
if t.OnSetFavorite != nil {
t.OnSetFavorite([]string{trackID}, fav)
t.OnSetFavorite(sharedutil.TracksToIDs(tracks), fav)
}
}