Mailing Lists: Apple Mailing Lists

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

Re: Validate before save in Doc Style App?



Hello...

There isn't any single method to override or implement that would allow you to do this, so you would probably want to override the action methods for the save related menu items in your NSDocument subclass. The action for the "Save" menu item is saveDocument:, for "Save As..." it is saveDocumentAs:, and for "Save To..." it is saveDocumentTo:. You can write a method that does the actual validation and call that same method from each of the overridden action methods.

So, for example, your saveDocument: method could look something like

- (void)saveDocument:(id)sender
{
	if ([self documentIsValid]) {[super saveDocument:sender];}
	else {return;}
}


The saveDocumentAs: and saveDocumentTo: method would follow the same pattern, calling the validation method and then invoking the super class implementation if the document passes validation. Then the validation method would go something like


- (BOOL)documentIsValid
{
	BOOL isValid = TRUE;

	/* ... do whatever validation you need to do ... */

if (isValid) {return TRUE;}
else
{
/* provide feedback to user regarding why save failed w/ alert sheet, beep, etc ... */
return FALSE;
}


}


Hope that helps,

	Louis

In my doc-style application, I need to validate some things before I save out to a file. Is there a method I can override that would allow me to do some validation before the save panel is presented? I would need to able to cancel the save operation and return to the document if it fails the validation.

Thanks in advance,


Todd Freese The Filmworkers Club - Chicago


_______________________________________________
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
References: 
 >Validate before save in Doc Style App? (From: Todd Freese <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.