Ignore:
Timestamp:
Dec 11, 2011, 10:31:01 PM (10 years ago)
Author:
livings124
Message:

eliminate all warnings by switching NSOpenPanel/NSSavePanels to use completion handler blocks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r13096 r13108  
    10041004{
    10051005    NSOpenPanel * panel = [NSOpenPanel openPanel];
    1006 
     1006   
    10071007    [panel setAllowsMultipleSelection: YES];
    10081008    [panel setCanChooseFiles: YES];
    10091009    [panel setCanChooseDirectories: NO];
    1010 
    1011     [panel beginSheetForDirectory: nil file: nil types: [NSArray arrayWithObjects: @"org.bittorrent.torrent", @"torrent", nil]
    1012         modalForWindow: fWindow modalDelegate: self didEndSelector: @selector(openSheetClosed:returnCode:contextInfo:)
    1013         contextInfo: [NSNumber numberWithBool: sender == fOpenIgnoreDownloadFolder]];
    1014 }
    1015 
    1016 - (void) openSheetClosed: (NSOpenPanel *) panel returnCode: (NSInteger) code contextInfo: (NSNumber *) useOptions
    1017 {
    1018     if (code == NSOKButton)
    1019     {
    1020         NSMutableArray * filenames = [NSMutableArray arrayWithCapacity: [[panel URLs] count]];
    1021         for (NSURL * url in [panel URLs])
    1022             [filenames addObject: [url path]];
    1023        
    1024         NSDictionary * dictionary = [[NSDictionary alloc] initWithObjectsAndKeys: filenames, @"Filenames",
    1025             [NSNumber numberWithInt: [useOptions boolValue] ? ADD_SHOW_OPTIONS : ADD_MANUAL], @"AddType", nil];
    1026         [self performSelectorOnMainThread: @selector(openFilesWithDict:) withObject: dictionary waitUntilDone: NO];
    1027     }
     1010   
     1011    [panel setAllowedFileTypes: [NSArray arrayWithObjects: @"org.bittorrent.torrent", @"torrent", nil]];
     1012   
     1013    [panel beginSheetModalForWindow: fWindow completionHandler: ^(NSInteger result) {
     1014        if (result == NSFileHandlingPanelOKButton)
     1015        {
     1016            NSMutableArray * filenames = [NSMutableArray arrayWithCapacity: [[panel URLs] count]];
     1017            for (NSURL * url in [panel URLs])
     1018                [filenames addObject: [url path]];
     1019           
     1020            NSDictionary * dictionary = [[NSDictionary alloc] initWithObjectsAndKeys: filenames, @"Filenames",
     1021                                         [NSNumber numberWithInt: sender == fOpenIgnoreDownloadFolder ? ADD_SHOW_OPTIONS : ADD_MANUAL], @"AddType", nil];
     1022            [self performSelectorOnMainThread: @selector(openFilesWithDict:) withObject: dictionary waitUntilDone: NO];
     1023        }
     1024    }];
    10281025}
    10291026
     
    14321429    [panel setCanCreateDirectories: YES];
    14331430   
    1434     torrents = [torrents retain];
    14351431    NSInteger count = [torrents count];
    14361432    if (count == 1)
     
    14401436        [panel setMessage: [NSString stringWithFormat: NSLocalizedString(@"Select the new folder for %d data files.",
    14411437                            "Move torrent -> select destination folder"), count]];
    1442        
    1443     [panel beginSheetForDirectory: nil file: nil modalForWindow: fWindow modalDelegate: self
    1444         didEndSelector: @selector(moveDataFileChoiceClosed:returnCode:contextInfo:) contextInfo: torrents];
    1445 }
    1446 
    1447 - (void) moveDataFileChoiceClosed: (NSOpenPanel *) panel returnCode: (NSInteger) code contextInfo: (NSArray *) torrents
    1448 {
    1449     if (code == NSOKButton)
    1450     {
    1451         for (Torrent * torrent in torrents)
    1452             [torrent moveTorrentDataFileTo: [[[panel URLs] objectAtIndex: 0] path]];
    1453     }
    1454    
    1455     [torrents release];
     1438   
     1439    [panel beginSheetModalForWindow: fWindow completionHandler: ^(NSInteger result) {
     1440        if (result == NSFileHandlingPanelOKButton)
     1441        {
     1442            for (Torrent * torrent in torrents)
     1443                [torrent moveTorrentDataFileTo: [[[panel URLs] objectAtIndex: 0] path]];
     1444        }
     1445    }];
    14561446}
    14571447
     
    14771467        [panel setExtensionHidden: NO];
    14781468       
    1479         [panel beginSheetForDirectory: nil file: [torrent name] modalForWindow: fWindow modalDelegate: self
    1480             didEndSelector: @selector(saveTorrentCopySheetClosed:returnCode:contextInfo:) contextInfo: torrents];
     1469        [panel setNameFieldStringValue: [torrent name]];
     1470       
     1471        [panel beginSheetModalForWindow: fWindow completionHandler: ^(NSInteger result) {
     1472            //copy torrent to new location with name of data file
     1473            if (result == NSFileHandlingPanelOKButton)
     1474                [torrent copyTorrentFileTo: [[panel URL] path]];
     1475           
     1476            [torrents removeObjectAtIndex: 0];
     1477            [self performSelectorOnMainThread: @selector(copyTorrentFileForTorrents:) withObject: torrents waitUntilDone: NO];
     1478        }];
    14811479    }
    14821480    else
     
    15001498        [self copyTorrentFileForTorrents: torrents];
    15011499    }
    1502 }
    1503 
    1504 - (void) saveTorrentCopySheetClosed: (NSSavePanel *) panel returnCode: (NSInteger) code contextInfo: (NSMutableArray *) torrents
    1505 {
    1506     //copy torrent to new location with name of data file
    1507     if (code == NSOKButton)
    1508         [[torrents objectAtIndex: 0] copyTorrentFileTo: [[panel URL] path]];
    1509    
    1510     [torrents removeObjectAtIndex: 0];
    1511     [self performSelectorOnMainThread: @selector(copyTorrentFileForTorrents:) withObject: torrents waitUntilDone: NO];
    15121500}
    15131501
Note: See TracChangeset for help on using the changeset viewer.