Fix #33: allow reordering of play queue
This commit is contained in:
@@ -77,6 +77,7 @@ func NewNowPlayingPage(
|
||||
DisablePlaybackMenu: true,
|
||||
DisableRating: !canRate,
|
||||
AuxiliaryMenuItems: []*fyne.MenuItem{
|
||||
util.NewReorderTracksSubmenu(a.doSetNewTrackOrder),
|
||||
fyne.NewMenuItem("Remove from queue", a.onRemoveSelectedFromQueue),
|
||||
},
|
||||
}
|
||||
@@ -208,6 +209,26 @@ func (a *NowPlayingPage) onRemoveSelectedFromQueue() {
|
||||
a.Reload()
|
||||
}
|
||||
|
||||
func (a *NowPlayingPage) doSetNewTrackOrder(op sharedutil.TrackReorderOp) {
|
||||
// Since the tracklist view may be sorted in a different order than the
|
||||
// actual running order, we need to get the IDs of the selected tracks
|
||||
// from the tracklist and convert them to indices in the *original* run order
|
||||
ids := a.tracklist.SelectedTrackIDs()
|
||||
idxs := make([]int, 0, len(ids))
|
||||
for i, tr := range a.queue {
|
||||
if sharedutil.SliceContains(ids, tr.ID) {
|
||||
idxs = append(idxs, i)
|
||||
}
|
||||
}
|
||||
newTracks := sharedutil.ReorderTracks(a.queue, idxs, op)
|
||||
a.pm.UpdatePlayQueue(newTracks)
|
||||
|
||||
// force-switch back to unsorted view to show new track order
|
||||
a.tracklist.SetSorting(widgets.TracklistSort{})
|
||||
a.tracklist.SetTracks(newTracks)
|
||||
a.tracklist.UnselectAll()
|
||||
}
|
||||
|
||||
// does not make calls to server - can safely be run in UI callbacks
|
||||
func (a *NowPlayingPage) load(highlightedTrackID string) {
|
||||
a.queue = a.pm.GetPlayQueue()
|
||||
|
||||
@@ -86,18 +86,13 @@ func newPlaylistPage(
|
||||
a.tracklist.OnVisibleColumnsChanged = func(cols []string) {
|
||||
conf.TracklistColumns = cols
|
||||
}
|
||||
reorderMenu := fyne.NewMenuItem("Reorder tracks", nil)
|
||||
reorderMenu.ChildMenu = fyne.NewMenu("", []*fyne.MenuItem{
|
||||
fyne.NewMenuItem("Move to top", a.onMoveSelectedToTop),
|
||||
fyne.NewMenuItem("Move up", a.onMoveSelectedUp),
|
||||
fyne.NewMenuItem("Move down", a.onMoveSelectedDown),
|
||||
fyne.NewMenuItem("Move to bottom", a.onMoveSelectedToBottom),
|
||||
}...)
|
||||
_, canRate := a.sm.Server.(mediaprovider.SupportsRating)
|
||||
a.tracklist.Options = widgets.TracklistOptions{
|
||||
DisableRating: !canRate,
|
||||
AuxiliaryMenuItems: []*fyne.MenuItem{reorderMenu,
|
||||
fyne.NewMenuItem("Remove from playlist", a.onRemoveSelectedFromPlaylist)},
|
||||
AuxiliaryMenuItems: []*fyne.MenuItem{
|
||||
util.NewReorderTracksSubmenu(a.doSetNewTrackOrder),
|
||||
fyne.NewMenuItem("Remove from playlist", a.onRemoveSelectedFromPlaylist),
|
||||
},
|
||||
}
|
||||
// connect tracklist actions
|
||||
a.contr.ConnectTracklistActions(a.tracklist)
|
||||
@@ -171,22 +166,6 @@ func renumberTracks(tracks []*mediaprovider.Track) {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *PlaylistPage) onMoveSelectedToTop() {
|
||||
a.doSetNewTrackOrder(sharedutil.MoveToTop)
|
||||
}
|
||||
|
||||
func (a *PlaylistPage) onMoveSelectedUp() {
|
||||
a.doSetNewTrackOrder(sharedutil.MoveUp)
|
||||
}
|
||||
|
||||
func (a *PlaylistPage) onMoveSelectedDown() {
|
||||
a.doSetNewTrackOrder(sharedutil.MoveDown)
|
||||
}
|
||||
|
||||
func (a *PlaylistPage) onMoveSelectedToBottom() {
|
||||
a.doSetNewTrackOrder(sharedutil.MoveToBottom)
|
||||
}
|
||||
|
||||
func (a *PlaylistPage) doSetNewTrackOrder(op sharedutil.TrackReorderOp) {
|
||||
// Since the tracklist view may be sorted in a different order than the
|
||||
// actual running order, we need to get the IDs of the selected tracks
|
||||
|
||||
Reference in New Issue
Block a user