Re: NSSavePanel beginSheetForDirectory:
Re: NSSavePanel beginSheetForDirectory:
- Subject: Re: NSSavePanel beginSheetForDirectory:
- From: Ali Ozer <email@hidden>
- Date: Thu, 1 Aug 2002 14:03:06 -0700
I'm having trouble implementing -beginSheetForDirectory: The only
sample project I can find that uses it is TextEdit, which uses it in a
way so fantastically sophisticated I can't make head or tail of it.
Here is a simple snippet of code which does a save sheet, and as a
bonus, an alert sheet right afterwards.
Ali
/* Put up a sheet for saving the currently selected type. On dismissal
of the sheet, didEndSaveSheet:returnCode:contextInfo: is called.
*/
- (IBAction)save:(id)sender {
[[NSSavePanel savePanel] beginSheetForDirectory:@"" file:@""
modalForWindow:[self window] modalDelegate:self
didEndSelector:@selector(didEndSaveSheet:returnCode:contextInfo:)
contextInfo:NULL];
}
/* Called when the save panel is dismissed. If OK, saves the data.
*/
- (void)didEndSaveSheet:(NSSavePanel *)savePanel
returnCode:(int)returnCode contextInfo:(void *)contextInfo {
[savePanel orderOut:nil];
if (returnCode == NSOKButton) {
NSString *filename = [savePanel filename];
NSData *data = [self dataToWrite]; // Can be transferred via
contextInfo, or gotten from document...
if (![data writeToFile:filename atomically:YES]) {
NSBeginCriticalAlertSheet(@"Couldn't write data.", @"OK",
nil, nil, [self window], self, NULL, NULL, NULL, "The file or folder
might be protected against writing."); // No need for a callback
selector, as the only possible option is to dismiss
}
}
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.