From 2441b2c439a3da072ea634aaaf1345d2c24b6158 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 7 Sep 2009 13:38:36 +0000 Subject: =?UTF-8?q?=E2=80=A2=C2=A0Query=20Favorite=20Manager=20-=20disable?= =?UTF-8?q?d=20sorting=20by=20clicking=20at=20table=20headers=20-=20added?= =?UTF-8?q?=20drag&drop=20support=20of=20multiple=20selected=20items?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPQueryFavoriteManager.m | 73 ++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 22 deletions(-) (limited to 'Source') diff --git a/Source/SPQueryFavoriteManager.m b/Source/SPQueryFavoriteManager.m index 545d0317..41276769 100644 --- a/Source/SPQueryFavoriteManager.m +++ b/Source/SPQueryFavoriteManager.m @@ -481,6 +481,15 @@ } } +/* + * Sorting by clicking at a column header inside groups + */ +- (void)tableView:(NSTableView*)tableView didClickTableColumn:(NSTableColumn *)tableColumn +{ + // TODO: Not yet implemented + return; +} + /* * favoriteProperties holds the data if a table row is a group header or not */ @@ -556,7 +565,7 @@ { // Up to now only one row can be dragged - if ([rows count] == 1) { + // if ([rows count] == 1) { NSArray *pboardTypes = [NSArray arrayWithObject:QUERY_FAVORITES_PB_DRAG_TYPE]; NSInteger originalRow = [[rows objectAtIndex:0] intValue]; @@ -567,13 +576,18 @@ if([[favorites objectAtIndex:originalRow] objectForKey:@"headerOfFileURL"]) return NO; [pboard declareTypes:pboardTypes owner:nil]; - [pboard setString:[[NSNumber numberWithInt:originalRow] stringValue] forType:QUERY_FAVORITES_PB_DRAG_TYPE]; + + NSMutableData *indexdata = [[[NSMutableData alloc] init] autorelease]; + NSKeyedArchiver *archiver = [[[NSKeyedArchiver alloc] initForWritingWithMutableData:indexdata] autorelease]; + [archiver encodeObject:rows forKey:@"indexdata"]; + [archiver finishEncoding]; + [pboard setData:indexdata forType:QUERY_FAVORITES_PB_DRAG_TYPE]; return YES; - } + // } - return NO; + // return NO; } /** @@ -585,9 +599,7 @@ if (([pboardTypes count] > 1) && (row != -1)) { if (([pboardTypes containsObject:QUERY_FAVORITES_PB_DRAG_TYPE]) && (operation == NSTableViewDropAbove)) { - NSInteger originalRow = [[[info draggingPasteboard] stringForType:QUERY_FAVORITES_PB_DRAG_TYPE] intValue]; - - if ((row != originalRow) && (row != (originalRow + 1)) && (row > 0)) { + if (row > 0) { return NSDragOperationMove; } } @@ -601,29 +613,46 @@ */ - (BOOL)tableView:(NSTableView *)tableView acceptDrop:(id )info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation -{ - NSInteger originalRow = [[[info draggingPasteboard] stringForType:QUERY_FAVORITES_PB_DRAG_TYPE] intValue]; +{ + + if(row < 1) return NO; + + NSKeyedUnarchiver *unarchiver = [[[NSKeyedUnarchiver alloc] initForReadingWithData:[[info draggingPasteboard] dataForType:QUERY_FAVORITES_PB_DRAG_TYPE]] autorelease]; + NSArray *draggedRows = [NSArray arrayWithArray:(NSArray *)[unarchiver decodeObjectForKey:@"indexdata"]]; + [unarchiver finishDecoding]; + NSInteger destinationRow = row; + NSInteger offset = 0; - if(destinationRow == originalRow || row < 1) return NO; - if(destinationRow > originalRow) destinationRow--; + NSUInteger i; - NSMutableDictionary *draggedRow = [NSMutableDictionary dictionaryWithDictionary:[favorites objectAtIndex:originalRow]]; + for(i=0; i<[draggedRows count]; i++) { - [favorites removeObjectAtIndex:originalRow]; - [favorites insertObject:draggedRow atIndex:destinationRow]; + NSInteger originalRow = [[draggedRows objectAtIndex:i] intValue]; - [favoritesTableView reloadData]; - [favoritesArrayController rearrangeObjects]; + if(originalRow < destinationRow) destinationRow--; + + originalRow += offset; + + // For safety reasons + if(originalRow > [favorites count]-1) originalRow = [favorites count] - 1; + + NSMutableDictionary *draggedRow = [NSMutableDictionary dictionaryWithDictionary:[favorites objectAtIndex:originalRow]]; + [favorites removeObjectAtIndex:originalRow]; + [favoritesTableView reloadData]; + + if(destinationRow+i >= [favorites count]) + [favorites addObject:draggedRow]; + else + [favorites insertObject:draggedRow atIndex:destinationRow+i]; + + if(originalRow < row) offset--; - if([[favorites objectAtIndex:destinationRow] objectForKey:@"headerOfFileURL"]) - [self _initWithNoSelection]; - else if([favoritesTableView numberOfSelectedRows] == 1 - && [favoritesTableView selectedRow] == originalRow) { - [favoritesTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:destinationRow] byExtendingSelection:NO]; - [favoritesArrayController setSelectionIndexes:[NSIndexSet indexSetWithIndex:destinationRow]]; } + [favoritesTableView reloadData]; + [favoritesArrayController rearrangeObjects]; + return YES; } -- cgit v1.2.3