Ignore:
Timestamp:
Jan 9, 2012, 11:59:57 PM (10 years ago)
Author:
livings124
Message:

merge the code to update the table when toggling the group rows

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r13150 r13153  
    22482248        }
    22492249    }
    2250     else if (!groupRows && wasGroupRows)
    2251     {
    2252         beganUpdates = YES;
    2253         if (onLion)
    2254             [fTableView beginUpdates];
    2255        
    2256         //since we're not doing this the right way (boo buggy animation), we need to remember selected group
    2257         NSArray * selectedValues = [fTableView selectedValues];
    2258        
    2259         if (onLion)
    2260             [fTableView removeItemsAtIndexes: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fDisplayedTorrents count])] inParent: nil withAnimation: NSTableViewAnimationSlideDown];
    2261              
    2262         [fDisplayedTorrents setArray: allTorrents];
    2263        
    2264         if (onLion)
    2265             [fTableView insertItemsAtIndexes: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fDisplayedTorrents count])] inParent: nil withAnimation: NSTableViewAnimationEffectFade];
    2266        
    2267         [fTableView selectValues: selectedValues];
    2268     }
    2269     else if (groupRows && !wasGroupRows)
    2270     {
    2271         //since we're not doing this the right way (boo buggy animation), we need to remember selected group
    2272         selectedValues = [fTableView selectedValues];
    2273        
    2274         //a map for quickly finding groups
    2275         NSMutableDictionary * groupsByIndex = [NSMutableDictionary dictionaryWithCapacity: [[GroupsController groups] numberOfGroups]];
    2276         for (Torrent * torrent in allTorrents)
    2277         {
    2278             const NSInteger groupValue = [torrent groupValue];
    2279             TorrentGroup * group = [groupsByIndex objectForKey: [NSNumber numberWithInteger: groupValue]];
    2280             if (!group)
    2281             {
    2282                 group = [[[TorrentGroup alloc] initWithGroup: groupValue] autorelease];
    2283                 [groupsByIndex setObject: group forKey: [NSNumber numberWithInteger: groupValue]];
    2284             }
    2285            
    2286             [[group torrents] addObject: torrent];
    2287         }
    2288        
    2289         beganUpdates = YES;
    2290         if (onLion)
    2291             [fTableView beginUpdates];
    2292        
    2293         #warning duplicate from above
    2294         if (onLion)
    2295             [fTableView removeItemsAtIndexes: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fDisplayedTorrents count])] inParent: nil withAnimation: NSTableViewAnimationSlideDown];
    2296        
    2297         [fDisplayedTorrents setArray: [groupsByIndex allValues]];
    2298        
    2299         //we need the groups to be sorted, and we can do it without moving items in the table, too!
    2300         NSSortDescriptor * groupDescriptor = [NSSortDescriptor sortDescriptorWithKey: @"groupOrderValue" ascending: YES];
    2301         [fDisplayedTorrents sortUsingDescriptors: [NSArray arrayWithObject: groupDescriptor]];
    2302        
    2303         if (onLion)
    2304             [fTableView insertItemsAtIndexes: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fDisplayedTorrents count])] inParent: nil withAnimation: NSTableViewAnimationEffectFade];
    2305     }
    2306     else
     2250    else if (groupRows && wasGroupRows)
    23072251    {
    23082252        NSAssert(groupRows && wasGroupRows, @"Should have had group rows and should remain with group rows");
     
    24242368        [self rearrangeTorrentTableArray: fDisplayedTorrents forParent: nil withSortDescriptors: [NSArray arrayWithObject: groupDescriptor] beganTableUpdate: &beganUpdates];
    24252369    }
     2370    else
     2371    {
     2372        NSAssert(groupRows != wasGroupRows, @"Trying togglng-group torrent reordering when we weren't expecting to.");
     2373       
     2374        //since we're not doing this the right way (boo buggy animation), we need to remember selected values
     2375        selectedValues = [fTableView selectedValues];
     2376       
     2377        beganUpdates = YES;
     2378        if (onLion)
     2379            [fTableView beginUpdates];
     2380       
     2381        if (onLion)
     2382            [fTableView removeItemsAtIndexes: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fDisplayedTorrents count])] inParent: nil withAnimation: NSTableViewAnimationSlideDown];
     2383       
     2384        if (groupRows)
     2385        {
     2386            //a map for quickly finding groups
     2387            NSMutableDictionary * groupsByIndex = [NSMutableDictionary dictionaryWithCapacity: [[GroupsController groups] numberOfGroups]];
     2388            for (Torrent * torrent in allTorrents)
     2389            {
     2390                const NSInteger groupValue = [torrent groupValue];
     2391                TorrentGroup * group = [groupsByIndex objectForKey: [NSNumber numberWithInteger: groupValue]];
     2392                if (!group)
     2393                {
     2394                    group = [[[TorrentGroup alloc] initWithGroup: groupValue] autorelease];
     2395                    [groupsByIndex setObject: group forKey: [NSNumber numberWithInteger: groupValue]];
     2396                }
     2397               
     2398                [[group torrents] addObject: torrent];
     2399            }
     2400           
     2401            [fDisplayedTorrents setArray: [groupsByIndex allValues]];
     2402           
     2403            //we need the groups to be sorted, and we can do it without moving items in the table, too!
     2404            NSSortDescriptor * groupDescriptor = [NSSortDescriptor sortDescriptorWithKey: @"groupOrderValue" ascending: YES];
     2405            [fDisplayedTorrents sortUsingDescriptors: [NSArray arrayWithObject: groupDescriptor]];
     2406        }
     2407        else
     2408            [fDisplayedTorrents setArray: allTorrents];
     2409       
     2410        if (onLion)
     2411            [fTableView insertItemsAtIndexes: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fDisplayedTorrents count])] inParent: nil withAnimation: NSTableViewAnimationEffectFade];
     2412    }
    24262413   
    24272414    //sort the torrents (won't sort the groups, though)
Note: See TracChangeset for help on using the changeset viewer.