Changeset 13158


Ignore:
Timestamp:
Jan 14, 2012, 2:28:54 AM (9 years ago)
Author:
livings124
Message:

#4713 (Lion) animate removing rows from the tracker table

Location:
trunk/macosx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/InfoTrackersViewController.m

    r12991 r13158  
    2424
    2525#import "InfoTrackersViewController.h"
     26#import "NSApplicationAdditions.h"
    2627#import "Torrent.h"
    2728#import "TrackerCell.h"
     
    103104    if ([fTrackerTable editedRow] == -1)
    104105    {
    105         [fTrackers release];
     106        NSArray * oldTrackers = fTrackers;
    106107       
    107108        if ([fTorrents count] == 1)
     
    115116       
    116117        [fTrackerTable setTrackers: fTrackers];
    117         [fTrackerTable reloadData];
     118       
     119        if ([NSApp isOnLionOrBetter] && [fTrackers isEqualToArray: oldTrackers])
     120            [fTrackerTable setNeedsDisplay: YES];
     121        else
     122            [fTrackerTable reloadData];
     123       
     124        [oldTrackers release];
    118125    }
    119126    else
     
    304311{
    305312    NSMutableDictionary * removeIdentifiers = [NSMutableDictionary dictionaryWithCapacity: [fTorrents count]];
    306     NSUInteger removeCount = 0;
     313    NSUInteger removeTrackerCount = 0;
    307314       
    308315    NSIndexSet * selectedIndexes = [fTrackerTable selectedRowIndexes];
    309316    BOOL groupSelected = NO;
     317    NSUInteger groupRowIndex = NSNotFound;
     318    NSMutableIndexSet * removeIndexes = [NSMutableIndexSet indexSet];
    310319    for (NSUInteger i = 0; i < [fTrackers count]; ++i)
    311320    {
     
    324333               
    325334                [removeSet addObject: [(TrackerNode *)object fullAnnounceAddress]];
    326                 ++removeCount;
     335                ++removeTrackerCount;
     336               
     337                [removeIndexes addIndex: i];
    327338            }
     339            else
     340                groupRowIndex = NSNotFound; //don't remove the group row
    328341        }
    329342        else
    330343        {
     344            //mark the previous group row for removal, if necessary
     345            if (groupRowIndex != NSNotFound)
     346                [removeIndexes addIndex: groupRowIndex];
     347           
    331348            groupSelected = [selectedIndexes containsIndex: i];
    332349            if (!groupSelected && i > [selectedIndexes lastIndex])
     350            {
     351                groupRowIndex = NSNotFound;
    333352                break;
    334         }
    335     }
     353            }
     354           
     355            groupRowIndex = i;
     356        }
     357    }
     358   
     359    //mark the last group for removal, too
     360    if (groupRowIndex != NSNotFound)
     361        [removeIndexes addIndex: groupRowIndex];
     362   
     363    NSAssert2(removeTrackerCount <= [removeIndexes count], @"Marked %ld trackers to remove, but only removing %ld rows", removeTrackerCount, [removeIndexes count]);
    336364   
    337365    //we might have no trackers if remove right after a failed add (race condition ftw)
    338366    #warning look into having a failed add apply right away, so that this can become an assert
    339     if (removeCount == 0)
     367    if (removeTrackerCount == 0)
    340368        return;
    341369   
     
    344372        NSAlert * alert = [[NSAlert alloc] init];
    345373       
    346         if (removeCount > 1)
     374        if (removeTrackerCount > 1)
    347375        {
    348376            [alert setMessageText: [NSString stringWithFormat: NSLocalizedString(@"Are you sure you want to remove %d trackers?",
    349                                                                 "Remove trackers alert -> title"), removeCount]];
     377                                                                "Remove trackers alert -> title"), removeTrackerCount]];
    350378            [alert setInformativeText: NSLocalizedString(@"Once removed, Transmission will no longer attempt to contact them."
    351379                                        " This cannot be undone.", "Remove trackers alert -> message")];
     
    371399            return;
    372400    }
     401   
     402   
     403    if ([NSApp isOnLionOrBetter])
     404        [fTrackerTable beginUpdates];
    373405   
    374406    for (Torrent * torrent in removeIdentifiers)
     
    381413        [fTrackers addObjectsFromArray: [torrent allTrackerStats]];
    382414   
    383     [fTrackerTable setTrackers: fTrackers];
    384     [fTrackerTable reloadData];
    385     [fTrackerTable deselectAll: self];
     415    if ([NSApp isOnLionOrBetter])
     416    {
     417        [fTrackerTable removeRowsAtIndexes: removeIndexes withAnimation: NSTableViewAnimationSlideLeft];
     418       
     419        [fTrackerTable setTrackers: fTrackers];
     420       
     421        [fTrackerTable endUpdates];
     422    }
     423    else
     424    {
     425        [fTrackerTable setTrackers: fTrackers];
     426       
     427        [fTrackerTable reloadData];
     428        [fTrackerTable deselectAll: self];
     429    }
    386430   
    387431    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil]; //incase sort by tracker
  • trunk/macosx/TrackerNode.h

    r11617 r13158  
    3737- (id) initWithTrackerStat: (tr_tracker_stat *) stat torrent: (Torrent *) torrent;
    3838
     39- (BOOL) isEqual: (id) object;
     40
    3941- (NSString *) host;
    4042- (NSString *) fullAnnounceAddress;
  • trunk/macosx/TrackerNode.m

    r12940 r13158  
    4848    //this object is essentially immutable after initial setup
    4949    return [self retain];
     50}
     51
     52- (BOOL) isEqual: (id) object
     53{
     54    if (self == object)
     55        return YES;
     56   
     57    if (![object isKindOfClass: [self class]])
     58        return NO;
     59   
     60    return [self tier] == [object tier] && [[self fullAnnounceAddress] isEqualToString: [object fullAnnounceAddress]];
    5061}
    5162
Note: See TracChangeset for help on using the changeset viewer.