Playlist View: Support undoing and redoing Drag and Drop operations within the playlist

CQTexperiment
Christopher Snowhill 2022-01-20 21:48:23 -08:00
parent c07b268288
commit 0f90dd3b3e
3 changed files with 46 additions and 0 deletions

View File

@ -28,5 +28,8 @@ extern NSString *iTunesDropType;
// utility methods // utility methods
-(void)moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet *)indexSet -(void)moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet *)indexSet
toIndex:(NSUInteger)insertIndex; toIndex:(NSUInteger)insertIndex;
// This is needed to undo the above
- (void)moveObjectsFromIndex:(NSUInteger)fromIndex
toArrangedObjectIndexes:(NSIndexSet *)indexSet;
@end @end

View File

@ -119,5 +119,28 @@ NSString *iTunesDropType = @"com.apple.tv.metadata";
} }
} }
- (void)moveObjectsFromIndex:(NSUInteger)fromIndex
toArrangedObjectIndexes:(NSIndexSet *)indexSet {
NSArray *objects = [self arrangedObjects];
NSUInteger index = [indexSet firstIndex];
NSUInteger itemIndex = 0;
id object;
NSArray *itemsSet = [objects objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(fromIndex, [indexSet count])]];
for (NSUInteger i = 0; i < [itemsSet count]; i++) {
[self removeObjectAtArrangedObjectIndex:fromIndex];
}
while (NSNotFound != index) {
object = itemsSet[itemIndex++];
[self insertObject:object atArrangedObjectIndex:index];
index = [indexSet indexGreaterThanIndex:index];
}
}
@end @end

View File

@ -363,8 +363,28 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
if ([self shuffle] != ShuffleOff) [self resetShuffleList]; if ([self shuffle] != ShuffleOff) [self resetShuffleList];
} }
// This action is only needed to revert the one that follows it
- (void)moveObjectsFromIndex:(NSUInteger)fromIndex
toArrangedObjectIndexes:(NSIndexSet *)indexSet {
[[[self undoManager] prepareWithInvocationTarget:self]
moveObjectsInArrangedObjectsFromIndexes:indexSet toIndex:fromIndex];
NSString *actionName =
[NSString stringWithFormat:@"Reordering %lu entries", (unsigned long) [indexSet count]];
[[self undoManager] setActionName:actionName];
[super moveObjectsFromIndex:fromIndex toArrangedObjectIndexes:indexSet];
[playbackController playlistDidChange:self];
}
- (void)moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet *)indexSet - (void)moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet *)indexSet
toIndex:(NSUInteger)insertIndex { toIndex:(NSUInteger)insertIndex {
[[[self undoManager] prepareWithInvocationTarget:self]
moveObjectsFromIndex:insertIndex toArrangedObjectIndexes:indexSet];
NSString *actionName =
[NSString stringWithFormat:@"Reordering %lu entries", (unsigned long) [indexSet count]];
[[self undoManager] setActionName:actionName];
[super moveObjectsInArrangedObjectsFromIndexes:indexSet toIndex:insertIndex]; [super moveObjectsInArrangedObjectsFromIndexes:indexSet toIndex:insertIndex];
#if 0 // syncPlaylistEntries is already called for rearrangement #if 0 // syncPlaylistEntries is already called for rearrangement