@@ -39,6 +39,12 @@ PlaylistFeature::PlaylistFeature(Library* pLibrary, UserSettingsPointer pConfig)
39
39
this ,
40
40
&PlaylistFeature::slotShufflePlaylist);
41
41
42
+ m_pOrderByCurrentPosAction = make_parented<QAction>(tr (" Adopt current order" ), this );
43
+ connect (m_pOrderByCurrentPosAction,
44
+ &QAction::triggered,
45
+ this ,
46
+ &PlaylistFeature::slotOrderTracksByCurrentPosition);
47
+
42
48
m_pUnlockPlaylistsAction =
43
49
make_parented<QAction>(tr (" Unlock all playlists" ), this );
44
50
connect (m_pUnlockPlaylistsAction,
@@ -81,6 +87,8 @@ void PlaylistFeature::onRightClickChild(
81
87
int playlistId = playlistIdFromIndex (index);
82
88
83
89
bool locked = m_playlistDao.isPlaylistLocked (playlistId);
90
+ m_pShufflePlaylistAction->setEnabled (!locked);
91
+ m_pOrderByCurrentPosAction->setEnabled (!locked && isChildIndexSelectedInSidebar (index));
84
92
m_pDeletePlaylistAction->setEnabled (!locked);
85
93
m_pRenamePlaylistAction->setEnabled (!locked);
86
94
@@ -92,6 +100,7 @@ void PlaylistFeature::onRightClickChild(
92
100
// TODO If playlist is selected and has more than one track selected
93
101
// show "Shuffle selected tracks", else show "Shuffle playlist"?
94
102
menu.addAction (m_pShufflePlaylistAction);
103
+ menu.addAction (m_pOrderByCurrentPosAction);
95
104
menu.addSeparator ();
96
105
menu.addAction (m_pRenamePlaylistAction);
97
106
menu.addAction (m_pDuplicatePlaylistAction);
@@ -228,17 +237,17 @@ void PlaylistFeature::slotShufflePlaylist() {
228
237
229
238
// Shuffle all tracks
230
239
// If the playlist is loaded/visible shuffle only selected tracks
231
- QModelIndexList selection;
232
240
if (isChildIndexSelectedInSidebar (m_lastRightClickedIndex) &&
233
241
m_pPlaylistTableModel->getPlaylist () == playlistId) {
242
+ QModelIndexList selection;
234
243
if (m_pLibraryWidget) {
235
244
WTrackTableView* view = dynamic_cast <WTrackTableView*>(
236
245
m_pLibraryWidget->getActiveView ());
237
246
if (view != nullptr ) {
238
247
selection = view->selectionModel ()->selectedIndexes ();
239
248
}
240
249
}
241
- m_pPlaylistTableModel->shuffleTracks (selection, QModelIndex () );
250
+ m_pPlaylistTableModel->shuffleTracks (selection);
242
251
} else {
243
252
// Create a temp model so we don't need to select the playlist
244
253
// in the persistent model in order to shuffle it
@@ -253,8 +262,27 @@ void PlaylistFeature::slotShufflePlaylist() {
253
262
Qt::AscendingOrder);
254
263
pPlaylistTableModel->select ();
255
264
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 ;
257
284
}
285
+ m_pPlaylistTableModel->orderTracksByCurrPos ();
258
286
}
259
287
260
288
void PlaylistFeature::slotUnlockAllPlaylists () {
0 commit comments