@@ -39,6 +39,12 @@ PlaylistFeature::PlaylistFeature(Library* pLibrary, UserSettingsPointer pConfig)
3939 this ,
4040 &PlaylistFeature::slotShufflePlaylist);
4141
42+ m_pOrderByCurrentPosAction = make_parented<QAction>(tr (" Adopt current order" ), this );
43+ connect (m_pOrderByCurrentPosAction,
44+ &QAction::triggered,
45+ this ,
46+ &PlaylistFeature::slotOrderTracksByCurrentPosition);
47+
4248 m_pUnlockPlaylistsAction =
4349 make_parented<QAction>(tr (" Unlock all playlists" ), this );
4450 connect (m_pUnlockPlaylistsAction,
@@ -81,6 +87,8 @@ void PlaylistFeature::onRightClickChild(
8187 int playlistId = playlistIdFromIndex (index);
8288
8389 bool locked = m_playlistDao.isPlaylistLocked (playlistId);
90+ m_pShufflePlaylistAction->setEnabled (!locked);
91+ m_pOrderByCurrentPosAction->setEnabled (!locked && isChildIndexSelectedInSidebar (index));
8492 m_pDeletePlaylistAction->setEnabled (!locked);
8593 m_pRenamePlaylistAction->setEnabled (!locked);
8694
@@ -92,6 +100,7 @@ void PlaylistFeature::onRightClickChild(
92100 // TODO If playlist is selected and has more than one track selected
93101 // show "Shuffle selected tracks", else show "Shuffle playlist"?
94102 menu.addAction (m_pShufflePlaylistAction);
103+ menu.addAction (m_pOrderByCurrentPosAction);
95104 menu.addSeparator ();
96105 menu.addAction (m_pRenamePlaylistAction);
97106 menu.addAction (m_pDuplicatePlaylistAction);
@@ -228,17 +237,17 @@ void PlaylistFeature::slotShufflePlaylist() {
228237
229238 // Shuffle all tracks
230239 // If the playlist is loaded/visible shuffle only selected tracks
231- QModelIndexList selection;
232240 if (isChildIndexSelectedInSidebar (m_lastRightClickedIndex) &&
233241 m_pPlaylistTableModel->getPlaylist () == playlistId) {
242+ QModelIndexList selection;
234243 if (m_pLibraryWidget) {
235244 WTrackTableView* view = dynamic_cast <WTrackTableView*>(
236245 m_pLibraryWidget->getActiveView ());
237246 if (view != nullptr ) {
238247 selection = view->selectionModel ()->selectedIndexes ();
239248 }
240249 }
241- m_pPlaylistTableModel->shuffleTracks (selection, QModelIndex () );
250+ m_pPlaylistTableModel->shuffleTracks (selection);
242251 } else {
243252 // Create a temp model so we don't need to select the playlist
244253 // in the persistent model in order to shuffle it
@@ -253,8 +262,27 @@ void PlaylistFeature::slotShufflePlaylist() {
253262 Qt::AscendingOrder);
254263 pPlaylistTableModel->select ();
255264
256- pPlaylistTableModel->shuffleTracks (selection, QModelIndex ());
265+ pPlaylistTableModel->shuffleTracks ();
266+ }
267+ }
268+
269+ void PlaylistFeature::slotOrderTracksByCurrentPosition () {
270+ int playlistId = playlistIdFromIndex (m_lastRightClickedIndex);
271+ if (playlistId == kInvalidPlaylistId ) {
272+ return ;
273+ }
274+
275+ if (m_playlistDao.isPlaylistLocked (playlistId)) {
276+ qDebug () << " Can't adopt current sorting for locked playlist" << playlistId
277+ << m_playlistDao.getPlaylistName (playlistId);
278+ return ;
279+ }
280+ // Note(ronso0) I propose to proceed only if the playlist is selected and loaded.
281+ // without playlist content visible we don't have a preview.
282+ if (!isChildIndexSelectedInSidebar (m_lastRightClickedIndex)) {
283+ return ;
257284 }
285+ m_pPlaylistTableModel->orderTracksByCurrPos ();
258286}
259287
260288void PlaylistFeature::slotUnlockAllPlaylists () {
0 commit comments