add tracklist submenu to bulk set rating
This commit is contained in:
+31
-2
@@ -291,6 +291,16 @@ func (t *Tracklist) onShowContextMenu(e *fyne.PointEvent, trackIdx int) {
|
|||||||
fyne.NewMenuItem("Unset favorite", func() {
|
fyne.NewMenuItem("Unset favorite", func() {
|
||||||
t.onSetFavorites(t.selectedTracks(), false, true)
|
t.onSetFavorites(t.selectedTracks(), false, true)
|
||||||
}))
|
}))
|
||||||
|
ratingMenu := fyne.NewMenuItem("Set rating", nil)
|
||||||
|
ratingMenu.ChildMenu = fyne.NewMenu("", []*fyne.MenuItem{
|
||||||
|
t.newRatingMenuItem(0),
|
||||||
|
t.newRatingMenuItem(1),
|
||||||
|
t.newRatingMenuItem(2),
|
||||||
|
t.newRatingMenuItem(3),
|
||||||
|
t.newRatingMenuItem(4),
|
||||||
|
t.newRatingMenuItem(5),
|
||||||
|
}...)
|
||||||
|
t.ctxMenu.Items = append(t.ctxMenu.Items, ratingMenu)
|
||||||
if len(t.AuxiliaryMenuItems) > 0 {
|
if len(t.AuxiliaryMenuItems) > 0 {
|
||||||
t.ctxMenu.Items = append(t.ctxMenu.Items, fyne.NewMenuItemSeparator())
|
t.ctxMenu.Items = append(t.ctxMenu.Items, fyne.NewMenuItemSeparator())
|
||||||
t.ctxMenu.Items = append(t.ctxMenu.Items, t.AuxiliaryMenuItems...)
|
t.ctxMenu.Items = append(t.ctxMenu.Items, t.AuxiliaryMenuItems...)
|
||||||
@@ -299,6 +309,16 @@ func (t *Tracklist) onShowContextMenu(e *fyne.PointEvent, trackIdx int) {
|
|||||||
widget.ShowPopUpMenuAtPosition(t.ctxMenu, fyne.CurrentApp().Driver().CanvasForObject(t), e.AbsolutePosition)
|
widget.ShowPopUpMenuAtPosition(t.ctxMenu, fyne.CurrentApp().Driver().CanvasForObject(t), e.AbsolutePosition)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Tracklist) newRatingMenuItem(rating int) *fyne.MenuItem {
|
||||||
|
label := "(none)"
|
||||||
|
if rating > 0 {
|
||||||
|
label = strconv.Itoa(rating)
|
||||||
|
}
|
||||||
|
return fyne.NewMenuItem(label, func() {
|
||||||
|
t.onSetRatings(t.selectedTracks(), rating, true)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Tracklist) onSetFavorite(trackID string, fav bool) {
|
func (t *Tracklist) onSetFavorite(trackID string, fav bool) {
|
||||||
t.tracksMutex.RLock()
|
t.tracksMutex.RLock()
|
||||||
tr := sharedutil.FindTrackByID(trackID, t.Tracks)
|
tr := sharedutil.FindTrackByID(trackID, t.Tracks)
|
||||||
@@ -328,10 +348,19 @@ func (t *Tracklist) onSetRating(trackID string, rating int) {
|
|||||||
t.tracksMutex.RLock()
|
t.tracksMutex.RLock()
|
||||||
tr := sharedutil.FindTrackByID(trackID, t.Tracks)
|
tr := sharedutil.FindTrackByID(trackID, t.Tracks)
|
||||||
t.tracksMutex.RUnlock()
|
t.tracksMutex.RUnlock()
|
||||||
tr.UserRating = rating
|
t.onSetRatings([]*subsonic.Child{tr}, rating, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tracklist) onSetRatings(tracks []*subsonic.Child, rating int, needRefresh bool) {
|
||||||
|
for _, tr := range tracks {
|
||||||
|
tr.UserRating = rating
|
||||||
|
}
|
||||||
|
if needRefresh {
|
||||||
|
t.Refresh()
|
||||||
|
}
|
||||||
// notify listener
|
// notify listener
|
||||||
if t.OnSetRating != nil {
|
if t.OnSetRating != nil {
|
||||||
t.OnSetRating([]string{trackID}, rating)
|
t.OnSetRating(sharedutil.TracksToIDs(tracks), rating)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user