Changeset 14016


Ignore:
Timestamp:
Feb 11, 2013, 1:39:44 AM (8 years ago)
Author:
livings124
Message:

#5286 Files renamed in Mac Inspector are not re-sorted

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/InfoGeneralViewController.m

    r13601 r14016  
    141141        Torrent * torrent = [fTorrents objectAtIndex: 0];
    142142       
     143        #warning candidate for localizedStringWithFormat (although then we'll get two commas)
    143144        NSString * piecesString = ![torrent isMagnet] ? [NSString stringWithFormat: @"%ld, %@", [torrent pieceCount],
    144145                                        [NSString stringForFileSize: [torrent pieceSize]]] : @"";
  • trunk/macosx/Torrent.m

    r13913 r14016  
    5454- (void) idleLimitHit;
    5555- (void) metadataRetrieved;
     56- (void)renameFinished: (BOOL) success withNodes: (NSArray *) nodes completionHandler: (void (^)(BOOL)) completionHandler oldPath: (NSString *) oldPath newName: (NSString *) newName;
    5657
    5758- (BOOL) shouldShowEta;
     
    9697    @autoreleasepool
    9798    {
    98         NSDictionary * contextDict = (NSDictionary *)contextInfo;
    99        
    10099        NSString * oldPath = [NSString stringWithUTF8String: oldPathCharString];
    101         NSString * path = [oldPath stringByDeletingLastPathComponent];
    102100        NSString * newName = [NSString stringWithUTF8String: newNameCharString];
    103101       
    104         if (error == 0)
    105         {
    106             NSString * oldName = [oldPath lastPathComponent];
    107             void (^__block updateNodeAndChildrenForRename)(FileListNode *) = ^(FileListNode * node) {
    108                 [node updateFromOldName: oldName toNewName: newName inPath: path];
    109                
    110                 if ([node isFolder]) {
    111                     [[node children] enumerateObjectsWithOptions: NSEnumerationConcurrent usingBlock: ^(FileListNode * childNode, NSUInteger idx, BOOL * stop) {
    112                         updateNodeAndChildrenForRename(childNode);
    113                     }];
    114                 }
    115             };
    116            
    117             NSArray * nodes = [contextDict objectForKey: @"Nodes"];
    118             [nodes enumerateObjectsWithOptions: NSEnumerationConcurrent usingBlock: ^(FileListNode * node, NSUInteger idx, BOOL *stop) {
    119                 updateNodeAndChildrenForRename(node);
    120             }];
    121         }
    122         else
    123             NSLog(@"Error renaming %@ to %@", oldPath, [path stringByAppendingPathComponent: newName]);
    124        
    125         typedef void (^RenameCompletionBlock)(BOOL);
    126         RenameCompletionBlock completionHandler = [contextDict objectForKey: @"CompletionHandler"];
    127         completionHandler(error == 0);
    128        
    129         [contextDict release];
     102        NSDictionary * contextDict = [(NSDictionary *)contextInfo autorelease];
     103        Torrent * torrentObject = [contextDict objectForKey: @"Torrent"];
     104        [torrentObject renameFinished: error == 0 withNodes: [contextDict objectForKey: @"Nodes"] completionHandler: [contextDict objectForKey: @"CompletionHandler"] oldPath: oldPath newName: newName];
    130105    }
    131106}
     
    849824    NSParameterAssert(![newName isEqualToString: @""]);
    850825   
    851     NSDictionary * contextInfo = [@{ @"Nodes" : fFileList, @"CompletionHandler" : [[completionHandler copy] autorelease] } retain];
     826    NSDictionary * contextInfo = [@{ @"Torrent" : self, @"CompletionHandler" : [[completionHandler copy] autorelease] } retain];
    852827   
    853828    tr_torrentRenamePath(fHandle, fInfo->name, [newName UTF8String], renameCallback, contextInfo);
     
    860835    NSParameterAssert(![newName isEqualToString: @""]);
    861836   
    862     NSDictionary * contextInfo = [@{ @"Nodes" : @[ node ], @"CompletionHandler" : [[completionHandler copy] autorelease] } retain];
     837    NSDictionary * contextInfo = [@{ @"Torrent" : self, @"Nodes" : @[ node ], @"CompletionHandler" : [[completionHandler copy] autorelease] } retain];
    863838   
    864839    NSString * oldPath = [[node path] stringByAppendingPathComponent: [node name]];
     
    17491724    {
    17501725        const NSInteger count = [self fileCount];
    1751         NSMutableArray * fileList = [NSMutableArray arrayWithCapacity: count],
     1726        NSMutableArray * fileList = [NSMutableArray array],
    17521727                    * flatFileList = [NSMutableArray arrayWithCapacity: count];
    17531728       
     
    19441919}
    19451920
     1921- (void)renameFinished: (BOOL) success withNodes: (NSArray *) nodes completionHandler: (void (^)(BOOL)) completionHandler oldPath: (NSString *) oldPath newName: (NSString *) newName
     1922{
     1923    NSParameterAssert(completionHandler != nil);
     1924    NSParameterAssert(oldPath != nil);
     1925    NSParameterAssert(newName != nil);
     1926   
     1927    NSString * path = [oldPath stringByDeletingLastPathComponent];
     1928   
     1929    if (success)
     1930    {
     1931        NSString * oldName = [oldPath lastPathComponent];
     1932        void (^__block updateNodeAndChildrenForRename)(FileListNode *) = ^(FileListNode * node) {
     1933            [node updateFromOldName: oldName toNewName: newName inPath: path];
     1934           
     1935            if ([node isFolder]) {
     1936                [[node children] enumerateObjectsWithOptions: NSEnumerationConcurrent usingBlock: ^(FileListNode * childNode, NSUInteger idx, BOOL * stop) {
     1937                    updateNodeAndChildrenForRename(childNode);
     1938                }];
     1939            }
     1940        };
     1941       
     1942        if (!nodes)
     1943            nodes = fFlatFileList;
     1944        [nodes enumerateObjectsWithOptions: NSEnumerationConcurrent usingBlock: ^(FileListNode * node, NSUInteger idx, BOOL *stop) {
     1945            updateNodeAndChildrenForRename(node);
     1946        }];
     1947       
     1948        //resort lists
     1949        NSMutableArray * fileList = [fFileList mutableCopy];
     1950        [fFileList release];
     1951        [self sortFileList: fileList];
     1952        fFileList = fileList;
     1953       
     1954        NSMutableArray * flatFileList = [fFlatFileList mutableCopy];
     1955        [fFlatFileList release];
     1956        [self sortFileList: flatFileList];
     1957        fFlatFileList = flatFileList;
     1958    }
     1959    else
     1960        NSLog(@"Error renaming %@ to %@", oldPath, [path stringByAppendingPathComponent: newName]);
     1961   
     1962    completionHandler(success);
     1963}
     1964
    19461965- (BOOL) shouldShowEta
    19471966{
Note: See TracChangeset for help on using the changeset viewer.