enable drag and drop reordering

This commit is contained in:
Drew Weymouth
2024-06-22 17:10:26 -07:00
parent f5a4146e2b
commit 4545839e92
9 changed files with 79 additions and 160 deletions
+21 -15
View File
@@ -31,6 +31,7 @@ type PlayQueueListModel struct {
type PlayQueueList struct {
widget.BaseWidget
Reorderable bool
DisableRating bool
DisableSharing bool
@@ -46,7 +47,7 @@ type PlayQueueList struct {
OnDownload func(tracks []*mediaprovider.Track, downloadName string)
OnShare func(tracks []*mediaprovider.Track)
OnShowArtistPage func(artistID string)
OnReorderItems func(itemIDs []string, op sharedutil.TrackReorderOp)
OnReorderItems func(itemIDs []string, reorderTo int)
useNonQueueMenu bool
menu *widget.PopUpMenu // ctx menu for when only tracks are selected
@@ -102,6 +103,17 @@ func NewPlayQueueList(im *backend.ImageManager, useNonQueueMenu bool) *PlayQueue
tr.Update(model, itemID+1)
},
)
p.list.OnDragBegin = func(id int) {
if !p.items[id].Selected {
p.selectTrack(id)
p.list.Refresh()
}
}
p.list.OnDragEnd = func(dragged, insertPos int) {
if p.OnReorderItems != nil {
p.OnReorderItems(p.selectedItemIDs(), insertPos)
}
}
return p
}
@@ -149,7 +161,12 @@ func (p *PlayQueueList) UnselectAll() {
p.tracksMutex.RLock()
util.UnselectAllItems(p.items)
p.tracksMutex.RUnlock()
p.Refresh()
p.list.Refresh()
}
func (p *PlayQueueList) Refresh() {
p.list.EnableDragging = p.Reorderable
p.BaseWidget.Refresh()
}
func (p *PlayQueueList) lenTracks() int {
@@ -292,15 +309,9 @@ func (p *PlayQueueList) ensureTracksMenu() {
}
})
remove.Icon = theme.ContentRemoveIcon()
reorder := util.NewReorderTracksSubmenu(func(tro sharedutil.TrackReorderOp) {
if p.OnReorderItems != nil {
p.OnReorderItems(p.selectedItemIDs(), tro)
}
})
menuItems = append(menuItems,
fyne.NewMenuItemSeparator(),
remove,
reorder)
remove)
}
p.menu = widget.NewPopUpMenu(
@@ -319,13 +330,8 @@ func (p *PlayQueueList) ensureRadiosMenu() {
}
})
remove.Icon = theme.ContentRemoveIcon()
reorder := util.NewReorderTracksSubmenu(func(tro sharedutil.TrackReorderOp) {
if p.OnReorderItems != nil {
p.OnReorderItems(p.selectedItemIDs(), tro)
}
})
p.radiosMenu = widget.NewPopUpMenu(
fyne.NewMenu("", remove, reorder),
fyne.NewMenu("", remove),
fyne.CurrentApp().Driver().CanvasForObject(p),
)
}
+16
View File
@@ -33,6 +33,9 @@ type TracklistOptions struct {
// or to use the number from the track's metadata
AutoNumber bool
// Reorderable sets whether the tracklist supports drag-and-drop reordering.
Reorderable bool
// ShowDiscNumber sets whether to display the disc number as part of the '#' column,
// (with format %d.%02d). Only applies if AutoNumber==false.
ShowDiscNumber bool
@@ -74,6 +77,7 @@ type Tracklist struct {
OnDownload func(tracks []*mediaprovider.Track, downloadName string)
OnShare func(trackID string)
OnPlaySongRadio func(track *mediaprovider.Track)
OnReorderTracks func(trackIDs []string, insertPos int)
OnShowArtistPage func(artistID string)
OnShowAlbumPage func(albumID string)
@@ -182,6 +186,17 @@ func NewTracklist(tracks []*mediaprovider.Track, im *backend.ImageManager, useCo
t.OnTrackShown(itemID)
}
})
t.list.OnDragBegin = func(id int) {
if !t.tracks[id].Selected {
t.selectTrack(id)
t.list.Refresh()
}
}
t.list.OnDragEnd = func(dragged, insertPos int) {
if t.OnReorderTracks != nil {
t.OnReorderTracks(t.SelectedTrackIDs(), insertPos)
}
}
t.container = container.NewBorder(t.hdr, nil, nil, nil, t.list)
return t
}
@@ -371,6 +386,7 @@ func (t *Tracklist) CreateRenderer() fyne.WidgetRenderer {
}
func (t *Tracklist) Refresh() {
t.list.EnableDragging = t.Options.Reorderable
t.hdr.DisableSorting = t.Options.DisableSorting
t.BaseWidget.Refresh()
}