Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Opening a document in code



I am trying to open a document in code (rather then the Open menu command). I have code that worked after a menu command, but when it is called after clicking on a button in a panel window it crashes. I determined the file opens, all data is read, my windowDidLoad method is called and succeeds, but it then crashes before ever returning from the openDocumentWithContentsOfURL. Below are action methods of the button and code to open the document

- (IBAction)openProcess:(id)sender
{
NSString *sourceFile=[inputPathText stringValue];
NSString *msg=[ResultsDocument openResultsFile:sourceFile];
if(msg!=nil)
{ NSBeginInformationalAlertSheet(@"The background process results could not be opened.",
@"OK",nil,nil,[self window],self,nil,nil,nil,msg);
}
}


+ (NSString *)openResultsFile:(NSString *)sourceFile
{
// if that document is open, close it first
ResultsDocument *resDoc;
NSURL *sourceURL=[NSURL fileURLWithPath:sourceFile];
if(resDoc=[[NSDocumentController sharedDocumentController] documentForURL:sourceURL])
{ [resDoc close];
}


// now open it
NSError *outError;
if(resDoc=[[NSDocumentController sharedDocumentController]
openDocumentWithContentsOfURL:sourceURL display:YES error:&outError])
{ return [outError localizedDescription];
}


    return nil;
}

---------------
John Nairn (1-801-581-3413, FAX:1-801-581-4816)
Web Page: http://www.mse.utah.edu/~nairn

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.