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 --- Interfaces/English.lproj/QueryFavoriteManager.xib | 75 ++++++++++++++--------- Source/SPQueryFavoriteManager.m | 73 +++++++++++++++------- 2 files changed, 96 insertions(+), 52 deletions(-) diff --git a/Interfaces/English.lproj/QueryFavoriteManager.xib b/Interfaces/English.lproj/QueryFavoriteManager.xib index 0a761cf3..20029676 100644 --- a/Interfaces/English.lproj/QueryFavoriteManager.xib +++ b/Interfaces/English.lproj/QueryFavoriteManager.xib @@ -8,6 +8,7 @@ 353.00 YES + YES @@ -45,7 +46,7 @@ {3.40282e+38, 3.40282e+38} {500, 371} - + 256 YES @@ -830,6 +831,7 @@ {500, 371} + {{0, 0}, {1680, 1028}} {500, 393} @@ -1140,22 +1142,6 @@ 283 - - - value: arrangedObjects.name - - - - - - value: arrangedObjects.name - value - arrangedObjects.name - 2 - - - 285 - value: selection.name @@ -1188,6 +1174,34 @@ 291 + + + favoritesArrayController + + + + 297 + + + + value: arrangedObjects.name + + + + + + value: arrangedObjects.name + value + arrangedObjects.name + + NSCreatesSortDescriptor + + + 2 + + + 298 + value: arrangedObjects.tabtrigger @@ -1200,21 +1214,22 @@ value arrangedObjects.tabtrigger - NSConditionallySetsEditable - + YES + + YES + NSConditionallySetsEditable + NSCreatesSortDescriptor + + + YES + + + 2 - 295 - - - - favoritesArrayController - - - - 297 + 299 @@ -1714,7 +1729,7 @@ com.apple.InterfaceBuilder.CocoaPlugin {{209, 69}, {500, 371}} {{209, 69}, {500, 371}} - + {196, 240} {{357, 418}, {480, 270}} @@ -1867,7 +1882,7 @@ - 297 + 299 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