Fixed playlist moving.
This commit is contained in:
parent
c6640cc3f5
commit
f451cd1712
4 changed files with 69 additions and 87 deletions
|
@ -11,16 +11,12 @@ extern NSString *iTunesDropType;
|
||||||
}
|
}
|
||||||
|
|
||||||
// table view drag and drop support
|
// table view drag and drop support
|
||||||
- (BOOL)tableView:(NSTableView *)tv writeRows:(NSArray*)rows toPasteboard:(NSPasteboard*)pboard;
|
- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard;
|
||||||
- (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)op;
|
- (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)op;
|
||||||
- (BOOL)tableView:(NSTableView*)tv acceptDrop:(id <NSDraggingInfo>)info row:(int)row dropOperation:(NSTableViewDropOperation)op;
|
- (BOOL)tableView:(NSTableView*)tv acceptDrop:(id <NSDraggingInfo>)info row:(int)row dropOperation:(NSTableViewDropOperation)op;
|
||||||
|
|
||||||
|
|
||||||
// utility methods
|
// utility methods
|
||||||
-(void)moveObjectsFromArrangedObjectIndexes:(NSArray *) sources toIndexes:(NSArray *)destinations;
|
|
||||||
|
|
||||||
-(void)moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet*)indexSet toIndex:(unsigned int)insertIndex;
|
-(void)moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet*)indexSet toIndex:(unsigned int)insertIndex;
|
||||||
|
|
||||||
- (NSIndexSet *)indexSetFromRows:(NSArray *)rows;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -16,15 +16,14 @@ NSString *iTunesDropType = @"CorePasteboardFlavorType 0x6974756E";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (BOOL)tableView:(NSTableView *)tv
|
- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard
|
||||||
writeRows:(NSArray*)rows
|
|
||||||
toPasteboard:(NSPasteboard*)pboard
|
|
||||||
{
|
{
|
||||||
NSData *data;
|
NSLog(@"INDEX SET ON DRAG: %@", rowIndexes);
|
||||||
data = [NSKeyedArchiver archivedDataWithRootObject:rows];
|
|
||||||
|
NSData *data = [NSArchiver archivedDataWithRootObject:rowIndexes];
|
||||||
|
|
||||||
[pboard declareTypes: [NSArray arrayWithObjects:MovedRowsType, nil] owner:self];
|
[pboard declareTypes: [NSArray arrayWithObjects:MovedRowsType, nil] owner:self];
|
||||||
[pboard setData: data forType: MovedRowsType];
|
[pboard setData:data forType: MovedRowsType];
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
@ -61,58 +60,33 @@ NSString *iTunesDropType = @"CorePasteboardFlavorType 0x6974756E";
|
||||||
// if drag source is self, it's a move
|
// if drag source is self, it's a move
|
||||||
if ([info draggingSource] == tableView)
|
if ([info draggingSource] == tableView)
|
||||||
{
|
{
|
||||||
NSArray *rows = [NSKeyedUnarchiver unarchiveObjectWithData:[[info draggingPasteboard] dataForType: MovedRowsType]];
|
NSIndexSet *indexSet = [NSUnarchiver unarchiveObjectWithData:[[info draggingPasteboard] dataForType:MovedRowsType]];
|
||||||
|
if (indexSet)
|
||||||
|
{
|
||||||
|
NSLog(@"INDEX SET ON DROP: %@", indexSet);
|
||||||
|
NSArray *selected = [[self arrangedObjects] objectsAtIndexes:indexSet];
|
||||||
|
[self moveObjectsInArrangedObjectsFromIndexes:indexSet toIndex:row];
|
||||||
|
|
||||||
NSIndexSet *indexSet = [self indexSetFromRows:rows];
|
[self setSelectedObjects:selected];
|
||||||
|
|
||||||
[self moveObjectsInArrangedObjectsFromIndexes:indexSet toIndex:row];
|
return YES;
|
||||||
|
}
|
||||||
// set selected rows to those that were just moved
|
|
||||||
// Need to work out what moved where to determine proper selection...
|
|
||||||
|
|
||||||
return YES;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
-(void)moveObjectsFromArrangedObjectIndexes:(NSArray *) sources toIndexes:(NSArray *)destinations;
|
-(void) moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet*)indexSet
|
||||||
{
|
|
||||||
//We expect [sources count] == [destinations count].
|
|
||||||
NSMutableArray *selectedObjects = [[NSMutableArray alloc] init];
|
|
||||||
|
|
||||||
NSUInteger i = 0;
|
|
||||||
for (i = 0; i < [sources count]; i++) {
|
|
||||||
NSUInteger source = [[sources objectAtIndex:i] unsignedIntegerValue];
|
|
||||||
NSUInteger dest = [[destinations objectAtIndex:i] unsignedIntegerValue];
|
|
||||||
|
|
||||||
id object = [[self arrangedObjects] objectAtIndex:source];
|
|
||||||
|
|
||||||
[object retain];
|
|
||||||
|
|
||||||
[self removeObjectAtArrangedObjectIndex:source];
|
|
||||||
[self insertObject:object atArrangedObjectIndex:dest];
|
|
||||||
|
|
||||||
[selectedObjects addObject: object];
|
|
||||||
|
|
||||||
[object release];
|
|
||||||
}
|
|
||||||
|
|
||||||
[self setSelectedObjects:selectedObjects];
|
|
||||||
|
|
||||||
[selectedObjects release];
|
|
||||||
}
|
|
||||||
|
|
||||||
-(void)moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet*)indexSet
|
|
||||||
toIndex:(unsigned int)insertIndex
|
toIndex:(unsigned int)insertIndex
|
||||||
{
|
{
|
||||||
int index = [indexSet lastIndex];
|
|
||||||
int aboveInsertIndexCount = 0;
|
|
||||||
int removeIndex;
|
|
||||||
|
|
||||||
NSMutableArray *sources = [NSMutableArray array];
|
NSArray *objects = [self arrangedObjects];
|
||||||
NSMutableArray *destinations = [NSMutableArray array];
|
int index = [indexSet lastIndex];
|
||||||
|
|
||||||
|
int aboveInsertIndexCount = 0;
|
||||||
|
id object;
|
||||||
|
int removeIndex;
|
||||||
|
|
||||||
while (NSNotFound != index)
|
while (NSNotFound != index)
|
||||||
{
|
{
|
||||||
|
@ -126,24 +100,16 @@ NSString *iTunesDropType = @"CorePasteboardFlavorType 0x6974756E";
|
||||||
insertIndex -= 1;
|
insertIndex -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
[sources addObject:[NSNumber numberWithUnsignedInteger:removeIndex]];
|
object = [objects objectAtIndex:removeIndex];
|
||||||
[destinations addObject: [NSNumber numberWithUnsignedInteger:insertIndex]];
|
|
||||||
|
[object retain];
|
||||||
|
[self removeObjectAtArrangedObjectIndex:removeIndex];
|
||||||
|
[self insertObject:object atArrangedObjectIndex:insertIndex];
|
||||||
|
[object release];
|
||||||
|
|
||||||
index = [indexSet indexLessThanIndex:index];
|
index = [indexSet indexLessThanIndex:index];
|
||||||
}
|
}
|
||||||
|
|
||||||
[self moveObjectsFromArrangedObjectIndexes:sources toIndexes:destinations];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSIndexSet *)indexSetFromRows:(NSArray *)rows
|
|
||||||
{
|
|
||||||
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
|
|
||||||
|
|
||||||
for (NSNumber *idx in rows)
|
|
||||||
{
|
|
||||||
[indexSet addIndex:[idx unsignedIntValue]];
|
|
||||||
}
|
|
||||||
return indexSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -84,25 +84,42 @@
|
||||||
return [[[self arrangedObjects] objectAtIndex:row] statusMessage];
|
return [[[self arrangedObjects] objectAtIndex:row] statusMessage];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)moveObjectsFromArrangedObjectIndexes:(NSArray *) sources toIndexes:(NSArray *)destinations
|
-(void)moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet*)indexSet
|
||||||
|
toIndex:(unsigned int)insertIndex
|
||||||
{
|
{
|
||||||
[super moveObjectsFromArrangedObjectIndexes:sources toIndexes:destinations];
|
[super moveObjectsInArrangedObjectsFromIndexes:indexSet toIndex:insertIndex];
|
||||||
|
|
||||||
NSUInteger firstIndex = (NSUInteger)-1;
|
NSUInteger lowerIndex = insertIndex;
|
||||||
NSUInteger i = 0;
|
NSUInteger index = insertIndex;
|
||||||
|
|
||||||
for (i = 0; i < [sources count]; i++) {
|
while (NSNotFound != lowerIndex) {
|
||||||
NSUInteger source = [[sources objectAtIndex:i] unsignedIntegerValue];
|
lowerIndex = [indexSet indexLessThanIndex:lowerIndex];
|
||||||
NSUInteger dest = [[destinations objectAtIndex:i] unsignedIntegerValue];
|
|
||||||
|
|
||||||
if (source < firstIndex)
|
if (lowerIndex != NSNotFound)
|
||||||
firstIndex = source;
|
index = lowerIndex;
|
||||||
|
|
||||||
if (dest < firstIndex)
|
|
||||||
firstIndex = dest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[self updateIndexesFromRow:firstIndex];
|
[self updateIndexesFromRow:index];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard
|
||||||
|
{
|
||||||
|
[super tableView:aTableView writeRowsWithIndexes:rowIndexes toPasteboard:pboard];
|
||||||
|
|
||||||
|
NSMutableArray *filenames = [NSMutableArray array];
|
||||||
|
NSInteger row;
|
||||||
|
for (row = [rowIndexes firstIndex];
|
||||||
|
row <= [rowIndexes lastIndex];
|
||||||
|
row = [rowIndexes indexGreaterThanIndex:row])
|
||||||
|
{
|
||||||
|
PlaylistEntry *song = [[self arrangedObjects] objectAtIndex:row];
|
||||||
|
[filenames addObject:[[song path] stringByExpandingTildeInPath]];
|
||||||
|
}
|
||||||
|
|
||||||
|
[pboard addTypes:[NSArray arrayWithObject:NSFilenamesPboardType] owner:self];
|
||||||
|
[pboard setPropertyList:filenames forType:NSFilenamesPboardType];
|
||||||
|
|
||||||
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)tableView:(NSTableView*)tv
|
- (BOOL)tableView:(NSTableView*)tv
|
||||||
|
@ -110,14 +127,9 @@
|
||||||
row:(int)row
|
row:(int)row
|
||||||
dropOperation:(NSTableViewDropOperation)op
|
dropOperation:(NSTableViewDropOperation)op
|
||||||
{
|
{
|
||||||
[super tableView:tv acceptDrop:info row:row dropOperation:op];
|
//Check if DNDArrayController handles it.
|
||||||
|
if ([super tableView:tv acceptDrop:info row:row dropOperation:op])
|
||||||
if ([info draggingSource] == tableView)
|
|
||||||
{
|
|
||||||
//DNDArrayController handles moving...
|
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
|
||||||
|
|
||||||
if (row < 0)
|
if (row < 0)
|
||||||
row = 0;
|
row = 0;
|
||||||
|
|
|
@ -324,4 +324,12 @@
|
||||||
return [super validateUserInterfaceItem:anItem];
|
return [super validateUserInterfaceItem:anItem];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal
|
||||||
|
{
|
||||||
|
if (isLocal)
|
||||||
|
return NSDragOperationNone;
|
||||||
|
else
|
||||||
|
return NSDragOperationCopy;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Reference in a new issue