diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-01-04 15:17:48 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-01-04 15:17:48 +0000 |
commit | 1ff1b7dd89dfbea772964f347dd43755b5d7d738 (patch) | |
tree | dafd7bf91368077fe07ff49f259b03c386260e15 /Source/SPQueryFavoriteManager.m | |
parent | 313c5bc247548319dc1f93c9ece04ea4326d37e8 (diff) | |
download | sequelpro-1ff1b7dd89dfbea772964f347dd43755b5d7d738.tar.gz sequelpro-1ff1b7dd89dfbea772964f347dd43755b5d7d738.tar.bz2 sequelpro-1ff1b7dd89dfbea772964f347dd43755b5d7d738.zip |
• replaced the (10.4) deprecated [NSTableView tableView:writeRows:toPasteboard:] method by [NSTableView tableView:writeRowsWithIndexes:toPasteboard:]
• some code cosmetics
Diffstat (limited to 'Source/SPQueryFavoriteManager.m')
-rw-r--r-- | Source/SPQueryFavoriteManager.m | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/Source/SPQueryFavoriteManager.m b/Source/SPQueryFavoriteManager.m index db70e8f5..d03581a6 100644 --- a/Source/SPQueryFavoriteManager.m +++ b/Source/SPQueryFavoriteManager.m @@ -564,33 +564,27 @@ /** * Return whether or not the supplied rows can be written. */ -- (BOOL)tableView:(NSTableView *)tableView writeRows:(NSArray *)rows toPasteboard:(NSPasteboard *)pboard +- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rows toPasteboard:(NSPasteboard*)pboard { - // Up to now only one row can be dragged - // if ([rows count] == 1) { + NSArray *pboardTypes = [NSArray arrayWithObject:SPFavoritesPasteboardDragType]; + NSInteger originalRow = [rows firstIndex]; - NSArray *pboardTypes = [NSArray arrayWithObject:SPFavoritesPasteboardDragType]; - NSInteger originalRow = [[rows objectAtIndex:0] intValue]; + if(originalRow < 1) return NO; - if(originalRow < 1) return NO; + // Do not drag headers + if([[favorites objectAtIndex:originalRow] objectForKey:@"headerOfFileURL"]) return NO; - // Do not drag headers - if([[favorites objectAtIndex:originalRow] objectForKey:@"headerOfFileURL"]) return NO; + [pboard declareTypes:pboardTypes owner:nil]; - [pboard declareTypes:pboardTypes owner:nil]; + NSMutableData *indexdata = [[[NSMutableData alloc] init] autorelease]; + NSKeyedArchiver *archiver = [[[NSKeyedArchiver alloc] initForWritingWithMutableData:indexdata] autorelease]; + [archiver encodeObject:rows forKey:@"indexdata"]; + [archiver finishEncoding]; + [pboard setData:indexdata forType:SPFavoritesPasteboardDragType]; - NSMutableData *indexdata = [[[NSMutableData alloc] init] autorelease]; - NSKeyedArchiver *archiver = [[[NSKeyedArchiver alloc] initForWritingWithMutableData:indexdata] autorelease]; - [archiver encodeObject:rows forKey:@"indexdata"]; - [archiver finishEncoding]; - [pboard setData:indexdata forType:SPFavoritesPasteboardDragType]; - - return YES; - - // } + return YES; - // return NO; } /** @@ -621,9 +615,17 @@ if(row < 1) return NO; NSKeyedUnarchiver *unarchiver = [[[NSKeyedUnarchiver alloc] initForReadingWithData:[[info draggingPasteboard] dataForType:SPFavoritesPasteboardDragType]] autorelease]; - NSArray *draggedRows = [NSArray arrayWithArray:(NSArray *)[unarchiver decodeObjectForKey:@"indexdata"]]; + NSIndexSet *draggedIndexes = [[NSIndexSet alloc] initWithIndexSet:(NSIndexSet *)[unarchiver decodeObjectForKey:@"indexdata"]]; [unarchiver finishDecoding]; + // TODO: still rely on a NSArray but in the future rewrite it to use the NSIndexSet directly + NSMutableArray *draggedRows = [[NSMutableArray alloc] initWithCapacity:1]; + NSUInteger rowIndex = [draggedIndexes firstIndex]; + while ( rowIndex != NSNotFound ) { + [draggedRows addObject:[NSNumber numberWithInt:rowIndex]]; + rowIndex = [draggedIndexes indexGreaterThanIndex: rowIndex]; + } + NSInteger destinationRow = row; NSInteger offset = 0; @@ -655,6 +657,8 @@ [favoritesTableView reloadData]; [favoritesArrayController rearrangeObjects]; + [draggedIndexes release]; + [draggedRows release]; return YES; } |