Fix #315: Pre-select most recent playlist in "Add to playlist" dialog
This commit is contained in:
@@ -42,6 +42,7 @@ type AppConfig struct {
|
||||
AllowMultiInstance bool
|
||||
MaxImageCacheSizeMB int
|
||||
SavePlayQueue bool
|
||||
DefaultPlaylistID string
|
||||
|
||||
// Experimental - may be removed in future
|
||||
FontNormalTTF string
|
||||
|
||||
@@ -272,12 +272,17 @@ func (m *Controller) DoAddTracksToPlaylistWorkflow(trackIDs []string) {
|
||||
log.Printf("error getting user-owned playlists: %s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
selectedIdx := -1
|
||||
plNames := make([]string, 0, len(pls))
|
||||
for _, pl := range pls {
|
||||
for i, pl := range pls {
|
||||
plNames = append(plNames, pl.Name)
|
||||
if defId := m.App.Config.Application.DefaultPlaylistID; defId != "" && pl.ID == defId {
|
||||
selectedIdx = i
|
||||
}
|
||||
}
|
||||
|
||||
dlg := dialogs.NewAddToPlaylistDialog("Add to Playlist", plNames)
|
||||
dlg := dialogs.NewAddToPlaylistDialog("Add to Playlist", plNames, selectedIdx)
|
||||
pop := widget.NewModalPopUp(dlg, m.MainWindow.Canvas())
|
||||
m.ClosePopUpOnEscape(pop)
|
||||
dlg.OnCanceled = pop.Hide
|
||||
@@ -287,8 +292,10 @@ func (m *Controller) DoAddTracksToPlaylistWorkflow(trackIDs []string) {
|
||||
if playlistChoice < 0 {
|
||||
go m.App.ServerManager.Server.CreatePlaylist(newPlaylistName, trackIDs)
|
||||
} else {
|
||||
playlist := pls[playlistChoice]
|
||||
m.App.Config.Application.DefaultPlaylistID = playlist.ID
|
||||
go m.App.ServerManager.Server.AddPlaylistTracks(
|
||||
pls[playlistChoice].ID, trackIDs)
|
||||
playlist.ID, trackIDs)
|
||||
}
|
||||
}
|
||||
m.haveModal = true
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package dialogs
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
@@ -23,7 +25,7 @@ type AddToPlaylistDialog struct {
|
||||
|
||||
var _ fyne.Widget = (*AddToPlaylistDialog)(nil)
|
||||
|
||||
func NewAddToPlaylistDialog(title string, existingPlaylistNames []string) *AddToPlaylistDialog {
|
||||
func NewAddToPlaylistDialog(title string, existingPlaylistNames []string, selectedIdx int) *AddToPlaylistDialog {
|
||||
a := &AddToPlaylistDialog{}
|
||||
a.ExtendBaseWidget(a)
|
||||
|
||||
@@ -35,6 +37,14 @@ func NewAddToPlaylistDialog(title string, existingPlaylistNames []string) *AddTo
|
||||
a.onSelectionChanged()
|
||||
})
|
||||
a.playlistSelect.PlaceHolder = "(Choose playlist)"
|
||||
if selectedIdx >= 0 {
|
||||
// calling SetSelectedIndex before showing the Select crashes...
|
||||
go func() {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
// add 1 to selectedIdx to account for "(Choose playlist)" entry
|
||||
a.playlistSelect.SetSelectedIndex(selectedIdx + 1)
|
||||
}()
|
||||
}
|
||||
a.newPlaylistName = widget.NewEntry()
|
||||
a.newPlaylistName.Hidden = true
|
||||
a.newPlaylistName.OnChanged = func(text string) {
|
||||
|
||||
Reference in New Issue
Block a user