allow changing groups by dragging (regardless of sort)

This commit is contained in:
Mitchell Livingston 2008-05-12 21:57:37 +00:00
parent b147256596
commit 320f43211f
2 changed files with 45 additions and 32 deletions

1
NEWS
View File

@ -3,6 +3,7 @@ NEWS file for Transmission <http://www.transmissionbt.com/>
1.30 (2008/mm/dd) 1.30 (2008/mm/dd)
http://trac.transmissionbt.com/query?group=component&milestone=1.30 http://trac.transmissionbt.com/query?group=component&milestone=1.30
- Mac - Mac
+ Torrents can be dragged to different groups
+ Status strings are toggled from the action button (they are no longer clickable) + Status strings are toggled from the action button (they are no longer clickable)
1.20 (2008/05/09) 1.20 (2008/05/09)

View File

@ -2578,7 +2578,8 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
- (BOOL) outlineView: (NSOutlineView *) outlineView writeItems: (NSArray *) items toPasteboard: (NSPasteboard *) pasteboard - (BOOL) outlineView: (NSOutlineView *) outlineView writeItems: (NSArray *) items toPasteboard: (NSPasteboard *) pasteboard
{ {
//only allow reordering of rows if sorting by order //only allow reordering of rows if sorting by order
if ([[fDefaults stringForKey: @"Sort"] isEqualToString: SORT_ORDER]) if (([fDefaults boolForKey: @"SortByGroup"] && [NSApp isOnLeopardOrBetter])
|| [[fDefaults stringForKey: @"Sort"] isEqualToString: SORT_ORDER])
{ {
NSMutableIndexSet * indexSet = [NSMutableIndexSet indexSet]; NSMutableIndexSet * indexSet = [NSMutableIndexSet indexSet];
NSEnumerator * enumerator = [items objectEnumerator]; NSEnumerator * enumerator = [items objectEnumerator];
@ -2611,10 +2612,17 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
else if ([item isKindOfClass: [Torrent class]]) else if ([item isKindOfClass: [Torrent class]])
{ {
NSDictionary * group = [fTableView parentForItem: item]; NSDictionary * group = [fTableView parentForItem: item];
index = [[group objectForKey: @"Torrents"] indexOfObject: item] + 1; if ([[fDefaults stringForKey: @"Sort"] isEqualToString: SORT_ORDER])
index = [[group objectForKey: @"Torrents"] indexOfObject: item] + 1;
else
index = NSOutlineViewDropOnItemIndex;
item = group; item = group;
} }
else; else
{
if (![[fDefaults stringForKey: @"Sort"] isEqualToString: SORT_ORDER])
index = NSOutlineViewDropOnItemIndex;
}
} }
else else
{ {
@ -2649,19 +2657,6 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
for (i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i]) for (i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
[movingTorrents addObject: [fTableView itemAtRow: i]]; [movingTorrents addObject: [fTableView itemAtRow: i]];
//find torrent to place under
NSArray * groupTorrents = item ? [item objectForKey: @"Torrents"] : fDisplayedTorrents;
Torrent * topTorrent = nil;
for (i = newRow-1; i >= 0; i--)
{
Torrent * tempTorrent = [groupTorrents objectAtIndex: i];
if (![movingTorrents containsObject: tempTorrent])
{
topTorrent = tempTorrent;
break;
}
}
//reset groups //reset groups
if (item) if (item)
{ {
@ -2677,25 +2672,42 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
[torrent setGroupValue: groupValue]; [torrent setGroupValue: groupValue];
} }
//part 1 of avoiding weird crash //part 2 of avoiding weird crash
[fTableView reloadItem: nil reloadChildren: YES]; [fTableView reloadItem: nil reloadChildren: YES];
} }
//remove objects to reinsert //reorder queue order
[fTorrents removeObjectsInArray: movingTorrents]; if ([[fDefaults stringForKey: @"Sort"] isEqualToString: SORT_ORDER])
{
//get all torrents to reorder //find torrent to place under
NSSortDescriptor * orderDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"orderValue" ascending: YES] autorelease]; NSArray * groupTorrents = item ? [item objectForKey: @"Torrents"] : fDisplayedTorrents;
[fTorrents sortUsingDescriptors: [NSArray arrayWithObject: orderDescriptor]]; Torrent * topTorrent = nil;
for (i = newRow-1; i >= 0; i--)
//insert objects at new location {
int insertIndex = topTorrent ? [fTorrents indexOfObject: topTorrent] + 1 : 0; Torrent * tempTorrent = [groupTorrents objectAtIndex: i];
for (i = 0; i < [movingTorrents count]; i++) if (![movingTorrents containsObject: tempTorrent])
[fTorrents insertObject: [movingTorrents objectAtIndex: i] atIndex: insertIndex + i]; {
topTorrent = tempTorrent;
//redo order values break;
for (i = 0; i < [fTorrents count]; i++) }
[[fTorrents objectAtIndex: i] setOrderValue: i]; }
//remove objects to reinsert
[fTorrents removeObjectsInArray: movingTorrents];
//get all torrents to reorder
NSSortDescriptor * orderDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"orderValue" ascending: YES] autorelease];
[fTorrents sortUsingDescriptors: [NSArray arrayWithObject: orderDescriptor]];
//insert objects at new location
int insertIndex = topTorrent ? [fTorrents indexOfObject: topTorrent] + 1 : 0;
for (i = 0; i < [movingTorrents count]; i++)
[fTorrents insertObject: [movingTorrents objectAtIndex: i] atIndex: insertIndex + i];
//redo order values
for (i = 0; i < [fTorrents count]; i++)
[[fTorrents objectAtIndex: i] setOrderValue: i];
}
[self applyFilter: nil]; [self applyFilter: nil];