Playlist View: Support undoing and redoing Drag and Drop operations within the playlist
parent
c07b268288
commit
0f90dd3b3e
|
@ -28,5 +28,8 @@ extern NSString *iTunesDropType;
|
|||
// utility methods
|
||||
-(void)moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet *)indexSet
|
||||
toIndex:(NSUInteger)insertIndex;
|
||||
// This is needed to undo the above
|
||||
- (void)moveObjectsFromIndex:(NSUInteger)fromIndex
|
||||
toArrangedObjectIndexes:(NSIndexSet *)indexSet;
|
||||
|
||||
@end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -363,8 +363,28 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
|
|||
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
|
||||
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];
|
||||
|
||||
#if 0 // syncPlaylistEntries is already called for rearrangement
|
||||
|
|
Loading…
Reference in New Issue