delay part of generating the message log text until after choosing a location

This commit is contained in:
Mitchell Livingston 2009-10-25 21:30:19 +00:00
parent 2296384fc1
commit 7eed54904a
1 changed files with 12 additions and 12 deletions

View File

@ -314,30 +314,30 @@
//make the array sorted by date
NSSortDescriptor * descriptor = [[[NSSortDescriptor alloc] initWithKey: @"Index" ascending: YES] autorelease];
NSArray * descriptors = [[NSArray alloc] initWithObjects: descriptor, nil];
NSArray * sortedMessages = [fMessages sortedArrayUsingDescriptors: descriptors];
NSArray * sortedMessages = [[fMessages sortedArrayUsingDescriptors: descriptors] retain];
[descriptors release];
//create the text to output
NSMutableArray * messageStrings = [NSMutableArray arrayWithCapacity: [fMessages count]];
for (NSDictionary * message in sortedMessages)
[messageStrings addObject: [self stringForMessage: message]];
NSString * fileString = [[messageStrings componentsJoinedByString: @"\n"] retain];
NSSavePanel * panel = [NSSavePanel savePanel];
[panel setRequiredFileType: @"txt"];
[panel setCanSelectHiddenExtension: YES];
[panel beginSheetForDirectory: nil file: NSLocalizedString(@"untitled", "Save log panel -> default file name")
modalForWindow: [self window] modalDelegate: self
didEndSelector: @selector(writeToFileSheetClosed:returnCode:contextInfo:) contextInfo: fileString];
didEndSelector: @selector(writeToFileSheetClosed:returnCode:contextInfo:) contextInfo: sortedMessages];
}
- (void) writeToFileSheetClosed: (NSSavePanel *) panel returnCode: (NSInteger) code contextInfo: (NSString *) string
- (void) writeToFileSheetClosed: (NSSavePanel *) panel returnCode: (NSInteger) code contextInfo: (NSArray *) messages
{
if (code == NSOKButton)
{
if (![string writeToFile: [panel filename] atomically: YES encoding: NSUTF8StringEncoding error: nil])
//create the text to output
NSMutableArray * messageStrings = [NSMutableArray arrayWithCapacity: [fMessages count]];
for (NSDictionary * message in messages)
[messageStrings addObject: [self stringForMessage: message]];
NSString * fileString = [messageStrings componentsJoinedByString: @"\n"];
if (![fileString writeToFile: [panel filename] atomically: YES encoding: NSUTF8StringEncoding error: nil])
{
NSAlert * alert = [[NSAlert alloc] init];
[alert addButtonWithTitle: NSLocalizedString(@"OK", "Save log alert panel -> button")];
@ -352,7 +352,7 @@
}
}
[string release];
[messages release];
}
@end