@@ -276,12 +276,25 @@ void CrateFeature::updateTreeItemForCrateSummary(
276276 pTreeItem->setUrl (CrateURLs::toUrl (crateSummary.getId ()));
277277}
278278
279+ bool CrateFeature::dropAccept (const QList<QUrl>& urls, QObject* pSource) {
280+ Q_UNUSED (pSource);
281+ QList<CrateId> crateIds = CrateURLs::parseCrateUrls (urls);
282+ if (crateIds.isEmpty ()) {
283+ return false ;
284+ }
285+ return moveToParent (CrateId (), crateIds);
286+ }
287+
279288bool CrateFeature::dropAcceptChild (
280289 const QModelIndex& index, const QList<QUrl>& urls, QObject* pSource) {
281- CrateId crateId (crateIdFromIndex (index));
282- VERIFY_OR_DEBUG_ASSERT (crateId .isValid ()) {
290+ CrateId targetCrateId (crateIdFromIndex (index));
291+ VERIFY_OR_DEBUG_ASSERT (targetCrateId .isValid ()) {
283292 return false ;
284293 }
294+
295+ bool movedTracks = false ;
296+ bool movedCrates = false ;
297+
285298 // If a track is dropped onto a crate's name, but the track isn't in the
286299 // library, then add the track to the library before adding it to the
287300 // playlist.
@@ -292,12 +305,22 @@ bool CrateFeature::dropAcceptChild(
292305 DragAndDropHelper::supportedTracksFromUrls (urls, false , true );
293306 const QList<TrackId> trackIds =
294307 m_pLibrary->trackCollectionManager ()->resolveTrackIds (fileInfos, pSource);
295- if (trackIds.isEmpty ()) {
296- return false ;
308+ if (!trackIds.isEmpty ()) {
309+ m_pTrackCollection->addCrateTracks (targetCrateId, trackIds);
310+ movedTracks = true ;
297311 }
298312
299- m_pTrackCollection->addCrateTracks (crateId, trackIds);
300- return true ;
313+ const QList<CrateId> crateIds = CrateURLs::parseCrateUrls (urls);
314+ if (!crateIds.isEmpty ()) {
315+ moveToParent (targetCrateId, crateIds);
316+ movedCrates = true ;
317+ }
318+
319+ return movedTracks || movedCrates;
320+ }
321+
322+ bool CrateFeature::dragMoveAccept (const QList<QUrl>& urls) {
323+ return !CrateURLs::parseCrateUrls (urls).isEmpty ();
301324}
302325
303326bool CrateFeature::dragMoveAcceptChild (const QModelIndex& index, const QList<QUrl>& urls) {
@@ -310,7 +333,8 @@ bool CrateFeature::dragMoveAcceptChild(const QModelIndex& index, const QList<QUr
310333 crate.isLocked ()) {
311334 return false ;
312335 }
313- return DragAndDropHelper::urlsContainSupportedTrackFiles (urls, true );
336+ return DragAndDropHelper::urlsContainSupportedTrackFiles (urls, true ) ||
337+ !CrateURLs::parseCrateUrls (urls).isEmpty ();
314338}
315339
316340void CrateFeature::bindLibraryWidget (
@@ -490,6 +514,32 @@ void CrateFeature::createNewCrate(CrateId parentId, bool selectAfterCreation) {
490514 }
491515}
492516
517+ bool CrateFeature::moveToParent (CrateId destinationId, const QList<CrateId>& cratesToMove) {
518+ // Note: An "invalid"/NULL destination is not actually invalid
519+ // for this function, but instead represents the root folder.
520+ bool success = false ;
521+ for (CrateId crateToMoveId : cratesToMove) {
522+ success |= moveToParent (destinationId, crateToMoveId, false );
523+ }
524+ return success;
525+ }
526+
527+ bool CrateFeature::moveToParent (CrateId destinationId, CrateId crateToMoveId, bool selectAfterMove) {
528+ // Note: An "invalid"/NULL destination is not actually invalid
529+ // for this function, but instead represents the root folder.
530+ Crate crate;
531+ if (m_pTrackCollection->crates ().readCrateById (crateToMoveId, &crate)) {
532+ crate.setParentId (destinationId);
533+ const bool success = m_pTrackCollection->updateCrate (crate);
534+ if (success && selectAfterMove) {
535+ // Scroll to new location of the selected crate/folder
536+ m_pSidebarWidget->selectChildIndex (indexFromCrateId (crateToMoveId), false );
537+ }
538+ return success;
539+ }
540+ return false ;
541+ }
542+
493543void CrateFeature::deleteItem (const QModelIndex& index) {
494544 m_lastRightClickedIndex = index;
495545 slotDeleteCrate ();
0 commit comments