From 5b6b6b4fe2388701a780e8fcad1690b63ff55a7e Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Sat, 29 Apr 2023 10:44:44 -0700 Subject: [PATCH] add context menu items to bulk set/unset favorite --- ui/widgets/tracklist.go | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/ui/widgets/tracklist.go b/ui/widgets/tracklist.go index a11604b..1c6030b 100644 --- a/ui/widgets/tracklist.go +++ b/ui/widgets/tracklist.go @@ -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) } }