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/MessageWindowController.m

    r12943 r13108  
    379379- (void) writeToFile: (id) sender
    380380{
    381     //make the array sorted by date
    382     NSSortDescriptor * descriptor = [NSSortDescriptor sortDescriptorWithKey: @"Index" ascending: YES];
    383     NSArray * descriptors = [[NSArray alloc] initWithObjects: descriptor, nil];
    384     NSArray * sortedMessages = [[fDisplayedMessages sortedArrayUsingDescriptors: descriptors] retain];
    385     [descriptors release];
    386    
    387381    NSSavePanel * panel = [NSSavePanel savePanel];
    388382    [panel setAllowedFileTypes: [NSArray arrayWithObject: @"txt"]];
    389383    [panel setCanSelectHiddenExtension: YES];
    390384   
    391     [panel beginSheetForDirectory: nil file: NSLocalizedString(@"untitled", "Save log panel -> default file name")
    392             modalForWindow: [self window] modalDelegate: self
    393             didEndSelector: @selector(writeToFileSheetClosed:returnCode:contextInfo:) contextInfo: sortedMessages];
    394 }
    395 
    396 - (void) writeToFileSheetClosed: (NSSavePanel *) panel returnCode: (NSInteger) code contextInfo: (NSArray *) messages
    397 {
    398     if (code == NSOKButton)
    399     {
    400         //create the text to output
    401         NSMutableArray * messageStrings = [NSMutableArray arrayWithCapacity: [messages count]];
    402         for (NSDictionary * message in messages)
    403             [messageStrings addObject: [self stringForMessage: message]];
    404    
    405         NSString * fileString = [messageStrings componentsJoinedByString: @"\n"];
    406        
    407         if (![fileString writeToFile: [[panel URL] path] atomically: YES encoding: NSUTF8StringEncoding error: nil])
     385    [panel setNameFieldStringValue: NSLocalizedString(@"untitled", "Save log panel -> default file name")];
     386   
     387    [panel beginSheetModalForWindow: [self window] completionHandler: ^(NSInteger result) {
     388        if (result == NSFileHandlingPanelOKButton)
    408389        {
    409             NSAlert * alert = [[NSAlert alloc] init];
    410             [alert addButtonWithTitle: NSLocalizedString(@"OK", "Save log alert panel -> button")];
    411             [alert setMessageText: NSLocalizedString(@"Log Could Not Be Saved", "Save log alert panel -> title")];
    412             [alert setInformativeText: [NSString stringWithFormat:
    413                     NSLocalizedString(@"There was a problem creating the file \"%@\".",
    414                     "Save log alert panel -> message"), [[[panel URL] path] lastPathComponent]]];
    415             [alert setAlertStyle: NSWarningAlertStyle];
     390            //make the array sorted by date
     391            NSSortDescriptor * descriptor = [NSSortDescriptor sortDescriptorWithKey: @"Index" ascending: YES];
     392            NSArray * descriptors = [[NSArray alloc] initWithObjects: descriptor, nil];
     393            NSArray * sortedMessages = [fDisplayedMessages sortedArrayUsingDescriptors: descriptors];
     394            [descriptors release];
    416395           
    417             [alert runModal];
    418             [alert release];
     396            //create the text to output
     397            NSMutableArray * messageStrings = [NSMutableArray arrayWithCapacity: [sortedMessages count]];
     398            for (NSDictionary * message in sortedMessages)
     399                [messageStrings addObject: [self stringForMessage: message]];
     400           
     401            NSString * fileString = [messageStrings componentsJoinedByString: @"\n"];
     402           
     403            if (![fileString writeToFile: [[panel URL] path] atomically: YES encoding: NSUTF8StringEncoding error: nil])
     404            {
     405                NSAlert * alert = [[NSAlert alloc] init];
     406                [alert addButtonWithTitle: NSLocalizedString(@"OK", "Save log alert panel -> button")];
     407                [alert setMessageText: NSLocalizedString(@"Log Could Not Be Saved", "Save log alert panel -> title")];
     408                [alert setInformativeText: [NSString stringWithFormat:
     409                                            NSLocalizedString(@"There was a problem creating the file \"%@\".",
     410                                                              "Save log alert panel -> message"), [[[panel URL] path] lastPathComponent]]];
     411                [alert setAlertStyle: NSWarningAlertStyle];
     412               
     413                [alert runModal];
     414                [alert release];
     415            }
    419416        }
    420     }
    421    
    422     [messages release];
     417    }];
    423418}
    424419
Note: See TracChangeset for help on using the changeset viewer.