add remove from playlist support

This commit is contained in:
Drew Weymouth
2023-02-10 17:17:42 -08:00
parent 12cc315e12
commit dca82b8fee
2 changed files with 18 additions and 0 deletions
+8
View File
@@ -50,6 +50,9 @@ func NewPlaylistPage(
a.header = NewPlaylistPageHeader(a)
a.tracklist = widgets.NewTracklist(nil)
a.tracklist.AutoNumber = true
a.tracklist.AuxiliaryMenuItems = []*fyne.MenuItem{
fyne.NewMenuItem("Remove from playlist", a.onRemoveSelectedFromPlaylist),
}
// connect tracklist actions
a.tracklist.OnPlayTrackAt = a.onPlayTrackAt
a.tracklist.OnAddToQueue = func(tracks []*subsonic.Child) { a.pm.LoadTracks(tracks, true) }
@@ -114,6 +117,11 @@ func (a *PlaylistPage) loadAsync() {
}()
}
func (a *PlaylistPage) onRemoveSelectedFromPlaylist() {
a.sm.Server.UpdatePlaylistTracks(a.playlistID, nil, a.tracklist.SelectedTrackIndexes())
go a.Reload()
}
type PlaylistPageHeader struct {
widget.BaseWidget
+10
View File
@@ -112,6 +112,8 @@ type Tracklist struct {
Tracks []*subsonic.Child
AutoNumber bool
// must be set before the context menu is shown for the first time
AuxiliaryMenuItems []*fyne.MenuItem
// user action callbacks
OnPlayTrackAt func(int)
@@ -219,6 +221,10 @@ func (t *Tracklist) onShowContextMenu(e *fyne.PointEvent, trackIdx int) {
}
}),
)
if len(t.AuxiliaryMenuItems) > 0 {
t.ctxMenu.Items = append(t.ctxMenu.Items, fyne.NewMenuItemSeparator())
t.ctxMenu.Items = append(t.ctxMenu.Items, t.AuxiliaryMenuItems...)
}
}
widget.ShowPopUpMenuAtPosition(t.ctxMenu, fyne.CurrentApp().Driver().CanvasForObject(t), e.AbsolutePosition)
}
@@ -240,3 +246,7 @@ func (t *Tracklist) selectedTrackIDs() []string {
}
return tracks
}
func (t *Tracklist) SelectedTrackIndexes() []int {
return t.selectionMgr.GetSelection()
}