Fix #619: remove correct tracks from playlist if in searched view

This commit is contained in:
Drew Weymouth
2025-05-14 08:30:32 -07:00
parent dc180cd973
commit a23e7d382d
2 changed files with 30 additions and 16 deletions
+18 -4
View File
@@ -221,7 +221,6 @@ func (a *PlaylistPage) doSetNewTrackOrder(ids []string, newPos int) {
newTracks := sharedutil.ReorderItems(a.tracks, idxs, newPos) newTracks := sharedutil.ReorderItems(a.tracks, idxs, newPos)
ids = sharedutil.TracksToIDs(newTracks) ids = sharedutil.TracksToIDs(newTracks)
// we can't block the UI waiting for the server so assume it will succeed
go func() { go func() {
if err := a.sm.Server.ReplacePlaylistTracks(a.playlistID, ids); err != nil { if err := a.sm.Server.ReplacePlaylistTracks(a.playlistID, ids); err != nil {
log.Printf("error updating playlist: %s", err.Error()) log.Printf("error updating playlist: %s", err.Error())
@@ -244,9 +243,24 @@ func (a *PlaylistPage) doSetNewTrackOrder(ids []string, newPos int) {
} }
func (a *PlaylistPage) onRemoveSelectedFromPlaylist() { func (a *PlaylistPage) onRemoveSelectedFromPlaylist() {
a.sm.Server.RemovePlaylistTracks(a.playlistID, a.tracklist.SelectedTrackIndexes()) idxToRemove := sharedutil.MapSlice(a.tracklist.SelectedTracks(), func(t *mediaprovider.Track) int {
a.tracklist.UnselectAll() return t.TrackNumber - 1
a.Reload() })
go func() {
if err := a.sm.Server.RemovePlaylistTracks(a.playlistID, idxToRemove); err != nil {
log.Printf("error removing playlist tracks: %s", err.Error())
fyne.Do(func() {
a.contr.ToastProvider.ShowErrorToast(
lang.L("An error occurred updating the playlist"),
)
})
} else {
fyne.Do(func() {
a.tracklist.UnselectAll()
a.Reload()
})
}
}()
} }
func (a *PlaylistPage) onSearched(query string) { func (a *PlaylistPage) onSearched(query string) {
+12 -12
View File
@@ -509,40 +509,40 @@ func (t *Tracklist) onShowContextMenu(e *fyne.PointEvent, trackIdx int) {
if t.ctxMenu == nil { if t.ctxMenu == nil {
t.ctxMenu = util.NewTrackContextMenu(t.Options.DisablePlaybackMenu, t.Options.AuxiliaryMenuItems) t.ctxMenu = util.NewTrackContextMenu(t.Options.DisablePlaybackMenu, t.Options.AuxiliaryMenuItems)
t.ctxMenu.OnPlay = func(shuffle bool) { t.ctxMenu.OnPlay = func(shuffle bool) {
t.OnPlaySelection(t.selectedTracks(), shuffle) t.OnPlaySelection(t.SelectedTracks(), shuffle)
} }
t.ctxMenu.OnAddToQueue = func(next bool) { t.ctxMenu.OnAddToQueue = func(next bool) {
if next { if next {
t.OnPlaySelectionNext(t.selectedTracks()) t.OnPlaySelectionNext(t.SelectedTracks())
} else { } else {
t.OnAddToQueue(t.selectedTracks()) t.OnAddToQueue(t.SelectedTracks())
} }
} }
t.ctxMenu.OnPlaySongRadio = func() { t.ctxMenu.OnPlaySongRadio = func() {
t.onPlaySongRadio(t.selectedTracks()) t.onPlaySongRadio(t.SelectedTracks())
} }
t.ctxMenu.OnAddToPlaylist = func() { t.ctxMenu.OnAddToPlaylist = func() {
t.OnAddToPlaylist(t.SelectedTrackIDs()) t.OnAddToPlaylist(t.SelectedTrackIDs())
} }
t.ctxMenu.OnDownload = func() { t.ctxMenu.OnDownload = func() {
t.onDownload(t.selectedTracks(), "Selected tracks") t.onDownload(t.SelectedTracks(), "Selected tracks")
} }
t.ctxMenu.OnShowInfo = func() { t.ctxMenu.OnShowInfo = func() {
t.OnShowTrackInfo(t.selectedTracks()[0]) t.OnShowTrackInfo(t.SelectedTracks()[0])
} }
t.ctxMenu.OnFavorite = func(fav bool) { t.ctxMenu.OnFavorite = func(fav bool) {
t.onSetFavorites(t.selectedTracks(), fav, true /*needRefresh*/) t.onSetFavorites(t.SelectedTracks(), fav, true /*needRefresh*/)
} }
t.ctxMenu.OnShare = func() { t.ctxMenu.OnShare = func() {
t.onShare(t.selectedTracks()) t.onShare(t.SelectedTracks())
} }
t.ctxMenu.OnSetRating = func(rating int) { t.ctxMenu.OnSetRating = func(rating int) {
t.onSetRatings(t.selectedTracks(), rating, true /*needRefresh*/) t.onSetRatings(t.SelectedTracks(), rating, true /*needRefresh*/)
} }
} }
t.ctxMenu.SetRatingDisabled(t.Options.DisableRating) t.ctxMenu.SetRatingDisabled(t.Options.DisableRating)
t.ctxMenu.SetShareDisabled(t.Options.DisableSharing || len(t.selectedTracks()) != 1) t.ctxMenu.SetShareDisabled(t.Options.DisableSharing || len(t.SelectedTracks()) != 1)
t.ctxMenu.SetInfoDisabled(len(t.selectedTracks()) != 1) t.ctxMenu.SetInfoDisabled(len(t.SelectedTracks()) != 1)
t.ctxMenu.ShowAtPosition(e.AbsolutePosition, fyne.CurrentApp().Driver().CanvasForObject(t)) t.ctxMenu.ShowAtPosition(e.AbsolutePosition, fyne.CurrentApp().Driver().CanvasForObject(t))
} }
@@ -617,7 +617,7 @@ func (t *Tracklist) onPlaySongRadio(tracks []*mediaprovider.Track) {
} }
} }
func (t *Tracklist) selectedTracks() []*mediaprovider.Track { func (t *Tracklist) SelectedTracks() []*mediaprovider.Track {
return util.SelectedTracks(t.tracks) return util.SelectedTracks(t.tracks)
} }